3 # Cumulus: Efficient Filesystem Backup to the Cloud
4 # Copyright (C) 2012 The Cumulus Developers
5 # See the AUTHORS file for a list of contributors.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 # Perform a simple Cumulus integration test: create a sample file tree, create
22 # a backup, modify the files, create a new backup, then try restoring and
23 # compare with the original state.
25 # Directory containing test scripts
26 TEST_DIR="$(readlink -f "$(dirname "$0")")"
28 # Directory containing Cumulus binaries
29 BIN_DIR="$(readlink -f "$TEST_DIR/..")"
31 # Directory where temporary files used for the tests can be stored.
32 TMP_DIR="$(readlink -f "$(mktemp -d cumulus-tests.XXXXXX)")"
34 # Command to use for running memory leak tests.
35 VALGRIND="valgrind --tool=memcheck --leak-check=full --log-file=$TMP_DIR/valgrind.log"
37 # Python interpreter to test with.
38 PYTHON="${PYTHON:-python2}"
42 echo "================================================================"
46 log_action "Starting tests: BIN_DIR=$BIN_DIR TMP_DIR=$TMP_DIR"
48 log_action "Initializing local database..."
49 LOCALDB="$TMP_DIR/database"
51 sqlite3 -init "$BIN_DIR/schema.sql" "$LOCALDB/localdb.sqlite" ".exit"
53 log_action "Creating test file system tree..."
56 cp "$BIN_DIR"/*.cc "$BIN_DIR"/*.h "$TREE"
57 cp -a "$BIN_DIR/python" "$TREE"
58 "$TEST_DIR"/digest_tree "$TREE" >"$TMP_DIR/digest.1"
60 log_action "Running initial backup..."
62 BACKUP_DIR="$TMP_DIR/backups"
64 "$BIN_DIR"/cumulus --dest="$BACKUP_DIR" --localdb="$LOCALDB" \
65 --scheme=test -v "$TREE"
67 log_action "Modifying files..."
69 cp -a "$BIN_DIR/third_party" "$TREE"
70 "$TEST_DIR"/digest_tree "$TREE" >"$TMP_DIR/digest.2"
72 log_action "Running second backup..."
74 $VALGRIND "$BIN_DIR"/cumulus --dest="$BACKUP_DIR" --localdb="$LOCALDB" \
75 --scheme=test -v "$TREE"
77 log_action "Restoring snapshots"
78 export LBS_GPG_PASSPHRASE=""
79 snapshots=$("$BIN_DIR"/cumulus-util --store="$BACKUP_DIR" list-snapshots)
80 echo "Available snapshots:" $snapshots
82 for s in $snapshots; do
84 dest="$TMP_DIR/restore-$i"
86 "$PYTHON" "$BIN_DIR"/cumulus-util --store="$BACKUP_DIR" \
87 restore-snapshot $s "$dest"