gencache: Simplify gencache_stabilize
[Samba.git] / ctdb / tests / simple / 58_ctdb_restoredb.sh
blob31b81a6dcb3541912c8d258c1d0b8d6531d4fd13
1 #!/bin/bash
3 test_info()
5 cat <<EOF
6 The command 'ctdb restoredb' is used to restore a database across the
7 whole cluster.
9 Prerequisites:
11 * An active CTDB cluster with at least 2 active nodes.
13 Steps:
15 1. Verify that the status on all of the ctdb nodes is 'OK'.
16 2. Create a persistent test database
17 3. Add some records to test database
18 4. Backup database
19 5. Wipe database and verify the database is empty on all nodes
20 6. Restore database and make sure all the records are restored
21 7. Make sure no recovery has been triggered
23 Expected results:
25 * Database operations should not cause a recovery
27 EOF
30 . "${TEST_SCRIPTS_DIR}/integration.bash"
32 ctdb_test_init "$@"
34 set -e
36 cluster_is_healthy
38 try_command_on_node 0 $CTDB status
39 generation=$(echo "$out" | sed -n -e 's/^Generation:\([0-9]*\)/\1/p')
41 try_command_on_node 0 "$CTDB listnodes"
42 num_nodes=$(echo "$out" | wc -l)
44 # 2.
45 test_db="restoredb_test.tdb"
46 test_dump=$(mktemp)
47 echo $test_dump
48 echo "Create persistent test database \"$test_db\""
49 try_command_on_node 0 $CTDB attach "$test_db" persistent
50 try_command_on_node 0 $CTDB wipedb "$test_db"
52 # 3.
53 # add 10,000 records to database
54 echo "Adding 10000 records to database"
56 for i in $(seq 1 10000) ; do
57 echo "\"key$i\" \"value$i\""
58 done
59 ) | try_command_on_node -i 0 $CTDB ptrans "$test_db"
61 num_records=$(db_ctdb_cattdb_count_records 1 "$test_db")
62 if [ $num_records = "10000" ] ; then
63 echo "OK: Records added"
64 else
65 echo "BAD: We did not end up with 10000 records"
66 echo "num records = $num_records"
67 exit 1
70 ctdb_test_exit_hook_add "rm -f $test_dump"
72 # 4.
73 echo "Backup database"
74 try_command_on_node 0 $CTDB backupdb "$test_db" "$test_dump"
76 # 5.
77 echo "Wipe database"
78 try_command_on_node 0 $CTDB wipedb "$test_db"
80 # check that the database is restored
81 num_records=$(db_ctdb_cattdb_count_records 1 "$test_db")
82 if [ $num_records = "0" ] ; then
83 echo "OK: Database was wiped"
84 else
85 echo "BAD: We did not end up with an empty database"
86 echo "num records = $num_records"
87 exit 1
90 # 6.
91 echo "Restore database"
92 try_command_on_node 0 $CTDB restoredb "$test_dump" "$test_db"
94 # check that the database is restored
95 num_records=$(db_ctdb_cattdb_count_records 1 "$test_db")
96 if [ $num_records = "10000" ] ; then
97 echo "OK: Database was restored"
98 else
99 echo "BAD: We did not end up with 10000 records"
100 echo "num records = $num_records"
101 exit 1
104 # 7.
105 wait_until_ready
107 try_command_on_node 0 $CTDB status
108 new_generation=$(echo "$out" | sed -n -e 's/^Generation:\([0-9]*\)/\1/p')
110 echo "Old generation = $generation"
111 echo "New generation = $new_generation"
113 if [ "$generation" = "$new_generation" ]; then
114 echo "OK: Database recovery not triggered."
115 else
116 echo "BAD: Database recovery triggered."
117 exit 1