This repository was archived by the owner on Apr 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup.sh
More file actions
executable file
·69 lines (59 loc) · 1.86 KB
/
Copy pathbackup.sh
File metadata and controls
executable file
·69 lines (59 loc) · 1.86 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
set -uo pipefail
restic cat config
status=$?
echo "Check repo status $status"
if [ $status != 0 ]; then
echo "Repository '${RESTIC_REPOSITORY}' does not exist. Initialize repo with 'restic init'."
exit 1
fi
if [ -f "/hooks/pre-backup.sh" ]; then
echo "Running pre-backup script."
/hooks/pre-backup.sh
else
echo "No /hooks/pre-backup.sh script found. Skipping."
fi
start=$(date +'%s')
echo "Starting Backup at $(date +"%Y-%m-%d %H:%M:%S")"
echo "RESTIC_REPOSITORY: ${RESTIC_REPOSITORY:-}"
echo "RESTIC_PASSWORD: $(test -n "${RESTIC_PASSWORD}" && echo "<set>" || echo "<not set>")"
echo "RESTIC_JOB_ARGS: ${RESTIC_JOB_ARGS:-}"
echo "RESTIC_FORGET_ARGS: ${RESTIC_FORGET_ARGS:-}"
echo ""
echo "Directory tree:"
tree -xdp /data
# shellcheck disable=SC2086
restic backup /data ${RESTIC_JOB_ARGS}
rc_backup=$?
echo "Finished backup at $(date +"%Y-%m-%d %H:%M:%S")"
if [[ $rc_backup == 0 ]]; then
echo "Backup Successful"
else
echo "Backup Failed with Status ${rc_backup}"
restic unlock
fi
if [ -n "${RESTIC_FORGET_ARGS:-}" ]; then
echo "Forgetting old snapshots based on RESTIC_FORGET_ARGS = ${RESTIC_FORGET_ARGS}"
# shellcheck disable=SC2086
restic forget ${RESTIC_FORGET_ARGS}
rc_forget=$?
echo "Finished forget at $(date +"%Y-%m-%d %H:%M:%S")"
if [[ $rc_forget == 0 ]]; then
echo "Forget Successful"
else
echo "Forget Failed with Status ${rc_forget}"
restic unlock
fi
else
echo "No RESTIC_FORGET_ARGS provided. Skipping forget."
rc_forget=0
fi
end=$(date +'%s')
echo "Finished Backup at $(date +"%Y-%m-%d %H:%M:%S") after $((end - start)) seconds"
if [ -f "/hooks/post-backup.sh" ]; then
echo "Running post-backup script."
RC_BACKUP=$rc_backup RC_FORGET=$rc_forget /hooks/post-backup.sh
else
echo "No /hooks/post-backup.sh script found. Skipping."
fi
exit $((rc_backup + rc_forget))