-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestic-backup.sh
executable file
·47 lines (38 loc) · 1.11 KB
/
restic-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
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
if [[ -z "$RESTIC_PASSWORD" ]]; then
echo "Missing RESTIC_PASSWORD" >&2
exit 1
elif [[ -z "$RESTIC_REPOSITORY" ]]; then
echo "Missing RESTIC_REPOSITORY" >&2
exit 1
elif [[ -z "$1" ]]; then
echo "Missing directories to backup" >&2
exit 1
fi
export PATH=$PATH:/usr/local/bin/
LOGDIR=${HOME}/.restic/logs/
mkdir -p $LOGDIR
LOGDATE=$(date +%Y-%m-%dT%H-%M-%S)
exec > ${LOGDIR}/${LOGDATE}.log
exec 2>&1
unameOut="$(uname -s)"
# Some operations are expensive. Only run them if on AC power
if [[ "$unameOut" == "Darwin" ]]; then
ON_AC=$(/usr/sbin/system_profiler SPPowerDataType | grep -A3 "AC Charger" | grep "Connected" | awk '{print $2}')
elif [[ "$unameOut" == "Linux" ]]; then
# TODO: need to implement
ON_AC=""
else
echo "Unknown OS: $unameOut" >&2
exit 1
fi
dirs=( "$@" )
restic --verbose backup --one-file-system ${dirs[@]}
restic forget --keep-hourly 8 --keep-daily 7 --keep-weekly 4 --keep-monthly 6
if [[ $ON_AC == "Yes" ]]; then
# TODO: make a separate restic check script
#restic check --read-data-subset=1G
restic prune
fi