feat: Add errors counter and compression function. No compression by default.
This commit is contained in:
parent
98b54d30fe
commit
23403765e5
@ -25,7 +25,11 @@ __pid_file='/tmp/boring-backup.pid'
|
|||||||
__tar_options='-acf'
|
__tar_options='-acf'
|
||||||
__tar_exclude=
|
__tar_exclude=
|
||||||
__name_date_fmt='_%Y%m%d-%H%M'
|
__name_date_fmt='_%Y%m%d-%H%M'
|
||||||
__compression='gzip'
|
__compression=
|
||||||
|
__errors_count=0
|
||||||
|
__errors_file='/tmp/boring-backup.errors'
|
||||||
|
|
||||||
|
echo $__errors_count > $__errors_file
|
||||||
|
|
||||||
LIBRARY="${LIBRARY:-./lib}"
|
LIBRARY="${LIBRARY:-./lib}"
|
||||||
|
|
||||||
@ -201,8 +205,16 @@ for script in "${__args[@]}"; do
|
|||||||
unset tar_exclude
|
unset tar_exclude
|
||||||
done
|
done
|
||||||
|
|
||||||
log "Backup FINISHED"
|
if [[ "$(cat $__errors_file)" != '0' ]]; then
|
||||||
|
echo
|
||||||
|
log -p "Backup [Failed]: Process finished with $(cat $__errors_file) errors."\
|
||||||
|
"See $__log_file for info."
|
||||||
|
rm $__errors_file
|
||||||
|
else
|
||||||
echo -e "\nBackup [Done]"
|
echo -e "\nBackup [Done]"
|
||||||
|
fi
|
||||||
|
|
||||||
|
log "Backup FINISHED"
|
||||||
|
|
||||||
# Remove PID file
|
# Remove PID file
|
||||||
rm $__pid_file
|
rm $__pid_file
|
||||||
|
@ -99,7 +99,12 @@ err() {
|
|||||||
|
|
||||||
# Exit
|
# Exit
|
||||||
if [ "$errexit" ]; then
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,6 +116,7 @@ try() {
|
|||||||
if eval "$@" 2>> "$__log_file"; then
|
if eval "$@" 2>> "$__log_file"; then
|
||||||
return 0 # Success
|
return 0 # Success
|
||||||
else
|
else
|
||||||
|
# Count errors
|
||||||
err -a "Error: Something went wrong when executing command:"
|
err -a "Error: Something went wrong when executing command:"
|
||||||
err -a " $*"
|
err -a " $*"
|
||||||
err -aeo "Check $__log_file log for details."
|
err -aeo "Check $__log_file log for details."
|
||||||
@ -139,3 +145,29 @@ is_function_set() {
|
|||||||
declare -F -- "$1" > /dev/null
|
declare -F -- "$1" > /dev/null
|
||||||
return "$?"
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user