feat: Replace tar_compression with compressuion. Add tar_exclude option

This commit is contained in:
ge 2022-05-17 01:07:14 +03:00
parent c2dc7a0729
commit 9a008ad7b9

View File

@ -105,9 +105,10 @@ backup_files() {
local uri local uri
local src_path local src_path
local dst_path local dst_path
local tar_opts local opts
local archive local archive
local compression local compr
local exclude
local file_ext local file_ext
uri="$1" uri="$1"
@ -132,22 +133,31 @@ backup_files() {
# Overwrire __tar_options # Overwrire __tar_options
if [ -n "$tar_options" ]; then if [ -n "$tar_options" ]; then
tar_opts="$tar_options" opts="$tar_options"
else else
tar_opts="$__tar_options" opts="$__tar_options"
fi fi
# Overwrite __tar_compression # Overwrite __tar_exclude
if [ "$tar_compression" ]; then if [ "$tar_exclude" ]; then
compression="$tar_compression" for item in "${tar_exclude[@]}"; do
exclude+=" --exclude $item"
done
else else
compression="$__tar_compression" exclude=
fi
# Overwrite __compression
if [ "$compression" ]; then
compr="$compression"
else
compr="$__compression"
fi fi
# Select filename extension by compression type. # Select filename extension by compression type.
# Make sure for the `--auto-compress` is enabled in __tar_options # Make sure for the `--auto-compress` is enabled in __tar_options
# Refference: https://www.gnu.org/software/tar/manual/html_node/gzip.html # Refference: https://www.gnu.org/software/tar/manual/html_node/gzip.html
case "$compression" in case "$compr" in
gzip|gz) file_ext='.tar.gz';; # gzip gzip|gz) file_ext='.tar.gz';; # gzip
tgz) file_ext='.tgz';; # gzip tgz) file_ext='.tgz';; # gzip
taz) file_ext='.taz';; # gzip taz) file_ext='.taz';; # gzip
@ -172,13 +182,14 @@ backup_files() {
[ "$__verbose" ] && { [ "$__verbose" ] && {
echo "Source path: $src_path" echo "Source path: $src_path"
echo "Destination path: $dst_path" echo "Destination path: $dst_path"
echo "Command: tar $tar_opts $archive $src_path" echo "Command: tar $exclude $opts $archive $src_path"
} }
log "Archiving $src_path to $archive ..." log "Archiving $src_path to $archive ..."
log "Command: tar $exclude $opts $archive $src_path"
# Run tar # Run tar
try tar "$tar_opts" "$archive" "$src_path" try tar "$exclude" "$opts" "$archive" "$src_path"
# Append path to 'backups' array # Append path to 'backups' array
backups+=("$archive") backups+=("$archive")