How to backup using Robocopy

I have been using Beyond Compare to backup my files for a while and decided to try out Robocopy. Don’t get me wrong Beyond Compare (BC) is a pretty cool software and I will still use it for its primary function ie. compare folders and files. However, Robocopy has some advantages over BC when used as a backup software.

The main advantage is that Robocopy comes already preinstalled with Windows for free! No need to purchase, download and install anything.

What if you are willing to spend money on a “proper” backup software?

In my article How to use Beyond Compare for Backup, I’ve mentioned reasons against standard backup software:

  • proprietary backup archive formats
  • backup growing in size due / need of automatic clean-up

The growth might be a non-issue if you got a large storage capacity, however the proprietary format is a no-no:

The only way to access the files was to download current trial version of the program, install it and only then I was able to open it. To get the actual data out, I had to start a recovery wizard and wait for it to open the archive. Booring.

What if vendor goes out of business? How would you access your backup then?

What if you just want a simple copy of all of your data on your backup drive?

Let me show how to do just that with Robocopy.

Robocopy command

Here is the basic command:

robocopy P: S: /MIR /XD "$RECYCLE.BIN" /R:0 /W:0

This will mirror files from P: drive (your data) to S: drive (your backup) and exclude recycle bin. It will skip any read and write errors.

Make sure to replace P and S with your particular paths. It will work with folders too. Keep in mind the order. First path is the source (your original data), second path is the destination (your backup). If you mess up and swap the order you can lose your data!

Scheduling

Now, let’s schedule it to run automatically on a regular basis with Task Scheduler.

First, create an empty file “backup.cmd” and paste the command above inside.

Open up Task Scheduler (all it takes is to simply search for it or follow this guide).

Create a new task.

Give it a name and switch to Triggers tab.

Click New… button. Here you are going to configure when to run the backup. I suggest once a day but feel free to tweak at your leisure.

Click Ok when done and switch to Actions tab.

Click New… button. This is a dialog where you select to run the .cmd file we created before.

Click Ok on New Action dialog and Ok again on Create Task.

Congrats, your backup is scheduled to run regularly.

Nevertheless, you can always right-click the task and force it to run manually.

Try it out. Make sure to set the right paths in the .cmd file.

Running backup in background

Did you run the task? You might’ve noticed a command/console window appearing and writing out your entire drive content.

This can be sometimes annoying, if you’re focused on something else and the window with backup pops into existence.

Luckily, there is a tiny free utility CMDH which takes care of it. Get it from Tuts 4 You forum or from IPFS.

Move the cmdh.exe into the same folder as backup.cmd.

Open Task Scheduler, right-click MyBackup task and select Properties. Go to Actions tab and press Edit… button.

Change the program/script from the .cmd file to cmdh.exe and add file path to the .cmd file surrounded by quote marks “<your path>” as an argument.

Click Ok on Edit Action dialogue and on the task properties dialog.

This makes the backup sort of invisible. You might spot the process in the Task Manager as “Microsoft Robocopy”.

Add logging

If the backup is invisible, how do you make sure it’s running correctly? Let’s add a simple logging so you are able to inspect the output of the last run.

Open the backup.cmd file and append:

 > C:\BC_backup\backup.log

Your file should look like this:

This redirects the output of robocopy into a file. So everything the robocopy would write in a console is written into a file.

This overwrites the file each time.

If you’d like to have log of every run, change it to:

 >> C:\BC_backup\backup.log

Run the task and voilá, you got yourselves a backup with a logging feature.