Created
February 2, 2011 14:34
-
-
Save anonymous/807757 to your computer and use it in GitHub Desktop.
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 | |
| #################################### | |
| # | |
| # Backup MongoDB to S3 | |
| # | |
| #################################### | |
| #PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin | |
| MONGODB_SHELL='/usr/bin/mongo' | |
| DUMP_UTILITY='/usr/bin/mongodump' | |
| DB_NAME='prolinkd' | |
| echo '########################################################################' | |
| echo "###### backing up DB $DB_NAME" | |
| echo '########################################################################' | |
| date_now=`date +%Y_%m_%d_%H_%M` | |
| #date_now=`date +%Y-%b-%d_%T` | |
| dir_name="/root/BU/db_backup" | |
| tar_name="db_backup_${date_now}.tar.gz" | |
| file_name="${dir_name}/${tar_name}" | |
| if [ -z "$dir_name" ]; then | |
| mkdir $dir_name | |
| fi | |
| log() { | |
| echo $1 >> /tmp/mybackup.log | |
| } | |
| do_cleanup(){ | |
| # rm -rf db_backup* | |
| log 'cleaning up....' | |
| } | |
| do_backup(){ | |
| log 'snapshotting the db and creating archive' && \ | |
| echo "tar -jcf ${tar_name} dump" >> /tmp/mybackup.log && \ | |
| /usr/bin/mongodump -o ${dir_name} && /bin/tar -jcf ${tar_name} ${dir_name} && \ | |
| log 'data backd up and created snapshot' | |
| } | |
| save_in_s3(){ | |
| log 'saving the backup archive in amazon S3' && \ | |
| /usr/bin/s3cmd put --acl-private ${file_name} s3://prolinkd/db-backups/${tar_name} | |
| log 'data backup saved in amazon s3' | |
| } | |
| do_backup && save_in_s3 && do_cleanup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment