-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathverify-backups.bash
executable file
·126 lines (102 loc) · 4.83 KB
/
verify-backups.bash
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
#!/bin/bash
if [ -z "$MONGO_DIR" ]; then
echo "Need to set MONGO_DIR"
exit 1
fi
if [ -z "$MONGO_TYPE" ]; then
echo "Need to set MONGO_TYPE"
exit 1
fi
if [ -z "$HOT_BACKUP_DIR" ]; then
echo "Need to set HOT_BACKUP_DIR"
exit 1
fi
if [ -z "$VERIFY_LOG_NAME" ]; then
echo "Need to set VERIFY_LOG_NAME"
exit 1
fi
if [ -z "$NUM_COLLECTIONS" ]; then
echo "Need to set NUM_COLLECTIONS"
exit 1
fi
# start using the given data directory
export MONGO_LOG=${MACHINE_NAME}-validation.mongolog
# verify that the source database is solid
echo "" | tee -a ${VERIFY_LOG_NAME}
echo "" | tee -a ${VERIFY_LOG_NAME}
echo "--------------------------------------------------------------------------------------" | tee -a ${VERIFY_LOG_NAME}
echo "--------------------------------------------------------------------------------------" | tee -a ${VERIFY_LOG_NAME}
echo "--------------------------------------------------------------------------------------" | tee -a ${VERIFY_LOG_NAME}
echo "checking SOURCE directory" | tee -a ${VERIFY_LOG_NAME}
# stop mongod if it is currently running
mongo-stop
echo "`date` | starting the ${MONGO_TYPE} server at ${MONGO_DIR}" | tee -a ${VERIFY_LOG_NAME}
if [ ${MONGO_TYPE} == "tokumx" ]; then
mongo-start-tokumx-fork
else
mongo-start-pure-numa-fork
fi
mongo-is-up 30
echo "`date` | server is available (or not)" | tee -a ${VERIFY_LOG_NAME}
echo "`date` | checking admin database" | tee -a ${VERIFY_LOG_NAME}
echo "**************************************************************************************************" | tee -a ${VERIFY_LOG_NAME}
$MONGO_DIR/bin/mongo admin --eval "printjson(db.runCommand('dbhash').md5)" | tee -a ${VERIFY_LOG_NAME}
echo "`date` | checking ${DB_NAME} database" | tee -a ${VERIFY_LOG_NAME}
echo "**************************************************************************************************" | tee -a ${VERIFY_LOG_NAME}
$MONGO_DIR/bin/mongo ${DB_NAME} --eval "printjson(db.runCommand('dbhash').md5)" | tee -a ${VERIFY_LOG_NAME}
echo "**************************************************************************************************" | tee -a ${VERIFY_LOG_NAME}
./verify.bash
# END - verify that the source database is solid
deleteFinalBackup=Y
# remove the last backup since it might not finish before the database is shutdown
if [ ${deleteFinalBackup} == "Y" ] ; then
numBackupDirs=0
deleteBackupDir=""
for backupDir in ${HOT_BACKUP_DIR}/* ; do
let numBackupDirs=numBackupDirs+1
deleteBackupDir=${backupDir}
done
if ! [ ${numBackupDirs} == 0 ] ; then
# we have a backup directory to kill
echo "deleteting backup directory ${deleteBackupDir}" | tee -a ${VERIFY_LOG_NAME}
rm -rf ${deleteBackupDir}
fi
fi
for backupDir in ${HOT_BACKUP_DIR}/* ; do
if [ -d "${backupDir}" ]; then
echo "" | tee -a ${VERIFY_LOG_NAME}
echo "" | tee -a ${VERIFY_LOG_NAME}
echo "--------------------------------------------------------------------------------------" | tee -a ${VERIFY_LOG_NAME}
echo "--------------------------------------------------------------------------------------" | tee -a ${VERIFY_LOG_NAME}
echo "--------------------------------------------------------------------------------------" | tee -a ${VERIFY_LOG_NAME}
echo "checking backup directory : ${backupDir}" | tee -a ${VERIFY_LOG_NAME}
fi
# startup backup database
if [ ${MULTI_DIR} == "N" ]; then
export MONGO_DATA_DIR=${backupDir}
else
export MONGO_LOG_DIR=${backupDir}/log
export MONGO_DATA_DIR=${backupDir}/data
fi
# stop mongod if it is currently running
mongo-stop
echo "`date` | starting the ${MONGO_TYPE} server at ${MONGO_DIR}" | tee -a ${VERIFY_LOG_NAME}
if [ ${MONGO_TYPE} == "tokumx" ]; then
mongo-start-tokumx-fork
else
mongo-start-pure-numa-fork
fi
mongo-is-up 30
echo "`date` | server is available (or not)" | tee -a ${VERIFY_LOG_NAME}
echo "`date` | checking admin database" | tee -a ${VERIFY_LOG_NAME}
echo "**************************************************************************************************" | tee -a ${VERIFY_LOG_NAME}
$MONGO_DIR/bin/mongo admin --eval "printjson(db.runCommand('dbhash').md5)" | tee -a ${VERIFY_LOG_NAME}
echo "`date` | checking ${DB_NAME} database" | tee -a ${VERIFY_LOG_NAME}
echo "**************************************************************************************************" | tee -a ${VERIFY_LOG_NAME}
$MONGO_DIR/bin/mongo ${DB_NAME} --eval "printjson(db.runCommand('dbhash').md5)" | tee -a ${VERIFY_LOG_NAME}
echo "**************************************************************************************************" | tee -a ${VERIFY_LOG_NAME}
./verify.bash
done
echo "`date` | shutting down the server" | tee -a ${VERIFY_LOG_NAME}
mongo-stop
mongo-is-down