Robocopy: A robust Windows tool for secure backups
Robocopy has been a part of the standard configuration of Windows since Windows Vista. The tool is highly valued by system administrators and IT professionals for its robustness and reliability. Copy projects that are overwhelming for other tools or result in error messages can usually be successfully completed using Robocopy on Windows 10.
- Free website protection with SSL Wildcard included
- Free private registration for greater privacy
- Free 2 GB email account
What is Robocopy?
Robocopy is a Windows tool that’s specialised on copy processes and backups. The program is managed using special commands and parameters that are entered into the Windows command prompt. However, less experienced Windows users are also able to graphical interface software for Robocopy. One such software is the free GUI tool RoboMirror.
Robocopy is the most versatile of Windows’s native copy tools, followed by xcopy and copy. With 72 parameters, it leaves little to be desired and can handle pretty much any backup. The program can even create incremental backups that only back up recent changes rather than complete backups. This space-saving method lowers the strain on bandwidth and other resources during cloud and network backups.
For secure, automatic backups in the cloud, you can use a professional service for affordable access to plenty of cloud space.
The tool can also mirror entire directory structures with relatively little code, meaning that it can include subdirectories in copy operations and backups. These code-based features act as a great supplement to other backup routines, which might concentrate on, for example, a system image of Windows 10. It can also act as a supplement or alternative to rsync for server backups.
The various features and flexibility of Robocopy backups come with a certain learning curve. Even when using a GUI tool, beginners will need to spend some time immersing themselves in the program before they can carry out efficient backups and take advantage of the full potential of Robocopy in Windows 10. However, when it comes to simple copy tasks, beginners can jump in relatively quickly with clear command syntax. Whether your operation is simple or complex, you should proceed with caution when using Robocopy – there’s always the danger that files accidentally get deleted or overwritten.
Command syntax for Robocopy backups
As with all command line tools in Windows 10, Robocopy requires a special command syntax for carrying out certain tasks. The basic structure looks as follows:
robocopy <source> <destination> [<file>[...]] [<options>]
The parameter “source” is for the path to the source directory. The path to the target directory is defined in the “destination” parameter. The “file” parameter is for the file that will be copied and allows for placeholders. If you enter *.* instead of a concrete file name, all files in the source directory (not including subdirectories) will be copied. If you want to include all files of a certain file type, you can combine the asterisk with the file ending. So, if you want to copy all Word documents (and only Word documents), the syntax would look like this:
robocopy <Source directory> <Target directory> *.docx
The copy command can be expanded with further options that are added at the end. You can, for example, define how often a copy attempt should be repeated until it’s complete. The time between attempts can also be defined. These parameters significantly contribute to the versatility and robustness of the tool. They are a major improvement over Windows Explorer, which doesn’t offer the chance to intervene and often aborts complicated copy operations for no apparent reason.
The most important Robocopy commands
Below you’ll find an overview of the most important commands and options, which can be used to carry out relatively simple Robocopy backups. In the section after that, we’ll show you how to implement the commands using examples.
/COPY:copyflag[s] | Copies file properties - standard setting: /COPY:DAT- D: Data- S: Security information (NTFS access control lists)- A: Attribute- O: Owner information- T: Time stamp- U: Auditing information (NTFS monitoring of file access) |
---|---|
/COPYALL | Copies all file information (Alternative to COPY:DATSOU) |
/NOCOPY | File information isn’t copied (Often used in combination with /PURGE) |
/PURGE | Deletes files and directories in the target directory if they no longer exist in the source directory |
/MIR | Mirrors a directory tree (Equivalent to combining /E + /PURGE) |
/MON:n | Robocopy is run again after n number of changes (Background operation for automatic backups) |
/MOT:n | Robocopy is run again after n number of minutes (Background operation for automatic backups) |
/RH:hhmm-hhmm | Defines a timespan in which Robocopy is active |
/XF | Excludes certain file types |
/XD | Excludes certain directories |
/R:n | Defines the number of retries for failed copy operations (Standard setting: 1,000,000) |
/W:n | Defines the wait time between retries in seconds. The standard setting is 30 (giving a wait time of 30 seconds before the next copy attempt) |
/L | Lists backup files (Test run, backup won’t be executed) |
/LOG: | Records status in a new log file for every backup or sync process |
/LOG+: | Adds status to existing log file |
/TEE | Outputs information on the screen as well as in the log file |
/MOV | Files are moved and deleted from the source directory after copying |
/MOVE | Files and directories are moved and deleted from the source directory after copying |
robocopy /? | Opens the Robocopy help guide in the command prompt |
How to open Robocopy
Robocopy is operated using the Windows command prompt (cmd.exe). To get to the command prompt, open the Windows 10 Run dialogue:
- Press [WIN] + [R]
- Type “cmd” into the field
- Press “OK”
The command prompt will open, where you can enter the command syntax for Robocopy backups and copy operations.
How to create backups with Robocopy
Robocopy is ideal for everyday backup routines. In this section, we show you how to set parameters and options and provide examples of the required code.
Mirroring directories
One of the most frequently used options in Robocopy for Windows 10 is the mirroring feature (/MIR), which creates a complete backup of the source directory:
robocopy C:\Users\Maria\Desktop\test T:\ /MIR
In this example, the entire source directory (named “test”) will be copied into 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, the profile belonging to Maria).
Pre-check with test run
If you want to test which files the mirror command catches and whether you’ll encounter any errors, you can add the parameter /L. The command line will document the process and show any errors but won’t create a copy.
robocopy C:\Users\Maria\Desktop\test T:\ /MIR /L
Fine-tuned control of Robocopy backups
For more fine-tuned control of a Robocopy backup, you can define the number of copy attempts (R:3 means three attempts) and the wait time between attempts (W:2 means 2 seconds). In addition, you can create a file that keeps track of backups:
robocopy C:\Users\Maria\Desktop\test T:\ /MIR /R:3 /W:2 /LOG+:Z:\LogFiles\logfile.log
In this example, the protocol of copy operations (logfile.log) will be created in the directory called “LogFiles”. Note that the log directory must already exist, otherwise the copy process will be aborted.
If you want to leave out certain files or file types, you can use the parameter /XF (eXclude file):
robocopy C:\Users\Maria\Desktop\test T:\ /MIR /XF *.docx
Entire directories can be left out using the XD option (eXclude directory). Since the directory in question (“My Documents”) contains a space, it’s placed in quotation marks:
robocopy C:\Users\Maria\Desktop\test T:\ /MIR /XD "My Documents"
You’ll need to indicate precise paths for copy operations to work with Robocopy in Windows 10. If any part of the path contains spaces, the path should be put in quotation marks.
But it gets even more fine-tuned than that. You can target specific file attributes for inclusion or exclusion. This is carried out with the option /COPY:copyflag[s]. Robocopy uses the command /COPY:DAT as a default to backing up file contents (D = data), attributes like read-only or hidden (A = attributes), and the time stamp (T = timestamp). The timestamp contains information about the date of creation, date modified, and the date last opened. This information is essential for incremental backups since 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 help, for example, when certain security rights aren’t correctly set in the target system, leading to failed or incomplete copy operations. In this case, you can refrain from using the S copy flag. Including flag A can, for example, copy read-only attributes onto the backup copies. If you want to transfer file contents, attributes, and the time stamp, the code will look as follows:
robocopy C:\Users\Maria\Desktop\test T:\ /MIR /COPY:DAT
Especially when it comes to lengthy backup processes, you might want to back up in stages using /Z. If Robocopy needs to be restarted, it will pick up where it left off. It won’t be a problem if a process is interrupted multiple times. This method saves time and resources, as it prevents large files from needing to be backed up all over again.
Automating Robocopy backups
One advantage of Robocopy is that backups can be executed via batch file. You can create a batch script on the desktop and start it with the click of a mouse, or you can put 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 the Windows Explorer and press Enter. Alternatively, you can also open the “Run” window with [Windows] + [R] and enter “shell:startup” there and click “OK”. Then you can drag the batch file into the directory using your mouse. A copy of the batch file or a shortcut link will also work.
Another method for automating backups is Robocopy’s monitor feature, which can permanently monitor a source directory. If changes are made, they will be automatically backed up. Robocopy can also be set to run on a schedule of your choosing (e.g., once an hour) or at a specific point in time (e.g., at 6 p.m.). You can set up monitoring with the option /MON:n (backup activated after n number of changes) or /MOT:n (backup activated after n number of minutes). /RH:hhmm-hhmm is used for specific points in time. /MON and /MOT can also be combined:
robocopy C:\Users\Maria\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. The changes are recorded in the log file. If you don’t enter a specific time, Robocopy will use the default setting for automatically checking the directory (check and, if necessary, backup after one minute). If you want to take a closer look at Robocopy’s activities, for example before initiating a new backup, you can use /TEE to view the log on the screen in the command prompt.
Constant background activity can place a strain on your resources, i.e., if large files are frequently being transferred on the network or into the cloud. Be cautious with automations and put some thought into update and backup cycles. It’s a good idea to regularly check the backup directory, especially at the beginning of a new backup operation. This way you can be sure of what Robocopy is doing and whether unnecessary, undesired, or error-ridden backups are happening in the background.