Robocopy: Powerful Security Backup Tool and Tutorial on Windows Platform

Robocopy has been a standard part of Windows since Windows Vista. The tool is highly regarded by system administrators and IT professionals for its robustness and reliability. Copying projects that are overwhelming to other tools or result in error messages can often be successfully completed using Robocopy on Windows 10. If you don't know Robocopy yet, let's take a look at how to use it.

What is Robocopy?

Robocopy is a Windows tool designed for copying and backup. The program is managed using special commands and parameters entered into the Windows command prompt. However, less experienced Windows users can also use GUI software for Robocopy. One such software is the free GUI tool RoboMirror.

Robocopy Tutorial

Robocopy is the most versatile Windows native copy tool, followed by xcopy and copy. With 72 parameters, it leaves little to be desired and can handle almost any backup. The program can even create incremental backups that only back up recent changes instead of full backups. This space-efficient approach reduces strain on bandwidth and other resources during cloud and network backups.

The tool can also mirror entire directory structures with relatively little code, which means it can include subdirectories in copy operations and backups. These code-based features can serve as a great addition to other backup routines, such as perhaps Windows 10-focused system images. It can also be used in addition to or as an alternative to rsync for server backups.

The variety of features and flexibility of Robocopy Backup comes with a certain learning curve. Even with a GUI tool, beginners need to spend some time immersing themselves in the program before they can make efficient backups and utilize the full potential of Robocopy in Windows 10. However, when it comes to simple copying tasks, beginners can jump around relatively quickly using the clear command syntax. Whether your operations are simple or complex, caution should be exercised when using Robocopy – there is always a risk of files being accidentally deleted or overwritten.

Command Syntax for Robocopy Backup

Like all command-line tools in Windows 10, Robocopy requires special command syntax to perform certain tasks. The basic structure is as follows:

 
 

1

robocopy <source> <destination> [<file>[...]] [<options>]

The parameter "source" is the path to the source directory. The path to the destination directory is defined in the "destination" parameter. The "file" parameter is for the file to be copied and allows placeholders. If *.* is entered instead of a specific filename, all files in the source directory (excluding subdirectories) will be copied. If you want to include all files of a certain file type, you can combine an asterisk with the end of the file. So if you want to copy all Word documents (and only Word documents), the syntax is as follows:

 
 

1

robocopy <Source directory> <Target directory> *.docx

The copy command can be extended with more options added at the end. For example, you can define how often a copy attempt is repeated until complete. It is also possible to define the time between attempts. These parameters significantly increase the versatility and robustness of the tool. They are a major improvement over Windows Explorer, which provides no opportunity to intervene and often aborts complex copy operations for no reason.

Most Important Robocopy Commands

Below you will find an overview of the most important commands and options that can be used to perform relatively simple Robocopy backups. In the following sections, we will show you how to implement these commands with examples.

/COPY:copyflag[s] Copy File Properties – Standard Settings: /COPY:DAT – D: Data – S: Security Information (NTFS Access Control List) – A: Properties – O: Owner Information – T: Timestamp – U: Audit Information (NTFS monitoring) usage rights).
/COPYALL Copy all file information (replaces COPY:DATSOU)
/NOCOPY Do not copy file information (usually used in conjunction with /PURGE)
/PURGE Deletes files and directories in the target directory if they no longer exist in the source directory.
/MIR mirror directory tree (equivalent to combination /E + /PURGE)
/MON:n Run Robocopy again after n changes (background operation for automatic backups)
/WORD:n Robocopy to run again after n minutes (background operation for automatic backups)
/RH: hhmm-hhmm Defines the time span during which Robocopy is active
/XF Exclude certain file types
/XD exclude certain directories
/R:n Defines the number of retries for failed copy operations (standard setting: 1,000,000)
/W:n Defines the wait time in seconds between retries. Standard setting is 30 (wait 30 seconds before next copy attempt)
/L List backup files (test run, backup will not be performed)
/LOG: Record status in a new log file for each backup or sync process
/LOG+: Add status to existing log file
/TEE output information to the screen and to log files
/MOV Move and delete files from source directory after copying
/MOVE Files and directories are moved and deleted from the source directory after copying
robocopy /? Open the Robocopy Help Guide in Command Prompt

How to open Robocopy

Robocopy uses the Windows Command Prompt (cmd.exe) to operate. To get to Command Prompt, open the Windows 10 Run dialog:

1. Press【Win】+【R】keys to open the run window
2. Type "cmd" in the field
3. Press "OK"

A command prompt opens where you can enter the command syntax for Robocopy backup and copy operations.

How to create a backup with Robocopy

Robocopy is ideal for everyday backup routines. In this section, we'll show you how to set parameters and options, and provide examples of the required code.

mirror directory

One of the most commonly used options in Robocopy for Windows 10 is the mirror function (/MIR), which creates a full backup of the source directory:

 
 

1

robocopy C:\Users\XU\Desktop\test T:\ /MIR

In this example, the entire source directory (named "test") is copied to the target drive (T:\), including all subdirectories (even empty ones). The source directory is located on the desktop of the currently active user profile (in this case, Maria's profile).

Pre-check with test run

If you want to test which files are captured by the mirror command and whether any errors are encountered, you can add the parameter /L. The command line will log the process and display any errors, but will not create a copy.

 
 

1

robocopy C:\Users\XU\Desktop\test T:\ /MIR /L

Fine-tuned control over Robocopy backups

For more control over Robocopy backups, you can define the number of copy attempts (R:3 means 3 attempts) and the wait time between attempts (W:2 means 2 seconds). Additionally, you can create a file to keep track of backups:

 
 

1

robocopy C:\Users\XU\Desktop\test T:\ /MIR /R:3 /W:2 /LOG+:Z:\LogFiles\logfile.log

In this example, the copy operation protocol (logfile.log) is created in a directory named "LogFiles". Note that the log directory must already exist, otherwise the copy process will abort.

If you want to omit certain files or file types, you can use the parameter /XF (exclude files):

 
 

1

robocopy C:\Users\XU\Desktop\test T:\ /MIR /XF *.docx

Entire directories can be excluded using the XD option (Exclude Directories). Since the directory in question ("My Documents") contains a space, it is enclosed in quotes:

 
 

1

robocopy C:\Users\XU\Desktop\test T:\ /MIR /XD "My Documents"

NOTE
You need to specify the exact path for the copy operation using Robocopy in Windows 10. If any part of the path contains spaces, the path should be enclosed in quotes.

But it will get finer tuned than that. You can target specific file attributes for inclusion or exclusion. This is performed with the option /COPY:copyflag[s]. Robocopy uses the command /COPY:DAT as a default backup file content (D = data), attributes such as read-only or hidden (A = attribute) and timestamp (T = timestamp). Timestamps contain information about the creation date, modification date, and last open date. This information is critical for incremental backups, as they should only apply to recently changed files and directories. Another parameter is S (=security), which transfers NTFS access rights.

Excluding individual copy flags can be helpful, for example, when certain security permissions are not set correctly in the target system causing the copy operation to fail or be incomplete. In this case you can avoid using the S copy flag. For example, include flag A to replicate the read-only attribute on the backup copy. If you want to transfer the file content, attributes and timestamp, the code looks like this:

 
 

1

robocopy C:\Users\XU\Desktop\test T:\ /MIR /COPY:DAT

Especially when lengthy backup processes are involved, you may wish to use /Z to stage backups. If Robocopy needs to be restarted, it will pick up where it left off. There is also no problem if a process is interrupted multiple times. This approach saves time and resources because it prevents the need to re-backup large files.

Automated Robocopy backups

One of Robocopy's strengths is the ability to perform backups via batch files. You can create a batch script on your desktop and launch it with a single mouse click, or you can place it in the Windows autostart directory to run the backup every time the system starts. To get to the Autostart folder, type the word "Autostart" into Windows Explorer and press Enter. Alternatively, you can use [Windows] + [R] to open the Run window, then enter "shell:startup" there, and click OK. Then you can use the mouse to drag the batch file into the directory. A copy of the batch file or a shortcut link will also work.

Another way to automate backups is Robocopy's monitoring feature, which permanently monitors the source directory. If changes are made, they will be automatically backed up. Robocopy can also be set to run on a schedule of your choice (for example, once an hour) or to run at a specific time (for example, 6pm). You can set up monitoring with the options /MON:n (activate backup after n changes) or /MOT:n (activate backup after n minutes). /RH:hhmm-hhmm for a specific point in time. /MON and /MOT can also be combined:

 
 

1

robocopy C:\Users\XU\Desktop\test T:\ /MIR /R:3 /W:4 /LOG+:Z:\LogFiles\logfile.log /MON:1 /MOT:25

In this example, Robocopy will run a backup after 25 minutes if at least one change has been made. Changes are recorded in log files. If you don't enter a specific time, Robocopy will automatically check the directory with default settings (check and back up after one minute if necessary). If you want to take a closer look at Robocopy's activity, for example before starting a new backup, you can use /TEE to view the log on the screen at the command prompt.

Note
Continuous background activity can put pressure on your resources, for example if large files are frequently transferred over the network or to the cloud. Use automation sparingly and consider update and backup cycles. It's a good idea to check the backup directory regularly, especially when a new backup operation starts. This way, you can determine what Robocopy is doing and if unnecessary, unwanted or bug-ridden backups are happening in the background.

 

Guess you like

Origin blog.csdn.net/winkexin/article/details/131636420