Pular para o conteúdo principal

Use Robocopy's multi-threaded feature to quickly backup your data in Windows 7

Use Robocopy's multi-threaded feature to quickly backup your data in Windows 7: "
Soon after Windows Vista came out, I discovered that Microsoft had updated the venerable Robocopy with a bunch of extra features and made it a regular part of the Windows operating system. Of course, when Windows 7 came out I immediately examined the newest version of Robocopy and discovered that Microsoft had again updated Robocopy with a single, but very powerful new feature - the ability to perform a multi-threaded copy option. More specifically, with multi-threaded capabilities Robocopy can now simultaneously copy multiple files in parallel, which will result in very fast backup operations.

In this edition of the Windows Desktop Report, I’ll show you how to take advantage of Robocopy’s features to create an exact mirrored duplicate of all the pertinent data files in your user profile folder (C:\Users\YourName). As I do, I’ll show you how to use the new multi-threaded copy feature.

This blog post is also available in the PDF format in a TechRepublic Download.

Why use Robocopy?


If you’re a conscientious about the safety of your data, chances are good that you are already using Windows 7’s Backup and Restore tool to create an image file of your hard disk as well as to backup your data files on a regular schedule. However, you may like to have an additional copy of your data files just to be on the safe side. While you can easily do so by copying your files and folders to an external hard drive via drag and drop, that can be a tedious operation.

Fortunately, Robocopy provides more than 80 different command line switches that will allow you to create a powerful data backup operation. To help you get a leg up, I have delved into Robocopy ’s command line switches and have developed a nice little script that you can use to create an exact mirrored duplicate of all the data files in your user profile folder (C:\Users\YourName). Let’s take a closer look.

Constructing the command line


For my example, I’m going to back up the data file contents of my user profile folder, C:\Users\Greg Shultz, to a folder named TheBackup on an external hard disk which is assigned drive letter G. (You’ll of course substitute the names and paths with your own.) As such, my command will begin with:

Robocopy “C:\Users\Greg Shultz” “G:\TheBackup”

Now, I want to backup every folder in the source, even any empty folders, as they may be place holders for future data. I also don’t want to have files on the backup that I deleted from my hard disk. While I can use the /S and /PURGE switches to accomplish my goal, I can use the /MIR switch to accomplish both of these tasks with one switch. As such, my command is now:

Robocopy “C:\Users\Greg Shultz” “G:\TheBackup” /MIR

The C:\Users\Greg Shultz folder contains several hidden, system files and folders that I don’t want or need to backup. For example, I don’t need to back up the NTUSER.DAT file nor do I need to backup the contents of the AppData folder. In addition, the C:\Users\Greg Shultz folder contains a host of junction points that I don’t need to back up.

Windows 7 uses junction points to link various operating system folders to the user profile folder. For example, the Cookies folder and the SendTo folder are linked to the user profile folder via junction points.

I’ll use the /XA:SH switch to exclude the hidden, system files and I can use the /XD AppData to exclude the entire AppData folder. I’ll then use the /XJD to exclude all of the junction points. As such, my command is now:

Robocopy “C:\Users\Greg Shultz” “G:\TheBackup” /MIR /XA:SH /XD AppData /XJD

One of Robocopy’s most useful features comes into play when it encounters a file that is in use. When it does, Robocopy will stop and wait for that file to be closed so that it can continue with the copy operation. It will retry to copy the file every 30 seconds. The default number of retries is 1 million (no joke!). As this will most like prevent the backup operation from ever completing, you should reset it to a reasonable number.

To change the number of retries, you’ll use the /R switch and to change the wait time between retries you’ll use the /W switch. I chose 5 retries with a 15 second wait time. That way after a reasonable number of retries and wait period, Robocopy will move on. As such, my command is now:

Robocopy “C:\Users\Greg Shultz” “G:\TheBackup” /MIR /XA:SH /XD AppData /XJD /R:5 /W:15

At this point, I am ready to add the new multi-threaded switch: /MT[:n], where n is a number from 1 to 128 and indicates the number of threads to be used. Keep in mind that n is optional and that by default, the /MT switch will use 8 threads. I’ll use 32 threads in my example, as I found it to be a good starting point. (Note that the multi-threaded option is not compatible with the /IPG and /EFSRAW switches.) At this point, my command is now:

Robocopy “C:\Users\Greg Shultz” “G:\TheBackup” /MIR /XA:SH /XD AppData /XJD /R:5 /W:15 /MT:32

Like all command line tools, Robocopy keeps you apprised of the status of operation right in the Command Prompt window. However, chances are that you’ll want to customize and record that feedback in a log file. I like to have the whole picture, so I’ll use the /V switch. However, I really don’t need to know the percentage progress of each file copy, so I’ll use the /NP switch. To create my log file, I’ll use the /LOG switch, which will overwrite the existing log file each time. Now, my command is:

Robocopy “C:\Users\Greg Shultz” “G:\TheBackup” /MIR /XA:SH /XD AppData /XJD /R:5 /W:15 /MT:32 /V /NP /LOG:Backup.log

Creating and using your script


Now that you know how the script works and the necessary switches, you can launch Notepad, type the command, and save the file as RobocopyBackup.cmd. To make sure that the script and open log file doesn’t interfere with the backup, I created a folder in the root directory called BackupTool (C:\BackupTool) and saved the script there.

You’ll find the log file in the same directory as the script after each backup operation. Keep in mind that while the log file is a simple text file, it can be larger than Notepad can handle. As such, you may want to use Wordpad or another word processor to open and view the log file.

Now, anytime that you want to make an extra backup you can just double-click on the RobocopyBackup.cmd to launch it. When it is done, you can examine the Backup.log file. You can also use the Task Scheduler to automatically run your RobocopyBackup.cmd on a regular basis if you want.

What’s your take?


Have you used Windows 7’s version of Robocopy? If so, what’s been your experience? Would you add any additional switches to the script that I presented? As always, if you have comments or information to share about this topic, please take a moment to drop by the TechRepublic Community Forums and let us hear from you.

Stay on top of the latest Microsoft Windows tips and tricks with TechRepublic’s Windows Desktop newsletter, delivered every Monday and Thursday. Automatically sign up today!




"

Comentários

Postagens mais visitadas deste blog

Favigen, Favicon Generator

Favigen, Favicon Generator : " Favicons are small icons that help identify websites. They are used as a visual representation of a website both in the web browser and at many online services. The three most prominent locations of favicons are the browser’s address bar, the tabbar and the bookmarks folder. Many webmasters like to create custom favicons to add that custom identifier to their website. Favicons can be created in many image and icon editors, but also online. Favigen is a straightforward favicon generator that can turn an image into a favicon. All that it takes is to pick an image from the local hard drive first, select the dimensions of the favicon and click the submit button to make the service generate the favicon. Favigen supports several image formats, including jpg and png, and it does not seem to have size restrictions either. Available image dimensions range are 16×16, 32×32 and 64×64. The generated favicon is displayed directly on the page. A click on do...

A simple rsync script to back up your home directory

A simple rsync script to back up your home directory : " Backing up important data is obviously something we should all do. Unfortunately, it is not always easy to make it happen. We get lazy; we do not have the additional hardware for a backup server; it takes a long time and a lot of CDs to back up to optical media; we do not trust online backup services; backup schemes are difficult to set up and use — any of dozens of reasons can stand in our way. Still, we know we should be backing up our important data. Modern open source Unix-like operating systems offer a plethora of options for incredibly simple, effective backup schemes, however. If the problem is figuring out how to set one up, a simple rsync solution may be exactly what you need. The rsync utility is used to synchronize files between two systems. It does so by way of incremental copies, only copying from the source to the destination what has not already been copied there, saving time, network bandwidth, and syst...

Google Wave now open to the public: faster, Robots and Gadgets aplenty!

Google Wave now open to the public: faster, Robots and Gadgets aplenty! : " Filed under: Internet , Google If you somehow missed it, Google Wave is now a bonafide Labs project: rather than being an invite-only alpha, it's now a public beta test! If you don't already have an account, just head on over to Wave and use your regular Google login details. If you've not seen any of the Google Wave introductory videos , you should check them out -- they explain the whole thing a lot more succinctly than I ever could. Wave has also been enabled for Google Apps domains -- businesses could convert their internal communication to Waves today! Leading up to this public release there have a lot of changes. It's by no means finished, but Google Wave is now a lot faster . It's also more intuitive -- more useful -- and given the large number of Robots and Gadgets now reaching prime-time readiness, it feels like the mass adoption of Wave is imminent. Also, if you're an ol...