用于将复制集备份到Windows Server本地的MongoDB脚本 [英] MongoDB script to backup replication set locally to a Windows Server

查看:60
本文介绍了用于将复制集备份到Windows Server本地的MongoDB脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Windows 2012服务器上运行的复制集中对MongoDB进行每日备份.

I would like to make a Daily Backup of my MongoDB from a replication set running from Windows 2012 servers.

最终目标是获取每日备份并将备份写入Windows的远程或本地共享.

End goal would be to get a daily backup and write the backup to a remote or local share - Windows.

我可以批处理mongodump命令吗?

Can I batch the mongodump command?

任何帮助将不胜感激!

推荐答案

对不起,已经有点晚了,但是以下内容对我来说似乎还行.该脚本转储数据库并使用7-Zip压缩输出.

Sorry, it's a bit late but the following seems to work OK for me. The script dumps the database and compresses the output using 7-Zip.

1)创建备份脚本(backup.bat)

@echo off

REM move into the backups directory
CD C:\database_backups


REM Create a file name for the database output which contains the date and time. Replace any characters which might cause an issue.
set filename=database %date% %time%
set filename=%filename:/=-%
set filename=%filename: =__%
set filename=%filename:.=_%
set filename=%filename::=-%

REM Export the database
echo Running backup "%filename%"
C:\mongodb\mongodump --out %filename%


REM ZIP the backup directory
echo Running backup "%filename%"
"c:\Program Files\7-Zip\7z.exe" a -tzip "%filename%.zip" "%filename%"


REM Delete the backup directory (leave the ZIP file). The /q tag makes sure we don't get prompted for questions 
echo Deleting original backup directory "%filename%"
rmdir "%filename%" /s /q

echo BACKUP COMPLETE

2)安排备份

  1. 打开计算机管理
  2. 转到任务计划程序,然后选择创建任务.
  3. 常规选项卡上,输入说明,然后选择运行是否登录用户,以使任务在夜间运行.
  4. 触发器标签上,选择您希望任务运行的时间.
  5. 操作标签上,创建一个指向您的批处理脚本的新操作.
  1. Open Computer Management
  2. Go to Task Scheduler and select Create Task.
  3. On the General tab, enter a description and select Run whether user is logged on or not if you want the task to run at night.
  4. On the Triggers tab, select when you would like the task to run.
  5. On the Actions tab, create a new action which points at your batch script.

这篇关于用于将复制集备份到Windows Server本地的MongoDB脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆