feat: Add errors counter and compression function. No compression by default.
This commit is contained in:
@ -99,7 +99,12 @@ err() {
|
||||
|
||||
# Exit
|
||||
if [ "$errexit" ]; then
|
||||
log "Backup ERROR: Exiting with previous errors"; exit 1
|
||||
# Count errors for backup recap
|
||||
__errors_count="$(cat $__errors_file)"
|
||||
((__errors_count++)) || true
|
||||
echo $__errors_count > "$__errors_file"
|
||||
|
||||
log -p "Backup ERROR: Exiting with previous errors" >&2; exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
@ -111,6 +116,7 @@ try() {
|
||||
if eval "$@" 2>> "$__log_file"; then
|
||||
return 0 # Success
|
||||
else
|
||||
# Count errors
|
||||
err -a "Error: Something went wrong when executing command:"
|
||||
err -a " $*"
|
||||
err -aeo "Check $__log_file log for details."
|
||||
@ -139,3 +145,29 @@ is_function_set() {
|
||||
declare -F -- "$1" > /dev/null
|
||||
return "$?"
|
||||
}
|
||||
|
||||
set_compression() {
|
||||
# Set compr_util and file_ext by name.
|
||||
|
||||
# Select compression utility and set filename extension.
|
||||
# Refference: https://www.gnu.org/software/tar/manual/html_node/gzip.html
|
||||
case "$1" in
|
||||
gzip|gz) file_ext='.gz'; compr_util='gzip';;
|
||||
tgz) file_ext='.gz'; compr_util='gzip';;
|
||||
taz) file_ext='.gz'; compr_util='gzip';;
|
||||
compress|Z) file_ext='.Z'; compr_util='compress';;
|
||||
taZ) file_ext='.Z'; compr_util='compress';;
|
||||
bzip2|bz2) file_ext='.bz2'; compr_util='bzip2';;
|
||||
tz2) file_ext='.bz2'; compr_util='bzip2';;
|
||||
tbz2) file_ext='.bz2'; compr_util='bzip2';;
|
||||
tbz) file_ext='.bz2'; compr_util='bzip2';;
|
||||
lzip|lz) file_ext='.lz'; compr_util='lzip';;
|
||||
lzma) file_ext='.lzma'; compr_util='lzma';;
|
||||
tlz) file_ext='.lzma'; compr_util='lzma';;
|
||||
lzop|lzo) file_ext='.lzop'; compr_util='lzop';;
|
||||
xz) file_ext='.xz'; compr_util='xz';;
|
||||
zstd|zst) file_ext='.zst'; compr_util='zstd';;
|
||||
tzst) file_ext='.zst'; compr_util='zstd';;
|
||||
*) file_ext=''; compr_util='';; # No compression
|
||||
esac
|
||||
}
|
||||
|
Reference in New Issue
Block a user