feat: Add tar compression selection
This commit is contained in:
parent
5b3f8dd15f
commit
1e124a6aa8
@ -20,7 +20,8 @@ __version='0.0.0'
|
|||||||
__config=
|
__config=
|
||||||
__verbose=
|
__verbose=
|
||||||
__log_file='./log.txt'
|
__log_file='./log.txt'
|
||||||
__tar_options='-czf'
|
__tar_options='-acf'
|
||||||
|
__tar_compression='gzip'
|
||||||
__name_date_fmt='_%Y%m%d-%H%M'
|
__name_date_fmt='_%Y%m%d-%H%M'
|
||||||
|
|
||||||
if [ -n "$BAFLIB" ]; then
|
if [ -n "$BAFLIB" ]; then
|
||||||
@ -121,10 +122,10 @@ log "Backup STARTED"
|
|||||||
log -p "Configuration file: $([ "$__config" ] || echo not specified && echo "$__config")"
|
log -p "Configuration file: $([ "$__config" ] || echo not specified && echo "$__config")"
|
||||||
log "Scripts to process (${_count}): ${__args[@]}"
|
log "Scripts to process (${_count}): ${__args[@]}"
|
||||||
|
|
||||||
# TODO source config
|
|
||||||
|
|
||||||
for script in "${__args[@]}"; do
|
for script in "${__args[@]}"; do
|
||||||
source_script "$script"
|
source_script "$script"
|
||||||
|
#. "$__config" # TODO Make it safe!
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo -e "\e[1m==> Script: ${__args[_iter-1]##*/} [$_iter/$_count]\e[0m" | log -p
|
echo -e "\e[1m==> Script: ${__args[_iter-1]##*/} [$_iter/$_count]\e[0m" | log -p
|
||||||
@ -162,6 +163,7 @@ for script in "${__args[@]}"; do
|
|||||||
|
|
||||||
# Unset user defined variables
|
# Unset user defined variables
|
||||||
unset tar_options
|
unset tar_options
|
||||||
|
unset tar_compression
|
||||||
unset name_date_fmt
|
unset name_date_fmt
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -103,6 +103,7 @@ backup_files() {
|
|||||||
local dst_path
|
local dst_path
|
||||||
local tar_opts
|
local tar_opts
|
||||||
local archive
|
local archive
|
||||||
|
local compression
|
||||||
local file_ext
|
local file_ext
|
||||||
|
|
||||||
uri="$1"
|
uri="$1"
|
||||||
@ -117,7 +118,8 @@ backup_files() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
is_installed tar # Exit if tar is not installed
|
# Exit if tar is not installed
|
||||||
|
is_installed tar
|
||||||
|
|
||||||
# Overwrire __tar_options
|
# Overwrire __tar_options
|
||||||
if [ -n "$tar_options" ]; then
|
if [ -n "$tar_options" ]; then
|
||||||
@ -126,9 +128,35 @@ backup_files() {
|
|||||||
tar_opts="$__tar_options"
|
tar_opts="$__tar_options"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# TODO выбор сжатия, можно в переменной __tar_options заменять букву z на
|
# Overwrite __tar_compression
|
||||||
# другую для соответствующего сжатия
|
if [ "$tar_compression" ]; then
|
||||||
file_ext=.tar.gz
|
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")"
|
archive="${dst_path}/$(gen_backup_name "$file_ext")"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user