/
backup-to-restic
executable file
·70 lines (59 loc) · 2.09 KB
/
backup-to-restic
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
#!/bin/sh
# restic credential should be put in ~/.config/restic-password.conf
# rclone must be configured in advanced
#
# to restore latest snapshot "in-place": backup-to-restic restore --target / latest
#
if [ ! -d $HOME/.config/rclone ]; then
echo "please configure rclone first"
exit 1
fi
LATEST_SNAPSHOT="$HOME/.snapshots/$(ls ~/.snapshots/ --sort=time -r | tail -1)/snapshot"
[ -d $LATEST_SNAPSHOT ] || LATEST_SNAPSHOT="$HOME"
cat << EOF > /tmp/restic-exclude.conf
.cache
.config/chromium
.config/google-chrome*
.config/**/IndexedDB
.config/**/Service\ Worker
.config/**/Extensions
.config/**/GPUCache
.config/**/Code\ Cache
.config/Microsoft Teams*
.config/epiphany/gsb-threats.db
.config/libreoffice/*/user/gallery
.config/Code/Cache*
.config/keycombiner/Cache
.config/microsoft-edge*
.local/share/flatpak/repo/objects
.local/share/flatpak/repo/tmp
.local/share/flatpak/appstream
.local/share/flatpak/app
.local/share/flatpak/runtime
.local/share/flatpak/.removed/
.mozilla
Documents/perso
Téléchargements
Musique
Vidéos
EOF
# disable selinux, it doesn't play well with access to whole directory and podman as rootless container
podman container run -d --pull always --name rclone_container --hostname $(hostname) --security-opt label=disable --replace -v /tmp/restic-exclude.conf:/tmp/restic-exclude.conf:ro -v /etc/localtime:/etc/localtime:ro -v $LATEST_SNAPSHOT:$HOME -v $HOME/.config/rclone:/config/rclone registry.opensuse.org/home/fcrozat/bci/containerfile_tw/opensuse/rclone:latest -vv serve restic onedrive:restic
if [ $? -gt 0 ]; then
echo "couldn't create container"
exit 1
fi
# waiting for rclone to be ready to serve
(podman logs -f rclone_container 2>&1 &) | grep -q 'Serving restic REST API'
# to be done only one it
# restic init
# allow start the rclone container
if [ $# -eq 0 ]; then
CMD="backup -v --exclude-caches --exclude-file /tmp/restic-exclude.conf --one-file-system /home/fcrozat"
else
CMD="$@"
fi
podman exec rclone_container restic -r rest:http://localhost:8080/ --password-file $HOME/.config/restic-password.conf $CMD
podman stop rclone_container
rm -f /tmp/restic-exclude.conf
exit 0