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

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store