Jumlins TechBlog

The coding hell and the daily IT of Niklas Jumlin

January 5th, 2010 by Niklas Jumlin

So I work with many servers and many customers. Usually I had to write a new backup script for every new customer and server. Therefore I figured I might as well just write a template that I can copy/paste everytime I have to implement a robocopy backup script. So here goes.

@echo off
title Copyright 2009-2010. Niklas Jumlin
echo Copyright 2009-2010. Niklas Jumlin
for /f "Tokens=1" %%i in ('time /t') do @set tm=%%i
for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do  @set dt=%%i%%j%%k%%l
set tm=%tm::=.%
set dtt=%dt%_%tm%
set networkpath=\\lacie2\backup
set username=<backup_user>
set pwd=<password for backup_user>
set alias=X:
: ROBOCOPY SPECIFIC. What source to backup from.
set source=E:\
: To exclude another dir, simply enter it with a space seperator. i.e C:\folder1 C:\folder2
: If you use brackets, you must enter the second excluded dir within the same brackets as the first excluded dir.
set excludedir="E:\System Volume Information"
set excludefiles="%source%robocopy_%dtt%.txt"
: Types: D=Data, A=Attributes, T=Timestamps, S=Security=NTFS ACLs, O=Owner info, U=aUditing info
set type=DAT
set target=%alias%\
: Define Logfile
set log=%source%\robocopy_%dtt%.txt
set showpassword=y
if %showpassword%==y set password=%pwd%
if %showpassword%==n set password=(not shown)
echo Copyright 2009-2010. Niklas Jumlin >> %log%
echo Backup Script Started: %dt% %tm% >> %log%
echo. >> %log%
echo Source: %source% >> %log%
echo Target: %networkpath% (%alias%\) >> %log%
echo Credentials: %username%/%password% >> %log%
echo. >> %log%
echo Excluded dirs/files: >> %log%
echo %excludedir% # %excludefiles% >> %log%
echo. >> %log%
echo Below is Robocopys log: >> %log%
net use %alias% /del
net use %alias% %networkpath% /user:%username% %pwd%
echo Copyright 2009-2010. Niklas Jumlin
robocopy %source% %target% /E /XD %excludedir% /XF %excludefiles% /L /ETA /COPY:%type% /LOG+:%log%
goto finnish
net use x: /del

5 Responses to “ Simplified robocopy backup script ”

  1. mp says:

    Is this suppose to be a bat or vbs file?

  2. Wayne says:

    Thats a bat/cmd

  3. These kinds of backups aren’t really a pain. A nice backup plan will go for years.

  4. MAGNE says:

    What exactly is the proper command syntax for your Batch?

  5. tushar says:

    Yes this is .vbs script and you can simple run interactively.

Leave a Reply