Created
October 28, 2013 04:14
-
-
Save adamb0mb/7191353 to your computer and use it in GitHub Desktop.
I needed a basic script to do basic backup of a set of databases on a mongodb on Windows.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment