Skip to content

Instantly share code, notes, and snippets.

@elfeffe
Forked from colinmollenhour/mongobackup.sh
Created October 18, 2016 09:13
Show Gist options
  • Save elfeffe/2a87bbc2f5f5fecb7302d623b423176e to your computer and use it in GitHub Desktop.
Save elfeffe/2a87bbc2f5f5fecb7302d623b423176e 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