forked from tutumcloud/dockup
-
Notifications
You must be signed in to change notification settings - Fork 9
/
test-backup.sh
executable file
·95 lines (80 loc) · 2.32 KB
/
test-backup.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
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
#!/bin/bash
#
# Simple test script for backup and restore
#
# Before running it, ensure there is a file test-env.txt
# with configuration options as in test-env.txt.sample
#
# Optionally use the ./gen-test-key.sh script to generate
# a GPG key used in this script.
set -e
GPG_KEYNAME=test-key
GPG_PASSPHRASE=dockup-test
# check for keyring
if [ ! -f "$GPG_KEYNAME.pub" ]; then
GPG_KEYNAME=""
fi
if [ "$1" == "--no-encryption" ]; then
GPG_KEYNAME=""
fi
# build dockup image
docker build -t wetransform/dockup:local .
# create data container
docker rm -v dockup-data-test || true
docker create --name dockup-data-test -v /data busybox
# create dummy file to backup
file_time=`date +%Y-%m-%d\\ %H:%M:%S\\ %Z`
echo "File created at $file_time" > tmpBackup.txt
docker cp tmpBackup.txt dockup-data-test:/data/file.txt
# generate a GPG key
#./gen-test-key.sh
#rc=$?; if [ $rc -ne 0 ]; then echo "ERROR: Error generating GPG key"; exit $rc; fi
# backup
docker run --rm \
--env-file test-env.txt \
-e BACKUP_NAME=dockup-test \
-e PATHS_TO_BACKUP=auto \
-e GPG_KEYNAME=$GPG_KEYNAME \
-e GPG_KEYRING=/$GPG_KEYNAME.pub \
--volumes-from dockup-data-test \
-v $(pwd)/$GPG_KEYNAME.pub:/$GPG_KEYNAME.pub \
-v $(pwd)/target:/dockup/target \
--name dockup-run-test wetransform/dockup:local
rc=$?; if [ $rc -ne 0 ]; then
echo "ERROR: Error running backup"
rm tmpBackup.txt
exit $rc
fi
# recreate data container
docker rm -v dockup-data-test || true
docker create --name dockup-data-test -v /data busybox
# restore
docker run --rm \
--env-file test-env.txt \
-e BACKUP_NAME=dockup-test \
-e PATHS_TO_BACKUP=/data \
-e GPG_KEYRING=/$GPG_KEYNAME.pub \
-e GPG_SECRING=/$GPG_KEYNAME.sec \
-e GPG_PASSPHRASE=$GPG_PASSPHRASE \
-e RESTORE=true \
--volumes-from dockup-data-test \
-v $(pwd)/$GPG_KEYNAME.pub:/$GPG_KEYNAME.pub \
-v $(pwd)/$GPG_KEYNAME.sec:/$GPG_KEYNAME.sec \
-v $(pwd)/target:/dockup/target \
--name dockup-run-test wetransform/dockup:local
rc=$?; if [ $rc -ne 0 ]; then
echo "ERROR: Error running restore"
rm tmpBackup.txt
exit $rc
fi
docker cp dockup-data-test:/data/file.txt tmpRestore.txt
cmp --silent tmpBackup.txt tmpRestore.txt
rc=$?
rm tmpBackup.txt
rm tmpRestore.txt
if [ $rc -ne 0 ]; then
echo "ERROR: Backup file is not identical to original"
exit $rc
else
echo "Restored file successfully"
fi