forked from lobaro/restic-backup-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup.sh
executable file
·51 lines (43 loc) · 1.35 KB
/
backup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/sh
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}"
logLast "RESTIC_JOB_ARGS: ${RESTIC_JOB_ARGS}"
# Do not save full backup log to logfile but to backup-last.log
restic backup /data ${RESTIC_JOB_ARGS} --tag=${RESTIC_TAG?"Missing environment variable RESTIC_TAG"} >> ${lastLogfile} 2>&1
rc=$?
logLast "Finished backup at $(date)"
if [[ $rc == 0 ]]; then
echo "Backup Successfull"
else
echo "Backup Failed with Status ${rc}"
restic unlock
copyErrorLog
kill 1
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} >> ${lastLogfile} 2>&1
rc=$?
logLast "Finished forget at $(date)"
if [[ $rc == 0 ]]; then
echo "Forget Successfull"
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)) seconds"