mongodb 备份与还原
#!/bin/bash # mongodb 数据备份与还原 # by zjs # date 2016-12-13 21:43 # 恢复命令 mongorestore -h 127.0.0.1 --port 27017 -d dbname --directoryperdb ${path} #备份目录 backup_path='/data/Backup/mongodb/' #备份子目录名 today_dir=`date -d yesterday +%Y%m%d` #备份天数 backup_day=7 #备份库名 dbname='yhtb' path=${backup_path}${today_dir} mkdir -p ${path} mongodump -h 127.0.0.1 --port 27017 -d ${dbname} -o ${path} #删除超过备份天数的目录 delete_file=${backup_path}`date +%Y%m%d --date="-${backup_day} day"` if [ -d ${delete_file} ];then rm -rf ${delete_file} fi
Leave a Comment