mongo相关
1、启动mongo服务:mongod --port 8051 --dbpath E:\GameDB\DB --wiredTigerCacheSizeGB 5(端口,数据路径、内存上限控制,单位为G)
2、简单的mongo定时完全备份批处理
1 @rem 备份mongo数据库批处理 2 @ECHO OFF 3 title backUpDatabase 4 5 setlocal EnableDelayedExpansion 6 7 rem 服务器索引 8 set serverStartIndex=10 9 set serverEndInfex=10 10 11 rem 设置数据库地址 12 set dbPath="127.0.0.1:27017" 13 14 rem 设置要备份的数据集 15 set backupCollections=Collection1 Collection2 Collection3 16 17 :begin 18 ECHO BackupDatabase... 19 20 set strDate=%date:~0,10% 21 set strDate=%strDate:/=_% 22 set strDate=%strDate: =0% 23 set strTime=%time:~0,5% 24 set strTime=%strTime::=-% 25 set strTime=%strTime: =0% 26 27 rem 遍历备份所有数据库 28 for /L %%i in (%serverStartIndex%,1,%serverEndInfex%) do ( 29 rem 声明数据库名 30 set dbName="GameDB0%%i" 31 if %%i gtr 9 set dbName="GameDB%%i" 32 33 ECHO 即将备份数据库!dbName!... 34 35 rem 创建备份文件夹,格式:日期/时-分 36 set strPath="E:\MongoBackup\GameServer\Server0%%i\%strDate%\%strTime%" 37 if %%i gtr 9 set strPath="E:\MongoBackup\GameServer\Server%%i\%strDate%\%strTime%" 38 md !strPath! 39 40 c: 41 cd C:\Program Files\MongoDB\Server\3.2\bin 42 for %%k in (%backupCollections%) do ( 43 rem 开始备份:mongodump -h 127.0.0.1:27017 -d 数据库名 -c 要备份的数据集 -o 备份目标路径 44 rem 如果备份整个数据库则 -d和-c可以去掉 45 mongodump -h !dbPath! -d "!dbName!" -c %%k -o !strPath! 46 ) 47 48 rem 压缩备份文件夹 49 cd C:\Program Files\WinRAR 50 set zipPath=!strPath!.rar 51 winrar a -ep1 -o+ -inul -r -iback !zipPath! !strPath! 52 53 rem 删除备份文件夹 54 e: 55 rd /s /q !strPath! 56 ) 57 58 rem 定时备份操作 59 rem ping 127.1 -n 3600 >nul 60 timeout /t 3600 /nobreak 61 goto begin 62 63 rem 还原数据库操作 64 rem mongorestore -h 127.0.0.1:27017 --drop --dir D:\MongoBackup\2017_07_07\02-10