Skip to main content

USE ROBOCOPY FOR COMPLEX BACKUPS

· 4 min read
Bora

Robocopy, also known as “Robust File Copy,” is a command-line utility in Windows that allows users to quickly and efficiently copy files from one location to another. It was first introduced in Windows Vista and has been included in every subsequent version of Windows since.

One of the key benefits of using Robocopy is its ability to copy large numbers of files very quickly. It is also able to copy files over network connections, making it a useful tool for backing up data or transferring files between computers. Additionally, Robocopy is able to copy files even if they are in use, which can be helpful when trying to copy files that are currently open and being accessed by other programs.

One of the more advanced features of Robocopy is its ability to copy entire directories and subdirectories, including all of the files contained within them. This can be particularly useful when copying large file structures or when trying to create a backup of a specific folder on your computer.

In terms of syntax, using Robocopy is fairly straightforward. The basic command structure is as follows:

robocopy source destination [options]

The source and destination arguments are the locations of the files you want to copy, and the options argument allows you to specify various parameters for the copy operation. Some of the more commonly used options include:

/E: Copies subdirectories, including empty ones.

/MIR: Mirrors a directory tree. Deletes files in the destination that no longer exist in the source.

/Z: Copies files in restartable mode. If the copy is interrupted, it can be resumed from where it left off.

/XF: Excludes files with the specified names or paths from the copy.

/NP: Does not display the progress of the copy operation.

There are many other options available with Robocopy, and you can see a full list of them by typing robocopy /? at the command prompt.

EXAMPLES


Incremental backups:

Robocopy has the option to copy only files that have been modified or created since the last backup. This can be achieved by using the /XO (exclude older) option along with the /DCOPY:T (copy directory timestamps) option. This allows you to keep multiple versions of a file, so you can recover an older version if necessary. The command for an incremental backup would look something like this:

robocopy C:\Source E:\Backup /MIR /XO /DCOPY:T

Excluding specific files or folders:

You may want to exclude certain files or folders from the backup, such as temporary files or large media files. The /XF option allows you to specify the names or paths of files or folders to exclude. You can use the wildcard * to match multiple files. For example, if you want to exclude all files with the .tmp extension, the command would look like this:

robocopy C:\Source E:\Backup /MIR /XF *tmp

Backup to a remote location:

Robocopy can also be used to copy files over a network connection. To do this, you simply need to specify the remote server and share name as the destination. You should be logged in as an authorized user on the remote server. The command would look something like this:

robocopy C:\Source \\remote_server\share E:\Backup /MIR

Schedule the backup:

You can schedule a robocopy job to run at specific time period using Task Scheduler on Windows. This allows you to perform the backup automatically at a certain time of day, or on a certain day of the week or month. Keep in mind that when using the /MIR option, Robocopy will delete files in the destination that no longer exist in the source. So, it is important to make sure that you have a recent backup or a good understanding of the files you are backing up before running the command.

By using these options and techniques, you can create more complex backups using Robocopy and schedule them to run automatically. However, it’s important to test the backup thoroughly and ensure that you can restore the files correctly in case of disaster.