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
: GLOBAL VARS
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%
: NETWORK MAPPING
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)
: LETS WRITE TO THE LOG
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%
: LETS GET TO WORK
net use %alias% /del
net use %alias% %networkpath% /user:%username% %pwd%
cls
echo Copyright 2009-2010. Niklas Jumlin
robocopy %source% %target% /E /XD %excludedir% /XF %excludefiles% /L /ETA /COPY:%type% /LOG+:%log%
goto finnish
:finnish
net use x: /del
exit
Is this suppose to be a bat or vbs file?
Thats a bat/cmd
These kinds of backups aren’t really a pain. A nice backup plan will go for years.
What exactly is the proper command syntax for your Batch?
Yes this is .vbs script and you can simple run interactively.