Skip to content
Menu
Jumlins TechBlog
  • Home
  • About
Jumlins TechBlog

Simplified robocopy backup script

Posted on 2010-01-052010-03-23 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
: 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

Share on Facebook

5 thoughts on “Simplified robocopy backup script”

  1. mp says:
    2010-08-06 at 06:35

    Is this suppose to be a bat or vbs file?

  2. Wayne says:
    2010-09-08 at 20:06

    Thats a bat/cmd

  3. linux backup program says:
    2010-11-23 at 11:55

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

  4. MAGNE says:
    2012-05-15 at 10:26

    What exactly is the proper command syntax for your Batch?

  5. tushar says:
    2013-06-07 at 14:10

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

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Office 365 Groups/Teams powershell reporting script 2019-03-25
  • [Powershell Script] Convert ImmutableID 2018-09-12
  • Script to Schedule Mem and or vCPU up/downgrade 2015-05-13
  • Backing up VMs in Hyper-V 2013-01-09
  • Windows Server 2012 as a Workstation 2012-09-13

Archives

Categories

  • Exchange 2003
  • Exchange 2010
  • HTML/CSS
  • Imagick
  • JavaScript
  • Linux
  • Misc
  • Office 365 / Azure
  • PHP
  • PowerCLI
  • PowerShell
  • Projects
  • Scripts
  • Server
  • System Administration
  • VMware
  • Winbatch
  • Windows
  • Windows Server 2012

Recent Posts

  • Office 365 Groups/Teams powershell reporting script 2019-03-25
  • [Powershell Script] Convert ImmutableID 2018-09-12
  • Script to Schedule Mem and or vCPU up/downgrade 2015-05-13
  • Backing up VMs in Hyper-V 2013-01-09
  • Windows Server 2012 as a Workstation 2012-09-13
©2023 Jumlins TechBlog | Powered by WordPress & Superb Themes