-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup.sh
executable file
·67 lines (59 loc) · 2.21 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh
export REPO='/home/asadik/.borg_backup'
export BORG_PASSPHRASE=''
# die if borg is already running
if pidof -x borg >/dev/null; then
echo "Backup already running"
exit
fi
# get last backup name to see if it was done today
last_backup_date=$(borg list --last 1 $REPO | cut -f1 -d' ' | grep -v "checkpoint" | grep -E "[0-9]{4}-[0-9]{2}-[0-9]{2}" -o)
today=$(date +%Y-%m-%d)
if [ "$last_backup_date" != "$today" ]; then
notify-send "Backups" "Starting Backup" -t 60000 --urgency=normal --icon=dialog-warning
borg create --compression zstd,9 --stats -v \
$REPO::'{hostname}-{now:%Y-%m-%d}' \
/home/asadik \
--exclude '/home/asadik/.borg_backup' \
--exclude '/home/asadik/.local' \
--exclude '/home/asadik/Dropbox' \
--exclude '/home/asadik/backup_exclusions' \
--exclude '/home/asadik/.cache'
# prune to remove old backups
borg prune -v --stats --list $REPO --prefix '{hostname}-' \
--keep-daily=7 --keep-weekly=4 --keep-monthly=3
notify-send "Backup Status" "Backup finished" -t 60000 --urgency=normal --icon=dialog-information
else
echo "Backup already done today."
fi
# check if we're on my wifi network
networkname=$(iwgetid -r)
if [ "$networkname" == '715 - CR∑∑KS' ]; then
# we're tethered to my phone
# bail
echo "Connected to phone, not uploading to aws"
exit
fi
# check if our connection sucks
# or if it's too good to be true
speed=$(ping amazonaws.com -c 1 | sed -n 2p | cut -f4 -d'=' | cut -f1 -d' ' | cut -f1 -d'.')
if [[ $speed -gt 200 ]] || [[ $speed -lt 5 ]]; then
# bad connection
# bail
echo "Connection speed is too slow ($speed)! Bailing"
exit
fi
# make sure upload isn't already running
if pidof -x aws >/dev/null; then
echo "Upload already running"
exit
fi
echo "Uploading..."
aws s3 sync --quiet $REPO s3://peterpanda2-backups --storage-class STANDARD_IA --delete
rc=$?
if [ $rc != 0 ]; then
notify-send "AWS Sync Status" "FAILED" -t 60000 --urgency=normal --icon=dialog-error
else
notify-send "AWS Sync Status" "Complete!" -t 60000 --urgency=normal --icon=dialog-information
echo "Done!"
fi