Skip to content

Commit 81e1c13

Browse files
authored
Moving fsyncUnlock right after dump is ready
Following @iokobi suggestion: #1
1 parent 0517bf0 commit 81e1c13

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

MongoBackup.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
#
33
# MongoDB Backup Tool
4-
# Copyright (c) 2017 Alexey Baikov <sysboss[@]mail.ru>
4+
# Copyright (c) 2018 Alexey Baikov <sysboss[@]mail.ru>
55
#
66
# Description: Backing up MongoDB to S3 Bucket
77
# GitHub: https://github.com/sysboss/mongodb_backup
@@ -38,7 +38,7 @@
3838
function usage {
3939
cat << EOF
4040
MongoDB Backup Tool
41-
Copyright (c) 2017 Alexey Baikov <sysboss[@]mail.ru>
41+
Copyright (c) 2018 Alexey Baikov <sysboss[@]mail.ru>
4242
4343
usage: $0 options
4444
@@ -132,7 +132,7 @@ function log {
132132
local lvl=${2:-"INFO"}
133133

134134
if ! which printf > /dev/null; then
135-
echo "$(getDateTime) $lvl $msg" #| tee -a ${LOGFILE}
135+
echo "$(getDateTime) $lvl $msg" #| tee -a ${LOGFILE}
136136
else
137137
printf "%15s %5s %s\n" "$(getDateTime)" "$lvl" "$msg"
138138
fi
@@ -141,10 +141,6 @@ function log {
141141
function cleanup {
142142
local lvl=$1
143143

144-
# unlock database writes
145-
runCommand mongo admin --eval "printjson(db.fsyncUnlock())"
146-
log "Database is unlocked"
147-
148144
# release lock
149145
unlock
150146

@@ -166,6 +162,9 @@ function cleanup {
166162

167163
# report, on error/abortion
168164
if [ "$lvl" != "" ]; then
165+
# unlock database writes
166+
runCommand mongo admin --eval "printjson(db.fsyncUnlock())"
167+
log "Database is unlocked"
169168
log "Aborting backup" "$lvl"
170169
exit 2
171170
fi
@@ -228,6 +227,10 @@ else
228227
mongodump -h $MONGO_HOST:$MONGO_PORT -o ${DUMPFILE}
229228
fi
230229

230+
# unlock database writes
231+
runCommand mongo admin --eval "printjson(db.fsyncUnlock())"
232+
log "Database is unlocked"
233+
231234
log "Creating compressed archive of backup directory"
232235
tar -zcf "${DUMPFILE}.tar.gz" -C "${BACKUP_DIR}/" .
233236

0 commit comments

Comments
 (0)