Specifying a Copy Schedule in Robocopy

by Barry Dysert
(last updated August 25, 2014)

9

You can use the built-in scheduling capability of Robocopy to specify a copy schedule instead of resorting to the Windows Task Scheduler to perform copies. There are actually a few different ways to use a copy schedule. When you specify the /MON:n switch Robocopy stays running and continually monitors the source directory for changes. When it detects that "n" or more changes have occurred to the source directory it implements these changes in the destination. (That is, when files get created in the source, the files are automatically copied to the destination.)

C:\> ROBOCOPY C:\Temp1 C:\Temp3 /MON:1

You exit the running of Robocopy by pressing the CTRL+C combination.

Similar behavior exists by specifying the /MOT:m switch. In this case, Robocopy stays running and performs another copy (if necessary) in "m" minutes' time if things have changed.

C:\> ROBOCOPY C:\Temp1 C:\Temp3 /MOT:1

So, with this command line, Robocopy looks for changes once every minute, and if there are any they are implemented. As before, press CTRL+C to stop Robocopy from running.

A third way of scheduling a copy is to use the /RH:hhmm-hhmm switch. This tells Robocopy that it can only copy files between the hours/minutes of the first "hhmm" and the second "hhmm". There are, of course, three scenarios here. If the timeframe specified with /RH has already passed, Robocopy will remain paused until the time occurs the next day. If the current system time is within the boundaries established with /RH then the copy occurs immediately. Finally, if the timeframe specified with /RH is in the future, Robocopy remains paused until the time occurs, and then the copy is performed. As an example:

C:\> ROBOCOPY C:\Temp1 C:\Temp3 /RH:1300-1400

This tells Robocopy to do its copying between the hours of 1300 and 1400 (1:00 pm and 2:00 pm).

 This tip (13219) applies to Windows 7 and 8.

Author Bio

Barry Dysert

Barry has been a computer professional for over 30 years, working in different positions such as technical team leader, project manager, and software developer.  He is currently a senior software engineer with an emphasis on developing custom applications under Microsoft Windows. ...

MORE FROM BARRY

Finding New Desktop Widgets

Although there are several widgets that come with Windows, a lot more are available if you're willing to do a little Web ...

Discover More

Copying Data with Robocopy

Robocopy is a robust file copy utility built into Windows. If you have a lot of file management to do that can't easily be ...

Discover More

Running a Batch File at a Scheduled Time

Once you become comfortable with batch files, chances are that you'll want to use them to perform various system maintenance ...

Discover More
More WindowsTips

Using File History

Backing up your data is an important part of computer management. Enabling File History is a painless way to be able to ...

Discover More

How to Change Drive Letters

Windows is quite configurable. It even allows you to change the drive letters associated with your disk drives. Although the ...

Discover More

Mapping a Network Drive

You can create a mapping relationship between a network folder and a drive letter so that it's easy to access the folder by ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WindowsTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 7 - 0?

2017-01-12 07:44:05

Jari

I'm not able to get /PF switch working? Anybody got any idea why?

Using these switches:

/NC /NDL /E /COPYALL /DCOPY:T /ZB /RH:1730-0700 /PF /ETA /MT:4 /R:1 /TEE /log+logfile.log


2016-12-04 16:34:36

Barry

I don't believe Robocopy can do what you need. The requirement of copying only 5000 files at a time is the sticking point.


2016-12-04 11:02:10

User2016

Barry,
The requirement I have is to move files from a directory of 300,000 files(static) but only 5000 at a time to the destination directory. The process needs to be repeated every 2 hrs.

Does Robocopy have that option as I didn't see one. Are there any combinations which could help me acheive that.


2016-11-24 03:01:28

Eric Price

I use the /RH:1930-0730 switch for transferring backups to a data center overnight and it works just fine, but you might also want to include the /PF (per file) switch.

With the /PF switch it checks the run hours for each file rather than the whole batch, once it tries to copy a file outside of the run hours it will then pause until the start time is reached again.

My next 'to do' is to figure out how to tell if it's the weekend and keep going..


2016-02-10 11:34:30

Barry

David, I don't know if that's the case. Please do test and report back here for everyone's sake. Thanks!


2016-02-10 11:24:29

David I. McIntosh

Documentation on the /RH option is incomplete. In particular, what if the interval over which you want to copy spans midnight? For example, if I want to copy from 11pm to 1am, i.e. 23:00:00 to 01:00:00, how can I specify this? I would hope that I can specify '/RH:2300-0100', and that robocopy is smart enough to figure out that if the starting time is greater than the stopping time, (e.g. in this case 2300 > 0100), that the implication is that the interval spans midnight. In other words, the test for "copyingActive" should be:
if( startTime <= stopTime )
{
copyActive = (startTime<=currentTime) && (currentTime<stopTime);
}
else
{
copyActive = (startTime<=currentTime) || (currentTime<stopTime);
}

Do you know if this is the case? I am about to test, and will post back here, but this should be added to your documentation.


2015-05-04 18:13:25

Barry

Mark, although I haven't tried it, I suspect you'd get a file locked error, and depending on what options you gave Robocopy either the file would be skipped or your job would die.


2015-05-04 17:43:36

Mark

From what I can tell, I can use MS scheduler to run a robocopy command every 2 min. What happens when the first command has not finished copying files before the second instance launches? I am worried about action against a file that is still in the directory but has a status of open.


2015-01-29 10:03:24

annonymous

1st and 3rd scenarios you gave for /RH flag are same. Another scenarios is when copy operation overshoots the time limit.


Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in WindowsTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.