Skip to content

Instantly share code, notes, and snippets.

@colinmollenhour
Created July 30, 2013 21:53
Show Gist options
  • Save colinmollenhour/6117359 to your computer and use it in GitHub Desktop.
Save colinmollenhour/6117359 to your computer and use it in GitHub Desktop.
Simple daily dump of mongo databases.
#!/bin/bash
cd /media/dumps
name=$(date +%b-%d)
year=$(date +%Y)
[ -d $year ] || mkdir $year || { echo "Could not create directory '$year'"; exit 1; }
mongodump --db t3_mage --out $name &> mongodump.log
if [ $? ]; then
tar -czf snapshots/$year/$name.tgz $name
if [ $(($(date +%d | sed 's/^0*//') % 10)) == 0 ]; then
cp snapshots/$year/$name.tgz archive/$year-$name.tgz
fi
rm -rf $name
find snapshots -mtime +60 -exec rm {} \;
find archive -mtime +365 -exec rm {} \;
else
echo "Error creating mongo dump for $year/$name"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment