Backing Up Data with XCopy

Looking for a quick and easy way to backup the data on your windows computer to another drive?  Using a simple XCopy command from DOS, we can accomplish this.  So first lets take a look at the DOS command we will use and break it down for a minute.

xcopy /d /e /y /h /c “c:\users\myuser\documents\*.*” “x:\databackup\documents\*.*”

Looking at the above command we see the xcopy command followed be several letters with slashes.  These are the parameters we are telling xcopy to use.  Next we have the source location (what we want to copy) in quotation marks, followed by the destination location (where we want to copy it).

So let’s look at all those parameters.  I have them all listed below if you are interested in knowing what they do, otherwise just skip to the next paragragh.

  • /d – Copies only those files whose source time is newer than the destination time.  This is very important so as we go forward we are only copying the updates, not every file every time.
  • /e – Copies directories and subdirectories, including empty ones.  This means it will copy our directory structure under the main folder, keeping it identical.
  • /y – This supresses the prompting you would normally get when Windows was going to overwrite a file.  This keeps the program moving, and is way less annoying that if you didn’t have this set.
  • /h – This tells xcopy to copy hidden and system files.  The files you may not normally see in your folder, but are still there and still important.
  • /c – This parameter tells xcopy to keep copying, even if there is an error.  This is important as you don’t want to have your program stop in the middle of copying due to an error.  You can always go back and fix the error at a later point.

Next you will notice there is then a directory path in quotation marks (c:\), this is the source where we are copying from.  You will notice it is the exact directory path, and on the end there is *.*, what that means is to copy everything under that directory.  This way we can just take the whole Documents directory without having to look at each folder or file.  When doing your own command, you will need to change this page to point to your own user directory.

The next directory page is where we are copying to, so in most cases this would be your external hard drive.  You will notice that it points to a folder called DataBackup on the external.  Right now the drive letter is set to X, but that can be changed to whatever letter Windows uses.  Again, you will need to update and change the directory based on where you want to copy your data to.

In short, the above command copies all the data from MyUser’s Documents directory, to his external hard drive, or X drive, into a DataBackup folder.  That is all great, but we all know that there is more data than just what is in the Documents folder.  So let’s take a look at what a sample batch file would look like.

xcopy /d /e /y /h /c “c:\users\myuser\documents\*.*” “x:\databackup\documents\*.*”
xcopy /d /e /y /h /c “c:\users\myuser\favorites\*.*” “x:\databackup\favorites\*.*”
xcopy /d /e /y /h /c “c:\users\myuser\music\*.*” “x:\databackup\music\*.*”
xcopy /d /e /y /h /c “c:\users\myuser\pictures\*.*” “x:\databackup\pictures\*.*”
xcopy /d /e /y /h /c “c:\users\myuser\videos\*.*” “x:\databackup\videos\*.*”

So basically if you opened Notepad and started a new text file, you could name it mybackup.bat so that it would be a batch file.  You can then copy the commands above, paste it into your batch file and update the directories for both the source and your destination and you would be set.  The batch file above would copy your Documents, IE Favorites, Music, Pictures, and Videos folder to your external hard drive for you.  But as always you can add lines and do as many, or as few directories as you want.

This is a great, cheap way of automating a basic home backup.  However there is one slight flaw with this method, the data only goes one way.  That means if you deleted a file on your hard drive, the xcopy will not remove it from the backup.  Depending how you look at this, it can either be a flaw or a feature.  So if you find yourself one afternoon feeling like playing with DOS commands and want to setup a backup method for your data, this is a great and simple way of doing it.

1 Response

  1. Ryan Nelson says:

    Check out robocopy. It’s smarter and more efficient than xcopy with a ton more features. An interesting example is that it will retry copying files that fail. This can be handy if you’re working with network shares, but you also might want to adjust the retry settings as the default is to retry 1 million times at 30 second intervals. Robocopy is included in Windows 7, and downloadable for earlier versions of Windows.