Skip to content

Instantly share code, notes, and snippets.

@ls0f
Last active November 5, 2015 02:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ls0f/c8e3d5b0fe4cc624d1d7 to your computer and use it in GitHub Desktop.
Save ls0f/c8e3d5b0fe4cc624d1d7 to your computer and use it in GitHub Desktop.
mongodb backup
#!/bin/bash
BACKUP_DB="xx"
DUMP_CMD="/usr/bin/mongodump"
HOST="127.0.0.1"
PORT="27017"
TIMESTAMP=`date +%F-%H%M`
BACKUP_DIR="/opt/data/backup"
cd $BACKUP_DIR
BACKUP_NAME_PREFIX="app-db"
BACKUP_NAME="$BACKUP_NAME_PREFIX-$TIMESTAMP"
#mongo admin --eval "printjson(db.fsyncLock())"
$DUMP_CMD -h $HOST:$PORT -d $BACKUP_DB
#mongo admin --eval "printjson(db.fsyncUnlock())"
tar -zcvf $BACKUP_DIR/$BACKUP_NAME.tgz dump
rm -rf dump
#find $BACKUP_DIR -mtime 7 -type f | xargs -r rm -r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment