Skip to content

Instantly share code, notes, and snippets.

@adamb0mb
Created October 28, 2013 04:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamb0mb/7191353 to your computer and use it in GitHub Desktop.
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.
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