c#操作MongoDB进行数据库备份、恢复

备份(mongodump):

      命令模板:

      mongodump -h 127.0.0.1 -d test -o c:\backup\mongoDb\data\%date:~0,4%-%date:~5,2%-%date:~8,2%\%time:~0,2%-%time:~3,2%

     C#代码:

        string strCmd = string.Format(
                  @"""{0}mongodump.exe"" -h 127.0.0.1 -d {1} -o {2}%date:~0,4%-%date:~5,2%-%date:~8,2%\%time:~0,2%-%time:~3,2%",
                  SysParameter.MongoDBPath,
                  SysParameter.Database,
                  SysParameter.MongoDBBackupPath);

恢复(mongorestore):

      命令模板:

     mongorestore -h 127.0.0.1 -d test c:\backup\mongoDb\data\2012-04-03\19-48\test

     C#代码:

          string strCmd = string.Format(
                    @"""{0}mongorestore.exe"" -h 127.0.0.1 -d {1} {2}{3}",
                    SysParameter.MongoDBPath,
                    SysParameter.Database,
                    SysParameter.MongoDBBackupPath,
                    SysParameter.Database);

 

posted @ 2015-10-28 15:25  So`  阅读(766)  评论(0编辑  收藏  举报