1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/borg_ynh.git synced 2024-09-03 18:16:05 +02:00

Add timestamp to logs, and log only to backup_borg.err (#55)

Co-authored-by: chateau <chateau@eauchat.org>
This commit is contained in:
Eauchat 2020-11-11 13:17:14 +00:00 committed by GitHub
parent ce1d78ea51
commit 30b7340878
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -14,6 +14,11 @@ do_need_mount() {
true true
} }
LOGFILE=/var/log/backup_borg.err
log_with_timestamp() {
sed -e "s/^/[$(date +"%Y-%m-%d_%H:%M:%S")] /" >> $LOGFILE
}
do_backup() { do_backup() {
export BORG_PASSPHRASE export BORG_PASSPHRASE
@ -23,12 +28,10 @@ do_backup() {
repo=$3 repo=$3
size=$4 size=$4
description=$5 description=$5
LOGFILE=/var/log/backup_borg.log
ERRFILE=/var/log/backup_borg.err
current_date=$(date +"%d_%m_%y_%H:%M") current_date=$(date +"%d_%m_%y_%H:%M")
pushd $work_dir pushd $work_dir
set +e set +e
if borg init -e repokey $repo >> $LOGFILE 2>> $ERRFILE; then if borg init -e repokey $repo 2>&1 >/dev/null | log_with_timestamp; then
#human_size=`echo $size | awk '{ suffix=" KMGT"; for(i=1; $1>1024 && i < length(suffix); i++) $1/=1024; print int($1) substr(suffix, i, 1), $3; }'` #human_size=`echo $size | awk '{ suffix=" KMGT"; for(i=1; $1>1024 && i < length(suffix); i++) $1/=1024; print int($1) substr(suffix, i, 1), $3; }'`
# Speed in Kbps # Speed in Kbps
#speed=1000 #speed=1000
@ -41,10 +44,10 @@ This is an automated message from your beloved YunoHost server." | /usr/bin/mail
fi fi
set -e set -e
borg create $repo::${name}_${current_date} ./ >> $LOGFILE 2>> $ERRFILE borg create $repo::${name}_${current_date} ./ 2>&1 >/dev/null | log_with_timestamp
popd popd
borg prune $repo -P ${name} --keep-hourly 2 --keep-daily=7 --keep-weekly=8 --keep-monthly=12 >> $LOGFILE 2>> $ERRFILE borg prune $repo -P ${name} --keep-hourly 2 --keep-daily=7 --keep-weekly=8 --keep-monthly=12 2>&1 >/dev/null | log_with_timestamp
} }
do_mount() { do_mount() {
@ -55,9 +58,7 @@ do_mount() {
repo=$3 repo=$3
size=$4 size=$4
description=$5 description=$5
LOGFILE=/var/log/backup_borg.log borg mount $repo::$name $work_dir 2>&1 >/dev/null | log_with_timestamp
ERRFILE=/var/log/backup_borg.err
borg mount $repo::$name $work_dir >> $LOGFILE 2>> $ERRFILE
} }
work_dir=$2 work_dir=$2