Skip to content

Instantly share code, notes, and snippets.

@rubendob
Created February 23, 2016 08:53
Show Gist options
  • Save rubendob/15fcfd8cd0ed1c47fbfc to your computer and use it in GitHub Desktop.
Save rubendob/15fcfd8cd0ed1c47fbfc to your computer and use it in GitHub Desktop.
mongo db backup script
#!/bin/sh
# MongoDB backup script
# This script is licensed under GNU GPL version 2.0 or above
# It makes a folder under BACKUP folder and compress it into .tar.gz.file
# Using another script we will remove older backups later
# ---------------------------------------------------------------------
### System Setup ###
BACKUP=""
### Mongo Setup ###
MUSER=""
MPASS=""
MHOST="localhost"
### Binaries ###
TAR="$(which tar)"
GZIP="$(which gzip)"
MONGODUMP="$(which mongodump)"
PURGE="purgebackup.sh"
### Today + hour in 24h format ###
NOW=$(date +"%F")
FOLDER=$BACKUP/$NOW
FOLDERGZ=$BACKUP/$NOW.tar.gz
mkdir $BACKUP/$NOW
cd $BACKUP/$NOW
$MONGODUMP -u $MUSER -p $MPASS --out $FOLDER
$TAR -cvf $FOLDERGZ $FOLDER
rm -rf $BACKUP/$NOW
cd /root/scripts
./$PURGE --force --ages=1,2,3,4,5,6,7,15,30,60,90,120,365 --directory=
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment