Skip to content

Instantly share code, notes, and snippets.

@jahil
Last active August 29, 2015 14:27
Show Gist options
  • Save jahil/96cf17d252b1947502ba to your computer and use it in GitHub Desktop.
Save jahil/96cf17d252b1947502ba to your computer and use it in GitHub Desktop.
Simple MongoDB Backup Script
#!/bin/bash
HOST=localhost
BASE_BAK_FLDR=/backup/mongodb
RM_FLDR_DAYS="+7"
DB_BKP_FLDR=$BASE_BAK_FLDR/$(date +%d-%m-%Y)
[ ! -d $DB_BKP_FLDR ] && mkdir -p $DB_BKP_FLDR
mongodump --host $HOST --out $DB_BKP_FLDR
echo "cleaning up"
cd $DB_BKP_FLDR && 7zr a dump.7z * > /dev/null && find -maxdepth 1 -type d -exec rm -rf {} \;
if [ ! -z "$RM_FLDR_DAYS" ]; then
echo -en "$(date) : removing folder : "
find $BASE_BAK_FLDR/ -maxdepth 1 -mtime $RM_FLDR_DAYS -type d -exec rm -rf {} \;
echo
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment