Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Mongodump Shell Script for Cronjob
#!/bin/bash
MONGO_DATABASE="annotation"
MONGO_HOST="127.0.0.1"
MONGO_PORT="27017"
TIMESTAMP=`date +%Y-%m-%d-%H-%M-%S`
MONGODUMP_PATH=/usr/bin/mongodump
BACKUPS_DIR=~/sjyan/data/mongodb-backup/
BACKUP_NAME=$TIMESTAMP
SCRIPT_DIR=~/sjyan/scripts/
cd
# mongo admin --eval "printjson(db.fsyncLock())"
$MONGODUMP_PATH -h $MONGO_HOST:$MONGO_PORT -d $MONGO_DATABASE
# mongo admin --eval "printjson(db.fsyncUnlock())"
# mkdir -p $BACKUPS_DIR
mv dump $BACKUP_NAME
# rm -rf $BACKUPS_DIR/*
mv $BACKUP_NAME $BACKUPS_DIR
# tar -zcvf $BACKUPS_DIR/$BACKUP_NAME.tgz $BACKUP_NAME
# rm -rf $BACKUP_NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.