Create Batch File For Dump From MongoDB And Set Scheduler

--

1: name:: batch_for_dump.bat

2:

@ECHO OFF
for /f “skip=1” %%i in (‘wmic os get localdatetime’) do if not defined fulldate set fulldate=%%i
set year=%fulldate:~0,4%
set month=%fulldate:~4,2%
set day=%fulldate:~6,2%
set foldername=%year%_%month%_%day%
md C:\data\db\%foldername%
mongodump — host=*.*.*.* — port=*** — username root — password ****— db mom_*** — authenticationDatabase admin -o C:\data\db\%foldername%
PAUSE

3:

Result:

Specific collection

@ECHO OFF
for /f “skip=1” %%i in (‘wmic os get localdatetime’) do if not defined fulldate set fulldate=%%i
set year=%fulldate:~0,4%
set month=%fulldate:~4,2%
set day=%fulldate:~6,2%
set foldername=%year%_%month%_%day%_minimal
md C:\data\db\%foldername%

set collections=a1 a2 a3
(for %%c in (%collections%) do (
mongodump — host=*** — port=*** — username root — password *** — db db_name — collection %%c — authenticationDatabase admin -o C:\data\db\%foldername%
))

PAUSE

--

--