Archive : Add support for .archiveignore.

This commit is contained in:
Dmitry Voronin 2024-01-03 17:21:11 +03:00
parent 6ca5f00e3e
commit 02fe135ed1
2 changed files with 24 additions and 6 deletions

View file

@ -3,6 +3,7 @@ export _archive_pattern_fast="_[0-9]{12}-[[:alnum:]]{40}.tgz"
# Archive directories.
# All directories by default.
# Supports .archiveignore exclude file.
# Usage: archive [DIRS]
function archive() {
local IFS=$'\n'
@ -15,8 +16,13 @@ function archive() {
# Parse name.
local name=$(parse_pascal ${target})
# Exclude support.
local exclude=""
[[ -f ".archiveignore" ]] && exclude="--exclude-from=.archiveignore"
[[ -f "${target}/.archiveignore" ]] && exclude="--exclude-from=${target}/.archiveignore"
# create archive.
local hash=$(tar -c ${target} | pv -s $(/usr/bin/du -sb ${target} | awk '{print $1}') | xz -9e | tee ${name}.txz | sha1sum | cut -d\ -f1)
local hash=$(tar ${exclude} -c ${target} | pv -s $(/usr/bin/du -sb ${target} | awk '{print $1}') | xz -9e | tee ${name}.txz | sha1sum | cut -d\ -f1)
# append hash to target name.
local new_name="${name}_${date}-${hash}.txz"
@ -28,6 +34,7 @@ function archive() {
# Archive using multiple threads. Uses 50% of free RAM.
# All directories by default.
# Supports .archiveignore exclude file.
# Usage: archive_mt [DIRS]
function archive_mt() {
local IFS=$'\n'
@ -40,12 +47,17 @@ function archive_mt() {
# Parse name.
local name=$(parse_pascal ${target})
# Exclude support.
local exclude=""
[[ -f ".archiveignore" ]] && exclude="--exclude-from=.archiveignore"
[[ -f "${target}/.archiveignore" ]] && exclude="--exclude-from=${target}/.archiveignore"
# Determine memory limit.
local mem_free=$(_mem_free)
local mem_limit=$((mem_free/2))
# create archive.
local hash=$(tar -c ${target} | pv -s $(/usr/bin/du -sb ${target} | awk '{print $1}') | xz -9e --threads=0 --memlimit=${mem_limit}MiB | tee ${name}.txz | sha1sum | cut -d\ -f1)
local hash=$(tar ${exclude} -c ${target} | pv -s $(/usr/bin/du -sb ${target} | awk '{print $1}') | xz -9e --threads=0 --memlimit=${mem_limit}MiB | tee ${name}.txz | sha1sum | cut -d\ -f1)
# append hash to target name.
local new_name="${name}_${date}-${hash}.txz"
@ -57,6 +69,7 @@ function archive_mt() {
# Archive directories with fast compression.
# All directories by default.
# Supports .archiveignore exclude file.
# Usage: archive_fast [DIRS]
function archive_fast() {
local IFS=$'\n'
@ -70,8 +83,13 @@ function archive_fast() {
# Parse name.
local name=$(parse_pascal "${target}")
# Exclude support.
local exclude=""
[[ -f ".archiveignore" ]] && exclude="--exclude-from=.archiveignore"
[[ -f "${target}/.archiveignore" ]] && exclude="--exclude-from=${target}/.archiveignore"
# create archive.
local hash=$(tar -c "${target}" | pv -s $(/usr/bin/du -sb "${target}" | awk '{print $1}') | gzip -1 | tee "${name}".tgz | sha1sum | cut -d\ -f1)
local hash=$(tar ${exclude} -c "${target}" | pv -s $(/usr/bin/du -sb "${target}" | awk '{print $1}') | gzip -1 | tee "${name}".tgz | sha1sum | cut -d\ -f1)
# append hash to target name.
local new_name="${name}_${date}-${hash}.tgz"

View file

@ -20,9 +20,9 @@ Command|Description
Command|Description
---|---
`archive [DIRS]`|Archive directories. All directories by default.
`archive_mt [DIRS]`|Archive using multiple threads. Uses 50% of free RAM. All directories by default.
`archive_fast [DIRS]`|Archive directories with fast compression. All directories by default.
`archive [DIRS]`|Archive directories. All directories by default. Supports .archiveignore exclude file.
`archive_mt [DIRS]`|Archive using multiple threads. Uses 50% of free RAM. All directories by default. Supports .archiveignore exclude file.
`archive_fast [DIRS]`|Archive directories with fast compression. All directories by default. Supports .archiveignore exclude file.
`archive_check [FILES]`|Check archives integrity. Checks all archives by default.
`archive_prune [NAME]`|Delete old versions of archives. All archives by default.
`archive_rm [FILES]`|Delete specified or all archive files.