-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_btrsnap
executable file
·302 lines (290 loc) · 12 KB
/
test_btrsnap
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
#!/bin/bash
# skips most edge-case tests if set to 1
SKIP=${SKIP:-"0"}
# btrsnap-help
echo -e "\n### btrsnap help"
DRY_RUN=1 btrsnap help
if [ "$SKIP" -eq 0 ]; then
echo -e "\n### btrsnap -h"
DRY_RUN=1 btrsnap -h
fi
# btrsnap-env
echo -e "\n### btrsnap env"
DRY_RUN=1 btrsnap env
# btrsnap-list
echo -e "\n### btrsnap l -t"
DRY_RUN=1 btrsnap l -t
if [ "$SKIP" -eq 0 ]; then
# btrsnap-list help
echo -e "\n### btrsnap l -h"
DRY_RUN=1 btrsnap l -h
# btrsnap-list verbose
echo -e "\n### btrsnap l -v"
DRY_RUN=1 btrsnap l -v
# btrsnap-list simple output
echo -e "\n### btrsnap l -s"
DRY_RUN=1 btrsnap l -s
# btrsnap-list hourly output
echo -e "\n### btrsnap l --mode 1"
DRY_RUN=1 btrsnap l --mode 1
# btrsnap-list table output
echo -e "\n### btrsnap l -t --mode 0"
DRY_RUN=1 btrsnap l -t --mode 0
fi
# btrsnap-create
if [ "$SKIP" -eq 0 ]; then
# btrsnap-create help
echo -e "\n### btrsnap c -h"
DRY_RUN=1 btrsnap c -h
# btrsnap-create default
echo -e "\n### btrsnap create"
DRY_RUN=1 btrsnap create
# btrsnap-create custom format
echo -e "\n### btrsnap c -f %Y%M"
DRY_RUN=1 btrsnap c -f %Y%M
# btrsnap-create iso format
echo -e "\n### btrsnap c -f iso-8601=seconds"
DRY_RUN=1 btrsnap c -f iso-8601=seconds
echo -e "\n### btrsnap c -v"
# btrsnap-create verbose
DRY_RUN=1 btrsnap c -v
echo -e "\n### btrsnap c -b /snappies"
# btrsnap-create basedir (absolute)
DRY_RUN=1 btrsnap c -b /snappies
# btrsnap-create basedir (relative)
echo -e "\n### btrsnap c -b snappies"
DRY_RUN=1 btrsnap c -b snappies
# btrsnap-create message
echo -e "\n### btrsnap c -v -m \"Some special snapshot\" -b /snaps / root"
DRY_RUN=1 btrsnap c -v -m "Some special snapshot" -b /snaps / root
# btrsnap-create (absolute)
echo -e "\n### btrsnap c -v / /snapshots/root"
DRY_RUN=1 btrsnap c -v / /snapshots/root
# btrsnap-create non-subvolume
echo -e "\n### btrsnap c -v /etc etc"
DRY_RUN=1 btrsnap c -v /etc etc
# btrsnap-create hourly
echo -e "\n### btrsnap c -v --mode 1"
DRY_RUN=1 btrsnap c -v --mode 1
fi
# btrsnap-remove
if [ "$SKIP" -eq 0 ]; then
# btrsnap-remove (relative)
echo -e "\n### btrsnap c -f \"current\" / /snapshots/test"
echo "#### btrsnap rm -f test/current"
btrsnap c -f "current" / /snapshots/test
btrsnap rm -f test/current
# btrsnap-remove (absolute)
echo -e "\n### btrsnap c -f \"current\" / /snapshots/test"
echo "#### btrsnap rm -f /snapshots/test/current"
btrsnap c -f "current" / /snapshots/test
btrsnap rm -f /snapshots/test/current
# btrsnap-remove default
echo -e "\n### btrsnap c -f \"current\" / /snapshots/test"
echo "#### btrsnap rm -f"
btrsnap c -f "current" / /snapshots/test
btrsnap rm -f
# btrsnap-remove by index
echo "#### btrsnap rm -f -1"
btrsnap c -f "current" / /snapshots/test
btrsnap rm -f -1
# TODO: btrsnap-remove mode
# TODO: btrsnap-remove wildcard
fi
# btrsnap-diff
if [ "$SKIP" -eq 0 ]; then
# btrsnap-diff help
echo -e "\n### btrsnap d -h"
DRY_RUN=1 btrsnap d -h
# btrsnap-diff default
echo -e "\n### btrsnap d | head -n 30"
btrsnap l &> /dev/null
btrsnap d | head -n 30
fi
# btrsnap-diff latest
echo -e "\n### touch /test_file.txt"
echo "### btrsnap c -f \"prev\" / test"
echo "### echo \"TEST CONTENT\" >> /test_file.txt"
echo "#### btrsnap diff /snapshots/test/prev 0"
echo "### btrsnap rm -f /snapshots/test/prev"
echo "### rm /test_file.txt"
touch /test_file.txt
btrsnap c -f "prev" / test &>/dev/null
echo "TEST CONTENT" >> /test_file.txt
btrsnap diff /snapshots/test/prev 0
btrsnap rm -f /snapshots/test/prev &>/dev/null
rm /test_file.txt
# btrsnap-diff file
echo -e "\n### touch /test_file.txt"
echo "### btrsnap c -f \"prev\" / test"
echo "### echo \"TEST CONTENT\" >> /test_file.txt"
echo "#### btrsnap d -f /test_file.txt test/prev"
echo "### btrsnap rm -f /snapshots/test/prev"
echo "### rm /test_file.txt"
touch /test_file.txt
btrsnap c -f "prev" / test &>/dev/null
echo "TEST CONTENT" >> /test_file.txt
btrsnap d -f /test_file.txt test/prev
btrsnap rm -f /snapshots/test/prev &>/dev/null
rm /test_file.txt
# btrsnap-undo
if [ "$SKIP" -eq 0 ]; then
# btrsnap-undo help
echo "### btrsnap undo -h"
btrsnap undo -h
# btrsnap-undo (relative)
echo -e "\n### touch test_file.txt"
echo "### echo \"THIS SHOULD BE THE ONLY LINE AFTER btrsnap-undo\" >> test_file.txt"
echo "### btrsnap c -f \"prev\" /home /snapshots/test"
echo "### echo \"OHHH, SNAP! THIS IS ANOTHER LINE\" >> test_file.txt"
echo "#### btrsnap undo test_file.txt /snapshots/test/prev"
echo "### cat test_file.txt"
echo "### btrsnap rm -f /snapshots/test/prev"
echo "### rm test_file.txt"
touch test_file.txt
echo "THIS SHOULD BE THE ONLY LINE AFTER btrsnap-undo" >> test_file.txt
btrsnap c -f "prev" /home /snapshots/test &>/dev/null
echo "OHHH, SNAP! THIS IS ANOTHER LINE" >> test_file.txt
btrsnap undo test_file.txt /snapshots/test/prev
cat test_file.txt
btrsnap rm -f /snapshots/test/prev &>/dev/null
rm test_file.txt
# btrsnap-undo (from non-root)
echo -e "\n### touch /home/test_file.txt"
echo "### echo \"THIS SHOULD BE THE ONLY LINE AFTER btrsnap-undo\" >> /home/test_file.txt"
echo "### btrsnap c -f \"prev\" /home /snapshots/test"
echo "### echo \"OHHH, SNAP! THIS IS ANOTHER LINE\" >> /home/test_file.txt"
echo "#### btrsnap undo /home/test_file.txt /snapshots/test/prev"
echo "### cat /home/test_file.txt"
echo "### btrsnap rm -f /snapshots/test/prev"
echo "### rm /home/test_file.txt"
touch /home/test_file.txt
echo "THIS SHOULD BE THE ONLY LINE AFTER btrsnap-undo" >> /home/test_file.txt
btrsnap c -f "prev" /home /snapshots/test &>/dev/null
echo "OHHH, SNAP! THIS IS ANOTHER LINE" >> /home/test_file.txt
btrsnap undo /home/test_file.txt /snapshots/test/prev
cat /home/test_file.txt
btrsnap rm -f /snapshots/test/prev &>/dev/null
rm /home/test_file.txt
# btrsnap-undo default
echo -e "\n### touch /test_file.txt"
echo "### echo \"THIS SHOULD BE THE ONLY LINE AFTER btrsnap-undo\" >> /test_file.txt"
echo "### btrsnap c -f \"prev\" / /snapshots/test"
echo "### echo \"OHHH, SNAP! THIS IS ANOTHER LINE\" >> /test_file.txt"
echo "#### btrsnap undo /test_file.txt"
echo "### cat /test_file.txt"
echo "### btrsnap rm -f /snapshots/test/prev"
echo "### rm /test_file.txt"
touch /test_file.txt
echo "THIS SHOULD BE THE ONLY LINE AFTER btrsnap-undo" >> /test_file.txt
btrsnap c -f "prev" / /snapshots/test &>/dev/null
echo "OHHH, SNAP! THIS IS ANOTHER LINE" >> /test_file.txt
btrsnap undo /test_file.txt
cat /test_file.txt
btrsnap rm -f /snapshots/test/prev &>/dev/null
rm /test_file.txt
# btrsnap-undo directory
echo -e "\n### mkdir /testdir"
echo "### touch /testdir/test_file.txt"
echo "### echo \"THIS SHOULD BE THE ONLY LINE AFTER btrsnap-undo\" >> /testdir/test_file.txt"
echo "### btrsnap c -f \"prev\" / /snapshots/test"
echo "### echo \"OHHH, SNAP! THIS IS ANOTHER LINE\" >> /testdir/test_file.txt"
echo "#### btrsnap undo /testdir"
echo "### cat /testdir/test_file.txt"
echo "### btrsnap rm -f /snapshots/test/prev"
echo "### rm -r /testdir"
mkdir /testdir
touch /testdir/test_file.txt
echo "THIS SHOULD BE THE ONLY LINE AFTER btrsnap-undo" >> /testdir/test_file.txt
btrsnap c -f "prev" / /snapshots/test &>/dev/null
echo "OHHH, SNAP! THIS IS ANOTHER LINE" >> /testdir/test_file.txt
btrsnap undo /testdir
cat /testdir/test_file.txt
btrsnap rm -f /snapshots/test/prev &>/dev/null
rm -r /testdir
fi
# btrsnap undo file
echo -e "\n### touch /test_file.txt"
echo "### echo \"THIS SHOULD BE THE ONLY LINE AFTER btrsnap-undo\" >> /test_file.txt"
echo "### btrsnap c -f \"prev\" / /snapshots/test"
echo "### echo \"OHHH, SNAP! THIS IS ANOTHER LINE\" >> /test_file.txt"
echo "#### btrsnap undo /test_file.txt /snapshots/test/prev"
echo "### cat test_file.txt"
echo "### btrsnap rm -f /snapshots/test/prev"
echo "### rm /test_file.txt"
touch /test_file.txt
echo "THIS SHOULD BE THE ONLY LINE AFTER btrsnap-undo" >> /test_file.txt
btrsnap c -f "prev" / /snapshots/test &>/dev/null
echo "OHHH, SNAP! THIS IS ANOTHER LINE" >> /test_file.txt
btrsnap undo /test_file.txt /snapshots/test/prev
cat /test_file.txt
btrsnap rm -f /snapshots/test/prev &>/dev/null
rm /test_file.txt
# btrsnap-restore
echo ""
btrfs subvolume create $HOME/btrsnap_test
if [ "$SKIP" -eq 0 ]; then
# btrsnap-restore help
btrsnap restore --help
# btrsnap-restore device 0
echo -e "\n### btrsnap c -f \"current\" $HOME/btrsnap_test /snapshots/test"
echo "### touch $HOME/btrsnap_test/test_file.txt"
echo "#### btrsnap restore /snapshots/test/current $HOME/btrsnap_test"
echo "### ls $HOME/btrsnap_test/test_file.txt"
echo "### btrsnap rm -f /snapshots/test/current"
btrsnap c -f "current" $HOME/btrsnap_test /snapshots/test &>/dev/null
touch $HOME/btrsnap_test/test_file.txt
btrsnap restore -d 0 /snapshots/test/current $HOME/btrsnap_test
ls $HOME/btrsnap_test/test_file.txt 2> /dev/null
btrsnap rm -f /snapshots/test/current &>/dev/null
# btrsnap-restore device 1
echo -e "\n### btrsnap c -f \"current\" $HOME/btrsnap_test /snapshots/test"
echo "### touch $HOME/btrsnap_test/test_file.txt"
echo "#### btrsnap restore /snapshots/test/current $HOME/btrsnap_test"
echo "### ls $HOME/btrsnap_test/test_file.txt"
echo "### btrsnap rm -f /snapshots/test/current"
btrsnap c -f "current" $HOME/btrsnap_test /snapshots/test &>/dev/null
touch $HOME/btrsnap_test/test_file.txt
btrsnap restore -d 1 /snapshots/test/current $HOME/btrsnap_test
ls $HOME/btrsnap_test/test_file.txt 2> /dev/null
btrsnap rm -f /snapshots/test/current &>/dev/null
# btrsnap-restore device 2
echo -e "\n### btrsnap c -f \"current\" $HOME/btrsnap_test /snapshots/test"
echo "### touch $HOME/btrsnap_test/test_file.txt"
echo "#### btrsnap restore /snapshots/test/current $HOME/btrsnap_test"
echo "### ls $HOME/btrsnap_test/test_file.txt"
echo "### btrsnap rm -f /snapshots/test/current"
btrsnap c -f "current" $HOME/btrsnap_test /snapshots/test &>/dev/null
touch $HOME/btrsnap_test/test_file.txt
btrsnap restore -d 2 /snapshots/test/current $HOME/btrsnap_test
ls $HOME/btrsnap_test/test_file.txt 2> /dev/null
btrsnap rm -f /snapshots/test/current &>/dev/null
# btrsnap-restore default
echo -e "\n### btrsnap c -f \"current\" $HOME/btrsnap_test /snapshots/test"
echo "### touch $HOME/btrsnap_test/test_file.txt"
echo "#### btrsnap restore -d 1"
echo "### ls $HOME/btrsnap_test/test_file.txt"
echo "### btrsnap rm -f /snapshots/test/current"
btrsnap c -f "current" $HOME/btrsnap_test /snapshots/test &>/dev/null
touch $HOME/btrsnap_test/test_file.txt
btrsnap restore -d 1
ls $HOME/btrsnap_test/test_file.txt 2> /dev/null
btrsnap rm -f /snapshots/test/current &>/dev/null
fi
# btrsnap-restore default subvolume
echo "### touch $HOME/btrsnap_test/test_file.txt"
echo "### echo \"THIS SHOULD BE THE ONLY LINE AFTER btrsnap-restore\" >> $HOME/btrsnap_test/test_file.txt"
echo "### btrsnap c -f \"btrsnap_test\" $HOME/btrsnap_test /snapshots/test"
echo "### echo \"This content should not be visible after btrsnap-restore\" >> $HOME/btrsnap_test/test_file.txt"
echo "#### btrsnap restore -d 0 /snapshots/test/btrsnap_test"
echo "### cat $HOME/btrsnap_test/test_file.txt"
echo "### btrsnap rm -f /snapshots/test/btrsnap_test"
touch $HOME/btrsnap_test/test_file.txt
echo "THIS SHOULD BE THE ONLY LINE AFTER btrsnap-restore" >> $HOME/btrsnap_test/test_file.txt
btrsnap c -f "btrsnap_test" $HOME/btrsnap_test /snapshots/test &>/dev/null
echo "OHHH, SNAP! THIS IS ANOTHER LINE" >> $HOME/btrsnap_test/test_file.txt
btrsnap restore -d 0 /snapshots/test/btrsnap_test
cat $HOME/btrsnap_test/test_file.txt
btrsnap rm -f /snapshots/test/btrsnap_test &>/dev/null
rm $HOME/btrsnap_test/test_file.txt
btrfs subvolume delete $HOME/btrsnap_test