From 9a008ad7b980c815077f38e334f5c8c06bec6a0e Mon Sep 17 00:00:00 2001 From: ge Date: Tue, 17 May 2022 01:07:14 +0300 Subject: [PATCH] feat: Replace tar_compression with compressuion. Add tar_exclude option --- src/lib/backup.sh | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/lib/backup.sh b/src/lib/backup.sh index d07e3b7..ecea702 100644 --- a/src/lib/backup.sh +++ b/src/lib/backup.sh @@ -105,9 +105,10 @@ backup_files() { local uri local src_path local dst_path - local tar_opts + local opts local archive - local compression + local compr + local exclude local file_ext uri="$1" @@ -132,22 +133,31 @@ backup_files() { # Overwrire __tar_options if [ -n "$tar_options" ]; then - tar_opts="$tar_options" + opts="$tar_options" else - tar_opts="$__tar_options" + opts="$__tar_options" fi - # Overwrite __tar_compression - if [ "$tar_compression" ]; then - compression="$tar_compression" + # Overwrite __tar_exclude + if [ "$tar_exclude" ]; then + for item in "${tar_exclude[@]}"; do + exclude+=" --exclude $item" + done else - compression="$__tar_compression" + exclude= + fi + + # Overwrite __compression + if [ "$compression" ]; then + compr="$compression" + else + compr="$__compression" fi # Select filename extension by compression type. # Make sure for the `--auto-compress` is enabled in __tar_options # 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 tgz) file_ext='.tgz';; # gzip taz) file_ext='.taz';; # gzip @@ -172,13 +182,14 @@ backup_files() { [ "$__verbose" ] && { echo "Source path: $src_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 "Command: tar $exclude $opts $archive $src_path" # Run tar - try tar "$tar_opts" "$archive" "$src_path" + try tar "$exclude" "$opts" "$archive" "$src_path" # Append path to 'backups' array backups+=("$archive")