This repository has been archived by the owner on Apr 2, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup
executable file
·69 lines (62 loc) · 1.88 KB
/
backup
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
#!/usr/bin/env bash
source $HOME/.config/backup/config
notify_backup () {
if [ -t 0 ]; then
echo $@
else
dunstify -i drive-multidisk "$@"
fi
}
case "$1" in
abort | cancel | end | exit | halt | int | interrupt | kill | quit | stop | term | terminate )
if [ -s $pidfile ]; then
kill $(cat $pidfile)
fi
exit 0
;;
esac
# make sure process is not already running
if [ -e $pidfile ]; then
if kill -0 &>1 > /dev/null $(cat $pidfile); then
notify_backup "A backup is already running!"
exit 1
else
rm $pidfile
fi
fi
echo $$ > $pidfile
cleanup () {
restic_status=$?
post_backup $restic_status >> $logfile
echo $restic_status >> $logfile
if [ $restic_status -eq 0 ]; then
action=$(notify_backup "Backup finished" --action="log,Show log")
elif [ $restic_status -eq 1 ]; then
action=$(notify_backup -u critical "Backup failed with code 1." --action="log,Show log" --action="info,More info")
elif [ $restic_status -eq 3 ]; then
action=$(notify_backup -u critical "Backup failed with code 3." "Some files couldn't be read." --action="log,Show log" --action="info,More info")
fi
case "$ACTION" in
"log")
$terminal_command "tac \"$(echo $logfile)\" | less"
;;
"info")
xdg-open "https://restic.readthedocs.io/en/stable/040_backup.html#exit-status-codes"
;;
esac
rm $pidfile
exit $restic_status
}
interrupted () {
kill $restic_pid
notify_backup "Backup cancelled"
exit 1
}
trap cleanup EXIT
trap interrupted INT TERM SIGINT SIGTERM
notify_backup "Backup starting"
pre_backup >> $logfile
# https://restic.readthedocs.io/en/stable/080_examples.html#backing-up-your-system-without-running-restic-as-root
sudo -u restic /home/restic/bin/restic $restic_opts -o rclone.args="serve restic --stdio --b2-hard-delete --contimeout=10m" --verbose=3 -r $dest --password-file=$passfile backup --files-from $includelist --exclude-file=$excludelist | tee $logfile &
restic_pid=$!
wait