MongoDB 备份脚本
这个备份脚本依赖于其它两个JS (fsync_lock.js 和 fsync_unlock.js)
#!/bin/sh MONGODB_SHELL='mongo' DUMP_UTILITY='mongodump' #SET the bd name which one you want to backup DB_NAME='' #SET server path where you want to save the file CLOUD_PATH='' #SET your user name SERVER_USER='' #SET your host name or IP of the server HOST_NAME='' date_now=`date +%Y_%m_%d_%H_%M_%S` dir_name='db_backup_'${date_now} file_name='db_backup_'${date_now}'.bz2' current_year=`date +%Y` log() { echo $1 } do_cleanup(){ rm -rf 'db_backup_'${current_year}* log 'cleaning up....' } do_backup(){ log 'snapshotting the db and creating archive' && \ ${MONGODB_SHELL} admin fsync_lock.js && \ log 'db locked and creating backup' ${DUMP_UTILITY} -d ${DB_NAME} -o ${dir_name} && tar -jcf $file_name ${dir_name} && \ ${MONGODB_SHELL} admin fsync_unlock.js && \ log 'data backd up and created snapshot' } save_in_cloud(){ log 'saving backup to another server...' scp ${file_name} ${SERVER_USER}@${HOST_NAME}:${CLOUD_PATH} log 'saved scuccessfully' } do_backup && save_in_cloud && do_cleanup来自:http://mushfiq.com/2013/08/08/mongodb-backup-script/
本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!