Backup Files with XCOPY


This entry is part 4 of 4 in the series DOS

In Windows, I regularly like to backup my data files from my laptop to my external drive. I can use DOS’ XCOPY command to do this for me, and you can too. I want to copy all the files in a particular folder in my D drive to a particular folder in my external drive. It’s okay if you only have a C drive ad this will work for you too. I want to be able to safely run this command and walk away and get a coffee without having to answer any prompts from DOS. I want it to copy any new files I’ve added to the source folder over to the destination folder. I also want it to overwrite any files that have changed. In other words, I want the newest version of the source file to be written over to the destination file, replacing it. I don’t need the old version. I want all hidden files, if any, copied over as well.

How can I manually do all of this with a simple XCOPY command at the command prompt?

Testing the Command

I highly recommend that you first test your XCOPY command before using it on live data. Here’s what I did. I manually created two new folder in two different Windows drives on my laptop to simulate a real backup to my external drive. Your test could be on the same drive. Let’s keep this simulation simple. Create these two folders and add a file or two into the first one.

  • C:\test_bk
  • D:\test_bk

Below is the command. There are a lot of switches here. I simply created a couple of text files in that C drive folder above. They have a word of two inside each one. Go ahead and create whichever files and folders you need to run your own tests. Run the command and then make a change to a source file, run the command again and check to see if the update was copied to the destination folder. It should be. This is what I originally wanted to happen.

xcopy c:\test_bk d:\test_bk /d /h /r /c /s /e /y

Here’s a link to Microsoft’s website on XCOPY. It explains the switches.

  • /d xcopy copies all source files that are newer than existing destination files, when no date is provided
  • /h Copies files with hidden and system file attributes. By default, xcopy doesn’t copy hidden or system files
  • /r Copies read-only files.
  • /c Ignores errors.
  • /s Copies directories and subdirectories, unless they’re empty. If you omit /s, xcopy works within a single directory.
  • /e Copies all subdirectories, even if they’re empty. Use /e with the /s and /t command-line options.
  • /y Suppresses prompting to confirm that you want to overwrite an existing destination file.

Use Case – PDFs

I have a folder with subfolders that contain some PDFs I’ve found and downloaded. I like to keep them all and I occasionally add more PDFs to the folders. I can use this XCOPY command to keep my backups of these files up to date. You could have folders with mp3 files or whatever type of files you like to store.

Series Navigation<< DOS Command to Merge Files

Leave a Reply