feat: Add tar compression selection

This commit is contained in:
ge
2022-05-15 08:12:47 +03:00
parent 5b3f8dd15f
commit 1e124a6aa8
2 changed files with 36 additions and 6 deletions

View File

@ -103,6 +103,7 @@ backup_files() {
local dst_path
local tar_opts
local archive
local compression
local file_ext
uri="$1"
@ -117,7 +118,8 @@ backup_files() {
exit 1
fi
is_installed tar # Exit if tar is not installed
# Exit if tar is not installed
is_installed tar
# Overwrire __tar_options
if [ -n "$tar_options" ]; then
@ -126,9 +128,35 @@ backup_files() {
tar_opts="$__tar_options"
fi
# TODO выбор сжатия, можно в переменной __tar_options заменять букву z на
# другую для соответствующего сжатия
file_ext=.tar.gz
# Overwrite __tar_compression
if [ "$tar_compression" ]; then
compression="$tar_compression"
else
compression="$__tar_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
gzip|gz) file_ext='.tar.gz';; # gzip
tgz) file_ext='.tgz';; # gzip
taz) file_ext='.taz';; # gzip
compress|Z) file_ext='.tar.Z';; # compress
taZ) file_ext='.taZ';; # compress
bzip2|bz2) file_ext='.tar.bz2';; # bzip2
tz2) file_ext='.tz2';; # bzip2
tbz2) file_ext='.tbz2';; # bzip2
tbz) file_ext='.tbz';; # bzip2
lzip|lz) file_ext='.tar.lz';; # lzip
lzma) file_ext='.tar.lzma';; # lzma
tlz) file_ext='.tlz';; # lzma
lzop|lzo) file_ext='.tar.lzo';; # lzop
xz) file_ext='.tar.xz';; # xz
zstd|zst) file_ext='.tar.zst';; # zstd
tzst) file_ext='.tzst';; # zstd
*) file_ext='.tar.gz';; # Force gzip
esac
archive="${dst_path}/$(gen_backup_name "$file_ext")"