MongoDB 备份脚本

jopen 7年前

这个备份脚本依赖于其它两个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/