Skip to content

Instantly share code, notes, and snippets.

@umutakturk
Created June 27, 2013 18:16
Show Gist options
  • Save umutakturk/5878916 to your computer and use it in GitHub Desktop.
Save umutakturk/5878916 to your computer and use it in GitHub Desktop.
MongoDB Backup script.
#!/bin/bash
BACKUP_DIR="$HOME/path/to/backup"
USER="db_user"
PASS="db_pass"
HOST="db_host"
PORT="db_port"
NAME="db_name"
if [ ! -d $BACKUP_DIR ];then
mkdir -p $BACKUP_DIR
fi
mongodump -h ${HOST}:${PORT} -d ${NAME} -u ${USER} -p ${PASS} -o $BACKUP_DIR
tar -C $BACKUP_DIR -jcvf ${BACKUP_DIR}/${NAME}_`date +%Y_%m_%d_%H%M%S`.tar.bz2 $NAME
rm -rf ${BACKUP_DIR}/${NAME}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment