Broken Remote

November 3, 2008

Backing up your data using Robocopy: Redux

Filed under: software, windows — Tags: , — Broken Remote @ 2:12 pm

Some time ago, I wrote a post on how to back up your data using an effective batch script that utilizes a file copy utility called Robocopy. Turns out that’s a very popular post, so I want to offer a less hassled method of doing this for the less technically adept.

So a quick recap on Robocopy: It’s a command line utility that allows you to easily copy files from one place to another. Why is this better than just using the windows right click > copy menu to move your files? There are lots of reasons:

  • You can keep logs of what you’ve backed up
  • You can restart in the middle of a failed data copy
  • It’s most likely a lot faster
  • If one file has an error, the entire copy does not fail
  • You can do incremental backups. If you have a lot of data this means that it’s not going to re-copy your entire MP3 collection if you do the same backup twice in a row. This saves a lot of time

In short, it beats a basic copy all around. The primary problem is Robocopy isn’t a simple program that you can just download and easily use. You have to use a command line interface. But no worries, I’ve written one for you!

Before I list the script, there are some important things to know:

  1. WIndows Vista users, you will use a special version of the script that excludes junction points. Vista has some strange folder virtualization that makes it compatible with old Windows XP user profile paths. If you don’t use the correct script, it will get stuck in an infinite loop on certain folders, notably “Documents and Settings/username”.
  2. Windows XP users, you cannot use the exclude junction point version as Robocopy probably won’t recognize that command. I’ve posted both versions below
  3. Windows XP users, you have to install the Windows 2003 Server Resource Kit in order to use Robocopy. Vista users, it’s already installed on your operating system.

So without further ado, here are two backup scripts.

Instructions:

Copy and paste the entire text of the correct version of the script below into notepad (Start > Programs > Accessories > Notepad).

Save that file as “backup.bat”, including the quotes, to somewhere you will remember, like your Windows desktop.

Go to that location and make sure you see a file named “backup.bat”, this time without the quotes. It should have a weird icon with a gear on it or just a plain white window.

Double click on the file to run it. A black window should pop up. Just follow the on screen instructions.

Important note: You must create the backup directory before you run the backup. For example, if you wanted to backup C:/Users/smith to D:/myProfileBackup, you should go to My Computer > D:/ and create a new folder called myProfileBackup before you run the script or you will get an error.

Leave me a comment if you have any questions!

Windows Vista Users:

@ECHO off

ECHO.
ECHO    * – - – - – - – - – - – - – - – - – - – - – - *
ECHO    *                                             *
ECHO    *     Robocopy Backup Utility for Windows     *
ECHO    *     by Broken Remote via                    *
ECHO    *     brokenremote.wordpress.com              *
ECHO    *     Free for any use and modification       *
ECHO    *                                             *
ECHO    * – - – - – - – - – - – - – - – - – - – - – - *
ECHO.

ECHO    Instructions:
ECHO.
ECHO      1. Enter the drive letter of the drive with the data to backup (ie: “C”)
ECHO      2. Enter the path to the folder you wish to backup (ie: “Documents and Settings/Smith”)
ECHO      3. Enter the drive letter of your backup drive (ie: “E”)
ECHO      4. Enter the path to the specific backup location (ie: “backups/novemberBackup”)
ECHO      5. Verify your options and press “Y” to proceed or “N” to exit
ECHO.
ECHO  ____________________________________________________
ECHO.

:: Prompt for inputs
SET /P sourceLetter=1. Source drive letter:
SET /P sourcePath=2. Path to data you wish to backup:
SET /P destinationLetter=3. Destination drive letter:
SET /P destinationPath=4. Path to backup folder:

:: Set full source and destination
SET source=%sourceLetter%:/%sourcePath%
SET destination=%destinationLetter%:/%destinationPath%

ECHO.
ECHO  ____________________________________________________
ECHO.

:: Verify source and destination
ECHO      You are copying data from
ECHO.
ECHO      %source%
ECHO.
ECHO      to
ECHO.
ECHO      %destination%

ECHO.
ECHO  ____________________________________________________
ECHO.

SET /P continue= Proceed? (Y/N):
IF /I %continue%==N GOTO END

:: Set the logfile
SET logfile=%destination%/backup.log

:: Set the options. Note to remove the /XJD option on Windows XP
SET options=/MIR /XJD /LOG:%logfile% /R:0 /W:0 /TEE

:: Start the copy
ROBOCOPY %source% %destination% %options%

:END
ECHO.

pause

:: ROBOCOPY COMMAND OPTIONS

:: Do ROBOCOPY /? in a command prompt for details on other flags
:: /MIR = delete files from destination that have been deleted on source
:: /LOG = create a log file
:: /R:0 = don’t retry a file if it fails. Change number as you wish
:: /W:0 = don’t wait to retry a file if it fails. Change number as you wish
:: /TEE = output progress to console window. Turn this on if you want to see the file copy report at the end of your copy and progress during
:: /XJD = Windows Vista has some weird folder virtualization to prevent programs from accessing folders directly. Exclude Junction points to fix this.

Windows XP Users:

@ECHO off

ECHO.
ECHO    * – - – - – - – - – - – - – - – - – - – - – - *
ECHO    *                                             *
ECHO    *     Robocopy Backup Utility for Windows     *
ECHO    *     by Broken Remote via                    *
ECHO    *     brokenremote.wordpress.com              *
ECHO    *     Free for any use and modification       *
ECHO    *                                             *
ECHO    * – - – - – - – - – - – - – - – - – - – - – - *
ECHO.

ECHO    Instructions:
ECHO.
ECHO      1. Enter the drive letter of the drive with the data to backup (ie: “C”)
ECHO      2. Enter the path to the folder you wish to backup (ie: “Documents and Settings/Smith”)
ECHO      3. Enter the drive letter of your backup drive (ie: “E”)
ECHO      4. Enter the path to the specific backup location (ie: “backups/novemberBackup”)
ECHO      5. Verify your options and press “Y” to proceed or “N” to exit
ECHO.
ECHO  ____________________________________________________
ECHO.

:: Prompt for inputs
SET /P sourceLetter=1. Source drive letter:
SET /P sourcePath=2. Path to data you wish to backup:
SET /P destinationLetter=3. Destination drive letter:
SET /P destinationPath=4. Path to backup folder:

:: Set full source and destination
SET source=%sourceLetter%:/%sourcePath%
SET destination=%destinationLetter%:/%destinationPath%

ECHO.
ECHO  ____________________________________________________
ECHO.

:: Verify source and destination
ECHO      You are copying data from
ECHO.
ECHO      %source%
ECHO.
ECHO      to
ECHO.
ECHO      %destination%

ECHO.
ECHO  ____________________________________________________
ECHO.

SET /P continue= Proceed? (Y/N):
IF /I %continue%==N GOTO END

:: Set the logfile
SET logfile=%destination%/backup.log

:: Set the options. Note to remove the /XJD option on Windows XP
SET options=/MIR /LOG:%logfile% /R:0 /W:0 /TEE

:: Start the copy
ROBOCOPY %source% %destination% %options%

:END
ECHO.

pause

:: ROBOCOPY COMMAND OPTIONS

:: Do ROBOCOPY /? in a command prompt for details on other flags
:: /MIR = delete files from destination that have been deleted on source
:: /LOG = create a log file
:: /R:0 = don’t retry a file if it fails. Change number as you wish
:: /W:0 = don’t wait to retry a file if it fails. Change number as you wish
:: /TEE = output progress to console window. Turn this on if you want to see the file copy report at the end of your copy and progress during
:: /XJD = Windows Vista has some weird folder virtualization to prevent programs from accessing folders directly. Exclude Junction points to fix this.

3 Comments »

  1. [...] Backing Up Your Data using Robocopy Also see: This newer post [...]

    Pingback by Backing Up Your Data using Robocopy « Broken Remote — November 3, 2008 @ 2:14 pm

  2. how do you use robocopy if you want to copy very large files (>50gb) in a DVD-R? I tried it and I was unsuccessful.

    Comment by frank m — November 23, 2008 @ 5:06 pm

  3. The file size in general does not make any difference with Robocopy. You cannot, however, use Robocopy to burn a DVD. You need special software for that that knows how to interface with your DVD burner – Robocopy can only work with things like hard drives or USB thumb drives.

    If you’re looking for a free program to burn data DVDs with, check out this program: http://www.dandans.com/TotallyFreeBurner.htm. I don’t have any personal experience with it, but it was featured on Lifehacker.com, so I trust the application and its functionality.

    Good luck!

    Comment by Broken Remote — November 24, 2008 @ 12:54 am


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.