-
Notifications
You must be signed in to change notification settings - Fork 12
/
vbox-restore-test.sh
executable file
·135 lines (110 loc) · 3.96 KB
/
vbox-restore-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
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
#!/bin/bash
#
# This script is to be run after vbox-backup-test.sh. It will restore backups
# in TEST_DIR/vbox-*-storage to TEST_DIR/vbox-*-restore
#
# NOTE:
# Please make sure that this script doesn't run pass midnight, otherwise it
# would not be able to restore duplicity backups because it assumed backups were
# created on the same day.
#
if [ "$#" -eq 0 ]; then
echo "Usage: $0 <test dir>"
exit 1
fi
if [ -z "$DUPLICACY_PATH" ]; then
echo "DUPLICACY_PATH must be set to the path of the Duplicacy executable"
exit 1
fi
if [ -z "$RESTIC_PATH" ]; then
echo "RESTIC_PATH must be set to the path of the restic executable"
exit 1
fi
if [ -z "$ATTIC_PATH" ]; then
echo "ATTIC_PATH must be set to the path of the attic executable"
exit 1
fi
if [ -z "$DUPLICITY_PATH" ]; then
echo "DUPLICITY_PATH must be set to the path of the duplicity executable"
exit 1
fi
if [ -z "$GPG_KEY" ]; then
echo "GPG_KEY must be set for duplicity to work properly"
exit 1
fi
if [ -z "$PASSPHRASE" ]; then
echo "PASSPHRASE must be set for duplicity to work properly"
exit 1
fi
# Set up directories
TEST_DIR=$1
DUPLICACY_STORAGE=${TEST_DIR}/vbox-duplicacy-storage
RESTIC_STORAGE=${TEST_DIR}/vbox-restic-storage
ATTIC_STORAGE=${TEST_DIR}/vbox-attic-storage
DUPLICITY_STORAGE=${TEST_DIR}/vbox-duplicity-storage
DUPLICACY_RESTORE=${TEST_DIR}/vbox-duplicacy-restore
RESTIC_RESTORE=${TEST_DIR}/vbox-restic-restore
ATTIC_RESTORE=${TEST_DIR}/vbox-attic-restore
DUPLICITY_RESTORE=${TEST_DIR}/vbox-duplicity-restore
# Used as the storage password throughout the tests
PASSWORD=12345678
rm -rf ${DUPLICACY_RESTORE}
mkdir -p ${DUPLICACY_RESTORE}
rm -rf ${RESTIC_RESTORE}
mkdir -p ${RESTIC_RESTORE}
rm -rf ${ATTIC_RESTORE}
mkdir -p ${ATTIC_RESTORE}
rm -rf ${DUPLICITY_RESTORE}
mkdir -p ${DUPLICITY_RESTORE}
function duplicacy_restore()
{
rm -rf ${DUPLICACY_RESTORE}/*
pushd ${DUPLICACY_RESTORE}
time env DUPLICACY_PASSWORD=${PASSWORD} ${DUPLICACY_PATH} restore -r $1 -stats | grep -v Downloaded
popd
}
function restic_restore()
{
rm -rf ${RESTIC_RESTORE}/*
# We need to find the snapshot id to restore
TODAY=`date +"%Y-%m-%d"`
SNAPSHOT=`env RESTIC_PASSWORD=${PASSWORD} ${RESTIC_PATH} -r ${RESTIC_STORAGE} snapshots | grep $TODAY | head -n $1 | tail -n 1 | awk '{print $1;}'`
echo Restoring from $SNAPSHOT
time env RESTIC_PASSWORD=${PASSWORD} ${RESTIC_PATH} -r ${RESTIC_STORAGE} restore $SNAPSHOT --target ${RESTIC_RESTORE}
}
function attic_restore()
{
rm -rf ${ATTIC_RESTORE}/*
pushd ${ATTIC_RESTORE}
time env BORG_PASSPHRASE=${PASSWORD} ${ATTIC_PATH} extract ${ATTIC_STORAGE}::$1
popd
}
function duplicity_restore()
{
rm -rf ${DUPLICITY_RESTORE}/*
# duplicity is crazy -- the --restore-time option doesn't take the time format printed by its own colleciton-status command!
TODAY=`date +"%Y-%m-%d"`
RESTORE_TIME=`${DUPLICITY_PATH} -v0 --encrypt-key ${GPG_KEY} --sign-key ${GPG_KEY} collection-status file://${DUPLICITY_STORAGE} | grep 'Full\|Incremental' | head -n $1 | tail -n 1 | awk '{print $5;}'`
RESTORE_TIME=${TODAY}T${RESTORE_TIME}
echo Restoring from $RESTORE_TIME
time ${DUPLICITY_PATH} --force -v0 --encrypt-key ${GPG_KEY} restore -t $RESTORE_TIME file://${DUPLICITY_STORAGE} ${DUPLICITY_RESTORE}
}
function all_restore()
{
echo ======================================== restore $1 ========================================
duplicacy_restore $1
#restic_restore $1
attic_restore $1
#duplicity_restore $1
}
# Initialize the duplicacy directory to be restored
pushd ${DUPLICACY_RESTORE}
env DUPLICACY_PASSWORD=${PASSWORD} ${DUPLICACY_PATH} init test ${DUPLICACY_STORAGE} -e
popd
echo restic snapshots:
env RESTIC_PASSWORD=${PASSWORD} ${RESTIC_PATH} -r ${RESTIC_STORAGE} snapshots
echo duplicity archives:
${DUPLICITY_PATH} -v0 --encrypt-key ${GPG_KEY} --sign-key ${GPG_KEY} collection-status file://${DUPLICITY_STORAGE} | grep "Full\|Incremental"
all_restore 1
all_restore 2
all_restore 3