This repository was archived by the owner on Mar 9, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrestic-backup.sh
More file actions
executable file
·57 lines (42 loc) · 1.6 KB
/
Copy pathrestic-backup.sh
File metadata and controls
executable file
·57 lines (42 loc) · 1.6 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
#!/bin/bash
# This is a script to automate restic backups
# Setting for this script are stored in the settings.sh file
# Do NOT modify this file directly
# configuration is done inside of the settings.sh file
source /home/nick/restic/settings.sh
# Stage 0, Test config
# Ping healthchecks to start the job and record run time
curl -fsS -m 10 --retry 5 "$CHECKIN_URL/start"
echo ""
CHECK_OUTPUT=$(restic cat config 2>&1)
if [[ $? -eq 0 ]]; then
echo "Repo connected sucessfully"
else
# If unsucessfull, return an error status code and the output to healthchecks
# Then exit the script
curl -fsS -m 10 --retry 5 --data-raw "$CHECK_OUTPUT" "$CHECKIN_URL/$?"
exit
fi
# Stage 1, Run backup
echo "Taking backups to "$RESTIC_REPOSITORY
# Use a list of given directories to backup
# Capture the output of the backup command inside the output variable
# and ship it off to healthcheck server for notification and logging
# Store the exit code of the last run, check it is non zero and continue
OUTPUT=$(echo "Backing up the following directories"
cat $BACKUP_SOURCE
restic backup --retry-lock 1h --one-file-system --tag v2_script --files-from=$BACKUP_SOURCE --exclude-file=$EXCLUDE_FILE --exclude-caches 2>&1
EXIT_CODE=$?
echo ""
if [[ $EXIT_CODE -ne 0 ]]; then
# An exit code of 3 means some files were inaccessable during the snapshot
if [[ $EXIT_CODE -eq 3 ]]; then
echo "The previous backup run could not access certain files"
exit 0
fi
exit $EXIT_CODE
fi
)
# Stage 2 send the report
curl -fsS -m 10 --retry 5 --data-raw "$OUTPUT" "$CHECKIN_URL/$?"
echo ""