Last active
August 29, 2015 14:27
-
-
Save jahil/96cf17d252b1947502ba to your computer and use it in GitHub Desktop.
Simple MongoDB Backup Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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