-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpins2-backup
executable file
·58 lines (48 loc) · 989 Bytes
/
pins2-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
#!/usr/bin/env bash
set -e
usage() {
echo "Usage: $0 <command> [NAME] [PATH]"
echo "Commands: archive | clean"
echo "Expects BORG_REPO env variable to be set"
exit 1
}
COMMAND="$1"
NAME="$2"
SOURCE_PATH="$3"
if [ -z "$SOURCE_PATH" ]; then
usage
fi
if [ -z "$NAME" ]; then
usage
fi
if [ -z "$BORG_REPO" ]; then
usage
fi
case "$COMMAND" in
archive)
SNAP="system-$(date +%Y-%m-%d)"
/usr/local/bin/with-system-snapshot "$SNAP" -- /usr/bin/borg create \
--verbose \
--stat \
--progress \
--compression zlib \
--lock-wait 86400 \
"${BORG_REPO}"::"$NAME"-{now} \
"/.snapshots/$SNAP/$SOURCE_PATH"
;;
clean)
echo "Pruning ..."
/usr/bin/borg prune \
--list \
--glob-archives "$NAME"- \
--show-rc \
--keep-daily 1 \
--keep-weekly 1 \
--keep-monthly 1
echo "Compacting ..."
/usr/bin/borg compact \
--progress \
"${BORG_REPO}"
;;
*) usage ;;
esac