mirror of
https://github.com/lobaro/restic-backup-docker.git
synced 2026-05-07 01:05:24 +00:00
Execute prune after forget, Improove logging
- Log start and end with total duration - Copy backup-last.log to backup-error-last.log after fail
This commit is contained in:
@@ -1,27 +1,60 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo "Starting Backup"
|
||||
lastLogfile="/var/log/backup-last.log"
|
||||
|
||||
copyErrorLog() {
|
||||
cp ${lastLogfile} /var/log/backup-error-last.log
|
||||
}
|
||||
|
||||
logLast() {
|
||||
echo "$1" >> ${lastLogfile}
|
||||
}
|
||||
|
||||
start=`date +%s`
|
||||
rm -f ${lastLogfile}
|
||||
echo "Starting Backup at $(date +"%Y-%m-%d %H:%M:%S")"
|
||||
echo "Starting Backup at $(date)" >> ${lastLogfile}
|
||||
logLast "BACKUP_CRON: ${BACKUP_CRON}"
|
||||
logLast "RESTIC_TAG: ${RESTIC_TAG}"
|
||||
logLast "RESTIC_FORGET_ARGS: ${RESTIC_FORGET_ARGS}"
|
||||
|
||||
|
||||
# Do not save full backup log to logfile but to backup-last.log
|
||||
restic backup /data --tag=${RESTIC_TAG?"Missing environment variable RESTIC_TAG"} > /var/log/backup-last.log 2>&1
|
||||
restic backup /data --tag=${RESTIC_TAG?"Missing environment variable RESTIC_TAG"} >> ${lastLogfile} 2>&1
|
||||
rc=$?
|
||||
echo "Finished backup at $(date)" >> /var/log/backup-last.log
|
||||
logLast "Finished backup at $(date)"
|
||||
if [[ $rc == 0 ]]; then
|
||||
echo "Backup Successfull"
|
||||
else
|
||||
echo "Backup Failed with Status ${rc}"
|
||||
restic unlock
|
||||
copyErrorLog
|
||||
fi
|
||||
|
||||
if [ -n "${RESTIC_FORGET_ARGS}" ]; then
|
||||
echo "Forget about old snapshots based on RESTIC_FORGET_ARGS = ${RESTIC_FORGET_ARGS}"
|
||||
restic forget ${RESTIC_FORGET_ARGS} >> /var/log/backup-last.log 2>&1
|
||||
restic forget ${RESTIC_FORGET_ARGS} >> ${lastLogfile} 2>&1
|
||||
rc=$?
|
||||
echo "Finished forget at $(date)" >> /var/log/backup-last.log
|
||||
logLast "Finished forget at $(date)"
|
||||
if [[ $rc == 0 ]]; then
|
||||
echo "Forget Successfull"
|
||||
echo "Prune obsolete data"
|
||||
restic prune >> ${lastLogfile} 2>&1
|
||||
rc=$?
|
||||
logLast "Finished prune at $(date)"
|
||||
if [[ $rc == 0 ]]; then
|
||||
echo "Prune Successfull"
|
||||
else
|
||||
echo "Prune Failed with Status ${rc}"
|
||||
restic unlock
|
||||
copyErrorLog
|
||||
fi
|
||||
else
|
||||
echo "Forget Failed with Status ${rc}"
|
||||
restic unlock
|
||||
copyErrorLog
|
||||
fi
|
||||
fi
|
||||
|
||||
end=`date +%s`
|
||||
echo "Finished Backup at $(date +"%Y-%m-%d %H:%M:%S") after $((end-start)) sconds"
|
||||
|
||||
@@ -7,7 +7,8 @@ echo "Start backup-test container. Backup of ~/test-data/ to repository ~/test-r
|
||||
docker run --privileged --name backup-test \
|
||||
-e "RESTIC_PASSWORD=test" \
|
||||
-e "RESTIC_TAG=test" \
|
||||
-e "BACKUP_CRON=* * * * *" \
|
||||
-e "BACKUP_CRON=0 0 * * *" \
|
||||
-e "RESTIC_FORGET_ARGS=--keep-last 10" \
|
||||
-v ~/test-data:/data \
|
||||
-v ~/test-repo/:/mnt/restic \
|
||||
-t restic-backup
|
||||
|
||||
Reference in New Issue
Block a user