Skip to content

@adamb0mb /backup_mongo.bat
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.