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

Improve Windows Security By Closing Open Ports

Improve Windows Security By Closing Open Ports : " A standard Windows operating system has a number of ports open after installation. Some of these ports are needed for the system to function properly while others might not. These ports can pose a security risk as every open port on a system might be an entry point for a malicious user. A port basically allows communication to or from the device. Characteristics are a port number, an IP address and a protocol type. This article will give you the tools at hand to identify and evaluate the open ports on your Windows system to make a decision in the end whether they can or should be closed or left open. Software programs and tools that we will use: CurrPorts : Available for 32-bit and 64-bit editions of Windows. It is a port monitor that displays all open ports on a computer system. We will use it to identify the ports and the programs that are using them. Windows Task Manager: Also used to identify the programs and link some p

Diagnosing a Blue Screen of Death Error in Windows

Diagnosing a Blue Screen of Death Error in Windows : For many years now the famous Blue Screen of Death (BSoD) has been the ultimate indication that something disastrous has happened to make your computer die, but how useful is the information in the BSoD and the respective crash dump file that Windows produces? The best article I ever found explaining the BSoD in depth is here on the Microsoft website, however it’s quite technical and doesn’t discuss how to actually troubleshoot a problem. The crash dump file is just technical details of what was being held in the computer’s memory at the time of the crash, and this will include details on every driver and service that was loaded, and every piece of software that was running. The most useful pieces of information are to be found on the BSoD itself and are highlighted on the screenshot below. These are the BSoD error name, the stop error code and the name of the driver or service that has failed (this last one might not always appea

Use BGInfo to Build a Database of System Information of Your Network Computers

Use BGInfo to Build a Database of System Information of Your Network Computers : " One of the more popular tools of the Sysinternals suite among system administrators is BGInfo which tacks real-time system information to your desktop wallpaper when you first login. For obvious reasons, having information such as system memory, available hard drive space and system up time (among others) right in front of you is very convenient when you are managing several systems. A little known feature about this handy utility is the ability to have system information automatically saved to a SQL database or some other data file. With a few minutes of setup work you can easily configure BGInfo to record system information of all your network computers in a centralized storage location. You can then use this data to monitor or report on these systems however you see fit. BGInfo Setup If you are familiar with BGInfo, you can skip this section. However, if you have never used this tool, it takes ju