add syslog, remove compress

This commit is contained in:
ge 2022-10-08 19:38:25 +03:00
parent 9276d0f738
commit b53cc39495

View File

@ -17,7 +17,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
log() { log() {
# Logger. Write message to __log_file. # Logger. Write message to log_file.
# #
# Usage: log [-pV] MESSAGE # Usage: log [-pV] MESSAGE
# #
@ -45,7 +45,7 @@ log() {
esac esac
done done
if [ -n "$print" ] || [ -n "$__verbose" ]; then if [ -n "$print" ] || [ -n "$verbose_output" ]; then
if [ -n "$print" ] || [ -z "$ignore_verbose" ]; then if [ -n "$print" ] || [ -z "$ignore_verbose" ]; then
echo -e "$message" echo -e "$message"
fi fi
@ -55,9 +55,13 @@ log() {
sed -r 's/\x1B\[(([0-9]+)(;[0-9]+)*)?[m,K,H,f,J]//g' | sed -r 's/\x1B\[(([0-9]+)(;[0-9]+)*)?[m,K,H,f,J]//g' |
while read -r line; do while read -r line; do
if [ -n "$line" ]; then if [ -n "$line" ]; then
# shellcheck disable=SC2154 if [ -n "$use_syslog" ]; then
printf '[%s] %s\n' \ logger --id="$$" --tag boring_backup "$line"
"$(date +"$log_date_format")" "$line" >> "$__log_file" else
# shellcheck disable=SC2154
printf '[%s] %s\n' \
"$(date +"$log_date_format")" "$line" >> "$log_file"
fi
fi fi
done done
} }
@ -69,7 +73,7 @@ handle_error() {
# Display amd log message # Display amd log message
log -p "$*" >&2 log -p "$*" >&2
log -p "Check $__log_file log for details." >&2 log -p "Check $log_file log for details." >&2
# Run user defined error handler function if set # Run user defined error handler function if set
if is_function_set on_error; then if is_function_set on_error; then
@ -126,8 +130,6 @@ set_compression() {
gzip|gz) cmpr_ext='.gz'; tar_ext='.tar.gz'; cmpr_cmd='gzip';; gzip|gz) cmpr_ext='.gz'; tar_ext='.tar.gz'; cmpr_cmd='gzip';;
tgz) cmpr_ext='.gz'; tar_ext='.tgz'; cmpr_cmd='gzip';; tgz) cmpr_ext='.gz'; tar_ext='.tgz'; cmpr_cmd='gzip';;
taz) cmpr_ext='.gz'; tar_ext='.taz'; cmpr_cmd='gzip';; taz) cmpr_ext='.gz'; tar_ext='.taz'; cmpr_cmd='gzip';;
compress|Z) cmpr_ext='.Z'; tar_ext='.tar.Z'; cmpr_cmd='compress';;
taZ) cmpr_ext='.Z'; tar_ext='.taZ'; cmpr_cmd='compress';;
bzip2|bz2) cmpr_ext='.bz2'; tar_ext='.tar.bz2'; cmpr_cmd='bzip2';; bzip2|bz2) cmpr_ext='.bz2'; tar_ext='.tar.bz2'; cmpr_cmd='bzip2';;
tz2) cmpr_ext='.bz2'; tar_ext='.tz2'; cmpr_cmd='bzip2';; tz2) cmpr_ext='.bz2'; tar_ext='.tz2'; cmpr_cmd='bzip2';;
tbz2) cmpr_ext='.bz2'; tar_ext='.tbz2'; cmpr_cmd='bzip2';; tbz2) cmpr_ext='.bz2'; tar_ext='.tbz2'; cmpr_cmd='bzip2';;
@ -172,15 +174,18 @@ compress_file() {
# Compress file # Compress file
if [ -n "$cmpr_cmd" ]; then if [ -n "$cmpr_cmd" ]; then
log -V "Compressing file $1 by ${cmpr_cmd%% *} ..." log -V "Compressing file $1 by ${cmpr_cmd%% *} ..."
$cmpr_cmd "$1" 2>> "$__log_file" $cmpr_cmd "$1" 2>> "$log_file"
compressed="${1}${cmpr_ext}" compressed="${1}${cmpr_ext}"
fi
if [ -f "$compressed" ]; then # Remove original file.
if [ -f "$1" ]; then if [ -f "$compressed" ]; then
log "Remove uncompressed file $1" if [ -f "$1" ]; then
rm -- "$1" log "Remove uncompressed file $1"
rm -- "$1"
fi
fi fi
else
compressed="$1"
fi fi
echo "$compressed" echo "$compressed"