-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestic-backups
executable file
·168 lines (134 loc) · 2.8 KB
/
restic-backups
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/bin/bash
# Available commands:
#
# restic-backups backup <id_repo>
# restic-backups prune <id_repo>
# restic-backups prune_single <hash_snapshot>
# restic-backups snapshots <id_repo>
# restic-backups restore <id_repo> <hash_snapshot> /destination/folder
# restic-backups restore <id_repo> /destination/folder
# restic-backups cli <id_repo> [comando e opzioni, esempio cat config]
exclude_programming=/home/iux/Documents/scripts/restic/excludes_programming.txt
repo_programming=/mnt/Synology/MatiuxHome/Backup/Programming
host_programming=/home/iux/Documents/Programming
exclude_documents=/home/iux/Documents/scripts/restic/excludes_documents.txt
repo_documents=/mnt/Synology/MatiuxHome/Backup/Documents
host_documents=/home/iux/Documents/
exclude_kde=/home/iux/Documents/scripts/restic/excludes_kde.txt
repo_kde=/mnt/Synology/MatiuxHome/Backup/KdeHome
host_kde="/home/iux/.cache/zellij/ /home/iux/.config /home/iux/.local/share/konsole/ /home/iux/.local/share/plasma_notes/"
PWD_FILE=/home/iux/Documents/scripts/restic/resticp.txt
KEEP_LAST=10
CMD=$1
REPO=repo_$2
HOST=host_$2
EXCLUDE="exclude_$2"
backup() {
# Create a snapshot
host=${1}
repo=${2}
restic -r $repo \
backup \
--password-file=$PWD_FILE \
--verbose=2 \
--compression=max \
--exclude-file=${!EXCLUDE} \
$host
}
snapshots() {
# List snapshots
repo=${1}
restic -r $repo \
snapshots \
--verbose=2 \
--password-file=$PWD_FILE
}
prune() {
# Delete old snapshots except last ${KEEP_LAST} (deleting data as well)
repo=${1}
restic -r $repo \
forget \
--keep-last ${KEEP_LAST} \
--prune \
--verbose=2 \
--password-file=${PWD_FILE}
}
prune_single() {
# Delete a specific snapshot (also deleting the data)
repo=${1}
hash=${2}
restic -r $repo \
forget \
--prune $hash \
--verbose=2 \
--password-file=$PWD_FILE
}
restore() {
# Restore a snapshot
repo=${1}
hash=${2}
destination=${3}
restic -r $repo \
restore $hash \
--target=$destination \
--password-file=$PWD_FILE \
--verbose=2
}
restore_latest() {
# Restore of the last snapshot
repo=${1}
destination=${2}
restic -r $repo \
restore latest \
--target=$destination \
--password-file=$PWD_FILE \
--verbose=2
}
cli() {
repo=repo_$2
repo=${!repo}
shift 2
params="$@"
echo "Command: $repo"
echo "Params: $params"
restic -r $repo \
--password-file=$PWD_FILE \
--verbose=2 \
$params
}
while :; do
case $CMD in
backup)
backup ${!HOST} ${!REPO}
break
;;
snapshots)
snapshots ${!REPO}
break
;;
prune)
prune ${!REPO}
break
;;
prune_single)
hash=$3
prune_single ${!REPO} $hash
break
;;
restore)
hash=$3
destination=$4
restore ${!REPO} $hash $destination
break
;;
restore_latest)
destination=$3
restore_latest ${!REPO} $destination
break
;;
cli)
cli $@
break
;;
esac
done