add syslog, remove compress
This commit is contained in:
parent
9276d0f738
commit
b53cc39495
@ -17,7 +17,7 @@
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
log() {
|
||||
# Logger. Write message to __log_file.
|
||||
# Logger. Write message to log_file.
|
||||
#
|
||||
# Usage: log [-pV] MESSAGE
|
||||
#
|
||||
@ -45,7 +45,7 @@ log() {
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -n "$print" ] || [ -n "$__verbose" ]; then
|
||||
if [ -n "$print" ] || [ -n "$verbose_output" ]; then
|
||||
if [ -n "$print" ] || [ -z "$ignore_verbose" ]; then
|
||||
echo -e "$message"
|
||||
fi
|
||||
@ -55,9 +55,13 @@ log() {
|
||||
sed -r 's/\x1B\[(([0-9]+)(;[0-9]+)*)?[m,K,H,f,J]//g' |
|
||||
while read -r line; do
|
||||
if [ -n "$line" ]; then
|
||||
if [ -n "$use_syslog" ]; then
|
||||
logger --id="$$" --tag boring_backup "$line"
|
||||
else
|
||||
# shellcheck disable=SC2154
|
||||
printf '[%s] %s\n' \
|
||||
"$(date +"$log_date_format")" "$line" >> "$__log_file"
|
||||
"$(date +"$log_date_format")" "$line" >> "$log_file"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
@ -69,7 +73,7 @@ handle_error() {
|
||||
|
||||
# Display amd log message
|
||||
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
|
||||
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';;
|
||||
tgz) cmpr_ext='.gz'; tar_ext='.tgz'; 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';;
|
||||
tz2) cmpr_ext='.bz2'; tar_ext='.tz2'; cmpr_cmd='bzip2';;
|
||||
tbz2) cmpr_ext='.bz2'; tar_ext='.tbz2'; cmpr_cmd='bzip2';;
|
||||
@ -172,16 +174,19 @@ compress_file() {
|
||||
# Compress file
|
||||
if [ -n "$cmpr_cmd" ]; then
|
||||
log -V "Compressing file $1 by ${cmpr_cmd%% *} ..."
|
||||
$cmpr_cmd "$1" 2>> "$__log_file"
|
||||
$cmpr_cmd "$1" 2>> "$log_file"
|
||||
compressed="${1}${cmpr_ext}"
|
||||
fi
|
||||
|
||||
# Remove original file.
|
||||
if [ -f "$compressed" ]; then
|
||||
if [ -f "$1" ]; then
|
||||
log "Remove uncompressed file $1"
|
||||
rm -- "$1"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
compressed="$1"
|
||||
fi
|
||||
|
||||
echo "$compressed"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user