-
Notifications
You must be signed in to change notification settings - Fork 0
/
restic.conf
131 lines (115 loc) · 3.51 KB
/
restic.conf
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
just_flags := "--justfile ${DOCKER_RESTIC_DIR}/config/restic.conf --working-directory ${DOCKER_RESTIC_DIR}"
restic_flags := "--repo ${DOCKER_RESTIC_DIR}/data/repository --password-file /run/secrets/restic-password"
rclone_flags := "--password-command 'cat /run/secrets/rclone-password'"
default:
@just {{just_flags}} --list
init:
-@just {{just_flags}} init_restic
-@just {{just_flags}} init_rclone
backup:
@just {{just_flags}} container_stop
-restic backup /source {{restic_flags}}
@just {{just_flags}} container_start
backup_prune:
restic forget {{restic_flags}} \
--keep-daily 7 \
--keep-weekly 4 \
--keep-monthly 12 \
--keep-yearly 2 \
--group-by paths \
--prune
backup_check:
restic check {{restic_flags}} \
--read-data
backup_check_subset percent:
restic check {{restic_flags}} \
--read-data-subset {{percent}}%
sync remotes:
set -euo pipefail \
&& for remote in {{remotes}}; do \
rclone sync ${DOCKER_RESTIC_DIR}/data/repository ${remote} {{rclone_flags}} \
--stats 15m \
--fast-list \
--progress; \
done
sync_check remotes:
set -euo pipefail \
&& for remote in {{remotes}}; do \
rclone check ${DOCKER_RESTIC_DIR}/data/repository ${remote} {{rclone_flags}} \
--stats 15m \
--fast-list \
--progress; \
done
dump:
set -euo pipefail \
&& restic dump latest / {{restic_flags}} \
--archive tar \
| gpg \
--cipher-algo AES256 \
--passphrase-file /run/secrets/restic-password \
--output ${DOCKER_RESTIC_DIR}/data/export/backup_$(date +'%Y-%m-%d_%H.%M.%S').tar.gpg \
--compress-level 0 \
--symmetric \
--batch \
--yes \
--verbose
dump_prune:
set -euo pipefail \
&& ls -t ${DOCKER_RESTIC_DIR}/data/export/backup_* \
| tail +7 \
| xargs -r rm -rf
dump_check:
set -euo pipefail \
&& ls -t ${DOCKER_RESTIC_DIR}/data/export/backup_* \
| head -1 \
| xargs -r gpg \
--passphrase-file /run/secrets/restic-password \
--decrypt \
--batch \
--yes \
--verbose \
| tar -tf - > /dev/null
[private]
init_restic:
restic init {{restic_flags}}
[private]
init_rclone:
#!/usr/bin/env sh
# Rclone does not provide a non-interactive method to encrypt the configuration file via CLI.
# Therefore, the `expect` tool is used to automate the interactive encryption process.
expect <<EOF
set timeout 1
spawn rclone config
expect "n/s/q>" { send "s\r" }
expect "a/q>" { send "a\r" }
expect "password:" { send "$(cat '/run/secrets/rclone-password')\r" }
expect "password:" { send "$(cat '/run/secrets/rclone-password')\r" }
expect "c/u/q>" { send "q\r" }
expect "n/s/q>" { send "q\r" }
expect eof
EOF
[private]
container_start:
set -euo pipefail \
&& docker ps \
--quiet \
--filter label=docker-restic.container.stop=true \
--filter status=exited \
| xargs -r docker restart > /dev/null
[private]
container_stop:
set -euo pipefail \
&& docker ps \
--quiet \
--filter label=docker-restic.container.stop=true \
| xargs -r docker stop > /dev/null
[private]
container_exec:
set -euo pipefail \
&& docker ps \
--quiet \
--filter label=docker-restic.container.exec \
| xargs -r -I {} \
docker inspect --format '{{{{.Id}}}} {{{{index .Config.Labels "docker-restic.container.exec"}}}}' {} \
| xargs -r -n2 \
/bin/sh -c 'docker exec $0 /bin/sh -c "$1"'