Skip to content

Instantly share code, notes, and snippets.

@droot
Created May 2, 2010 16:03
Show Gist options
  • Save droot/387237 to your computer and use it in GitHub Desktop.
Save droot/387237 to your computer and use it in GitHub Desktop.
#!/bin/sh
MONGODB_SHELL='/opt/mongodb/bin/mongo'
DUMP_UTILITY='/opt/mongodb/bin/mongodump'
DB_NAME='my_db'
date_now=`date +%Y_%m_%d_%H_%M_%S`
dir_name='db_backup_'${date_now}
file_name='db_backup_'${date_now}'.bz2'
log() {
echo $1
}
do_cleanup(){
rm -rf db_backup_2010*
log 'cleaning up....'
}
do_backup(){
log 'snapshotting the db and creating archive' && \
${MONGODB_SHELL} admin fsync_lock.js && \
${DUMP_UTILITY} -d ${DB_NAME} -o ${dir_name} && tar -jcf $file_name ${dir_name}
${MONGODB_SHELL} admin unlock.js && \
log 'data backd up and created snapshot'
}
save_in_s3(){
log 'saving the backup archive in amazon S3' && \
python aws_s3.py set ${file_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