Created
September 25, 2013 08:35
-
-
Save crudh/6696735 to your computer and use it in GitHub Desktop.
Exports MongoDB to BSON, creates an archive and mails it for backup purposes. Make sure that mailx is installed and in the path.
This file contains hidden or 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/sh | |
| # CONFIGURE THIS | |
| outputBase=/Users/crudh/Code/shell-scripts/mongo-backup/test | |
| resultPrefix=system-name | |
| mailSubject="Backup - mongodb" | |
| mailBody="Backup - mongodb" | |
| mailRecipient=christian@primian.se | |
| # DO NOT CHANGE BELOW HERE-------------------------- | |
| current=`date +"%Y%m%d-%H%M"` | |
| complete=$outputBase/$resultPrefix-$current | |
| resultFile=$complete.tar.bz2 | |
| # Create the folder | |
| mkdir -p $complete | |
| # Make the backup | |
| mongodump -o $complete >/dev/null 2>&1 | |
| # Create the archive file | |
| tar -c --bzip2 -f $resultFile $complete >/dev/null 2>&1 | |
| # Remove the folder | |
| rm -rf $complete | |
| # Mail the file | |
| echo "$mailBody" | mailx -s "$mailSubject" -a "$resultFile" $mailRecipient |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment