Broken Remote

August 21, 2008

Backing Up Your Data using Robocopy

Filed under: computer, software — Tags: , , — Broken Remote @ 11:11 pm

Also see: This newer post

The Problem

Backing up your data can get a little confusing sometimes. You need a data backup location like an external hard drive, but then you either have to use the software you were given or spend hours finding one you like, only to realize you will have to pay to use it. I won’t spend any time in this post on good hardware, I want to give my solution to the software problem.

The Solution

I hunted and hunted on my own for a while. I found some OK applications, but none that gave me the level of customization that I want…at the price I want: Free. Then I discovered RoboCopy. It’s a command line utility for Windows that kicks the butt of xcopy down the street and back.

For Windows XP users, you’ll need to download this utility. Windows Vista users, it’s installed for you already. You can download it as part of the Windows Server 2003 resource kit. Don’t heed the name, you can install this on XP.

Download

Don’t be mistaken now. You don’t just run this application straight out of the box. We will make use of the program via batch file.

The Script

Here’s a script I wrote to make use of this application.

@ECHO offREM —– SETUP INFORMATION —–
ECHO *———————————————*
ECHO Windows Backup Utility
ECHO *———————————————*
ECHO.

ECHO This script uses robocopy, a command line copy utility from Windows
ECHO Windows vista supports this by default, but older machines need the
ECHO Windows resource kit for robocopy support.
ECHO.

REM —– BACKUP SOURCES —–
SET profile=C:\Users\username

REM —– VERIFY BACKUP FOLDERS —–
ECHO —————————————-
ECHO Folders to backup
ECHO —————————————-
ECHO – %profile%
ECHO.

REM —– ASK USER TO PROCEED —–
SET /P continue= Proceed? (Y/N):
IF /I %continue%==N GOTO END

REM —– SET DESTINATION VARIABLE —–
SET dest=E:\Backups

REM —– Use below code to have user specify backup directory. Just remove the “REM” and put “REM” before the line above
REM SET /P dest=Backup directory:

REM —– DO THE COPY —–
REM —– Do ROBOCOPY /? in a command prompt for details on other flags
REM —– /MIR = delete files from destination that have been deleted on source
REM —– /LOG = create a log file
REM —– /R:0 = don’t retry a file if it fails. Change number as you wish
REM —– /W:0 = don’t wait to retry a file if it fails. Change number as you wish
REM —– /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
REM —– /XJD = Windows Vista has some weird folder virtualization to prevent programs from accessing folders directly. Exclude Junction points to fix this.
ROBOCOPY “%profile%” “%dest%\profile” /MIR /XJD /LOG:%dest%\profileLog.log /R:0 /W:0 /TEE

:END

pause

It’s not hard to use. Just follow these steps:

  • Create a new text file in notepad or other simple text editor
  • Paste the entire text in the dark box into notepad
  • Save the file as “backup.bat”. The important part is the “.bat” extension. This tells Windows that it is a series of commands.

Now you need to customize the file to match your needs. Under the BACKUP SOURCES header above, change the existing string “C:\Users\username” to match. For Vista users, just replace “username” with your username. For XP users, use “C:\Documents and Settings\username”. You can add new backup paths here using the same format.

Now, under VERIFY BACKUP SOURCES, just add new lines to print out what sources you are backing up. This helps you remember when you run your program what you are about to backup.

Third, under SET DESTINATION VARIABLE, set this to your backup drive. Most likely it will be E: for an external hard drive. You can use just the drive letter or specify a folder on that drive like I did.

Now, at the end of the document, look for ROBOCOPY “%profile%” “%dest%\profile” /MIR /XJD /LOG:%dest%\profileLog.log /R:0 /W:0 /TEE. Copy and paste this line once for every directory you back up, being sure to change the backup source and destination though!

Now just keep this file in a handy location, plug your backup drive in, and run it! It keeps a log of all the files it copies and if it succeeded or not. This script will do an “incremental backup” as well. This means that when you back up your data the first time, it will copy it all. Subsequent backups will only copy files that have changed.

PLEASE NOTE: If you delete a file from your computer, then run this backup utility, that file will be deleted from your backup data. To prevent this, uncomment the code underneath SET DESTINATION VARIABLE section by removing the REM so it says (SET /P dest=Backup directory:)and set a new folder every time you back up. I would create about 3 or 4 different folders and loop through them.

That’s it. I appologize for any confusion. If you have questions, leave a comment and I’ll be glad to help out.

Note: I have discovered a GUI for robocopy. If this interests you, check it out here.

2 Comments »

  1. [...] up your data using Robocopy: Redux 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 [...]

    Pingback by Backing up your data using Robocopy: Redux « Broken Remote — November 3, 2008 @ 2:12 pm

  2. [...] obot on Thu 20-11-2008 REM – Accelerate Tour 08 (24.08.08) Saved by N8music on Fri 14-11-2008 Backing Up Your Data using Robocopy Saved by kaitum on Tue 11-11-2008 plants Saved by erhanerdogan on Sun 09-11-2008 Bad [...]

    Pingback by Recent Links Tagged With "rem" - JabberTags — December 1, 2008 @ 10:19 pm


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.