1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00
samba-mirror/ctdb/tests/INTEGRATION/database/basics.010.backup_restore.sh
Martin Schwenke 8b24cae630 ctdb-tests: Update preamble for INTEGRATION tests
* Use "#!/usr/bin/env bash" for improved portability

* Drop test_info() definition and replace it with a comment

  The use of test_info() is pointless.

* Drop call to cluster_is_healthy()

  This is a holdover from when the previous test would restart daemons
  to get things ready for a test.  There was also a bug where going
  into recovery during the restart would sometimes cause the cluster
  to become unhealthy.  If we really need something like this then we
  can add it to ctdb_test_init().

* Make order of preamble consistent

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
2020-07-22 07:53:35 +00:00

98 lines
2.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Confirm that 'ctdb restoredb' works correctly:
# 1. Create a persistent test database
# 2. Add some records to test database
# 3. Backup database
# 4. Wipe database and verify the database is empty on all nodes
# 5. Restore database and make sure all the records are restored
# 6. Make sure no recovery has been triggered
. "${TEST_SCRIPTS_DIR}/integration.bash"
set -e
ctdb_test_init
try_command_on_node 0 $CTDB status
generation=$(sed -n -e 's/^Generation:\([0-9]*\)/\1/p' "$outfile")
try_command_on_node 0 "$CTDB listnodes | wc -l"
num_nodes="$out"
# 2.
test_db="restoredb_test.tdb"
test_dump=$(mktemp)
echo $test_dump
echo "Create persistent test database \"$test_db\""
try_command_on_node 0 $CTDB attach "$test_db" persistent
try_command_on_node 0 $CTDB wipedb "$test_db"
# 3.
# add 10,000 records to database
echo "Adding 10000 records to database"
(
for i in $(seq 1 10000) ; do
echo "\"key$i\" \"value$i\""
done
) | try_command_on_node -i 0 $CTDB ptrans "$test_db"
num_records=$(db_ctdb_cattdb_count_records 1 "$test_db")
if [ $num_records = "10000" ] ; then
echo "OK: Records added"
else
echo "BAD: We did not end up with 10000 records"
echo "num records = $num_records"
exit 1
fi
ctdb_test_exit_hook_add "rm -f $test_dump"
# 4.
echo "Backup database"
try_command_on_node 0 $CTDB backupdb "$test_db" "$test_dump"
# 5.
echo "Wipe database"
try_command_on_node 0 $CTDB wipedb "$test_db"
# check that the database is restored
num_records=$(db_ctdb_cattdb_count_records 1 "$test_db")
if [ $num_records = "0" ] ; then
echo "OK: Database was wiped"
else
echo "BAD: We did not end up with an empty database"
echo "num records = $num_records"
exit 1
fi
# 6.
echo "Restore database"
try_command_on_node 0 $CTDB restoredb "$test_dump" "$test_db"
# check that the database is restored
num_records=$(db_ctdb_cattdb_count_records 1 "$test_db")
if [ $num_records = "10000" ] ; then
echo "OK: Database was restored"
else
echo "BAD: We did not end up with 10000 records"
echo "num records = $num_records"
exit 1
fi
# 7.
wait_until_ready
try_command_on_node 0 $CTDB status
new_generation=$(sed -n -e 's/^Generation:\([0-9]*\)/\1/p' "$outfile")
echo "Old generation = $generation"
echo "New generation = $new_generation"
if [ "$generation" = "$new_generation" ]; then
echo "OK: Database recovery not triggered."
else
echo "BAD: Database recovery triggered."
exit 1
fi