-
-
Save elfeffe/2a87bbc2f5f5fecb7302d623b423176e to your computer and use it in GitHub Desktop.
Simple daily dump of mongo databases.
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 | |
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