-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
63 lines (50 loc) · 1.16 KB
/
test.sh
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
#!/usr/bin/env bash
sync=./git_backup
dst="../sync_depositery"
src="../track_folder"
init_test_folder() {
#prepare desination
rm -rf "$dst"
$sync init "$dst"
$sync track "$src" to_sync
rm -rf "$src"
mkdir -p "$src"
mkdir "$src/A"
echo A > "$src/A/a"
mkdir "$src/B"
echo A > "$src/B/b"
}
backup() {
$sync backup to_sync
}
restore() {
$sync restore to_sync
}
add_some_updates() {
echo B >> "$src/A/a"
echo B >> "$src/B/b"
}
md5_folder() {
#should be enough to test integrity
#NOTE: not sure that find will output filename in the same order
#=> long way for sorting before aggregating output for md5
find "$1" -type f |sort | xargs cat |md5sum | awk '{ print $1 }'
}
test_restore_feature() {
init_test_folder
backup
add_some_updates
backup
md5_before=$(md5_folder "$src")
#make local changes (non part of any backup)
echo noise > "$src/A/a"
restore
md5_after=$(md5_folder "$src")
if [[ $md5_before == $md5_after ]]
then
echo "[+] Backup successfuly restored."
else
echo "[x] Backup restore failed. Begin to pray"
fi
}
test_restore_feature