Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.