public
Created

I needed a basic script to do basic backup of a set of databases on a mongodb on Windows.

  • Download Gist
backup_mongo.bat
Batchfile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
REM | Hobo simple backup scripts for MongoDB
REM | Hastily constructed by Adam Phillabaum <adamp@payscale.com>
REM | Starting point was here: http://stackoverflow.com/a/5497138/240539
REM |
REM | Dumps all databases from a mongo server, then copies them to a network share.
REM | It just deletes old backups without any safety checks. Not safe.
 
REM CONFIG SETTINGS
SET host=mongoserver:27017
SET mongoBin=.
SET backupsFolder=\\networkshare\mongobackup
SET tempFolder=c:\temp\mongobackup
 
REM RUN THE DUMP
if not exist %tempFolder% md %tempFolder%
%mongoBin%\mongodump.exe --host %host% --out %tempFolder%
 
REM MOVE TO CENTAL SERVER
SET datestamp=%date:~12,2%%date:~4,2%%date:~7,2%
if not exist %backupsFolder%\%datestamp% md %backupsFolder%\%datestamp%
xcopy /e %tempFolder% %backupsFolder%\%datestamp%
 
REM CLEANUP
rmdir /s /q %tempFolder%
net use p: %backupsFolder%
forfiles /p p:\ /d -45 /c "cmd /c rmdir /S /Q @path"
net use p: /delete

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.