Robocopy as a backup solution

Since Vista’s “Backup and Restore Center” sucks and most backup solutions are bloated, I’m using the very light and built-in Window’s robocopy command to create my backups. Here’s how you can do the same:

  1. On the backup location (external hard drive), place the code below on a text file named backup-create.bat
  2. Edit all the lines that start with “call :BACKUP_DIR”. These lines define which folders will be backed up and where they will be put inside the backup folder.
  3. Double click backup-create.bat to create your first backup.
  4. When it is done executing you will have a folder with today’s date. This folder will contain all the backed up files.
  5. Double click the backup-create.bat file whenever you want to create a new backup.

Here’s the code inside backup-create.bat

echo off
set backupFolder=00-backup-in-progress
set logFile=last-execution.log

REM ---- empty out the existing log file
type NUL > %logFile%

REM ---- Copy stuff in the user folder
call :BACKUP_DIR %backupFolder%\00-mine C:\Users\pete\Documents\00-mine
call :BACKUP_DIR %backupFolder%\Desktop C:\Users\pete\Desktop
call :BACKUP_DIR %backupFolder%\FileZilla C:\Users\pete\AppData\Roaming\FileZilla

REM ---- Copy Pictures, Music, and Movies
call :BACKUP_DIR PICTURES T:\Pictures
call :BACKUP_DIR MUSIC T:\Music
call :BACKUP_DIR MOVIES T:\Movies\saved

REM ---- timestamp (datestamp) backup folder
powershell Rename-Item %backupFolder% (Get-Date -format yyyy-MM-dd)

goto :EOF [Return to OS]

REM -------------------------------------------------

:BACKUP_DIR
echo BACKING UP %2 INTO %1
robocopy %2 %1 /256 /S /NP /XA:H /R:0 /XJ /LOG+:%logFile%
goto :EOF [Return to Main]

This is a brief description of the robocopy parameters:

  • The command already ignores files that exist in the destination and look just like the source. Meaning it only copies a file it does not exist in the destination or if it different than the source.
  • /256 Turn off very long path (> 256 characters) support.
  • /S Copy sub-directories
  • /NP Don’t log progress (%)
  • /XA:H Will skip copying any hidden files. – this did not ignore hidden folders!
  • /R:0 Do not retry to copy a file if there is an error (file is in use)
  • /XJ Exclude Junctions (this includes /XJD and /XJF). Junctions are a kind of file or folder link. – I’m not sure if this was really needed.
  • /MT[:n] Do multi-threaded copies with n threads (default 8). This takes advantage of all your processor cores. This makes my two core computer run slow, so I’m not enabling it.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s