We help IT Professionals succeed at work.

Robocopy - Looking for help with syntax

Last Modified: 2016-01-26
I have a nightly backup of a folder to another PC. When a file cannot be copied, for example because it is open such as a .PST file, the destination .PST (from an earlier successful backup) is gone too.

I want RoboCopy to copy all new and changed files to the destination, leaving any other files in the destination alone.  In xcopy syntax, I want this:

xcopy <folderA> <folderB> /s /e /y /c /d

In RoboCopy, I'm doing this:
Robocopy \\MachineA\Data C:\BackupFolder\Data /E /COPYALL /XO /R:0 /W:0 /LOG:c:\BackupLog1.txt

When outlook.pst on MachineA\Data is not available (because it is open, for example), the destination folder also doesn't seem to have the .PST, even though it was there the previous night.

Is there an obvious error I'm making here?
Watch Question

Most Valuable Expert 2019
Most Valuable Expert 2018

Your syntax looks fine, and unless you're using /mir, robocopy doesn't remove files from the target directory. It only starts to overwrite files if it actually can access the source. And even with /mir, I can't get it to delete an existing target file if the source is locked.
Check the log file; the open files should be tagged with "newer" before the error message shows up.
Are you absolutely sure the command you posted here is the actual command you're running?
Is that part of a script, where maybe the target folder is cleared somewhere before the robocopy line?
Is that really the only task that does a copy to this folder (stranger things have happened than folders being backed up by multiple schedules ...)

I have found using the /Z and /B (or /ZB) allow the backup of files that are in use. This may circumvent your issue altogether
NVITEnd-user support

To close outlook remotely properly, you can make a .vbs script called by CloseOutlook.bat:

Set fn=CloseOutlook.vbs
>> echo "%fn%" Dim oOL
>> echo "%fn%" Set oOL = CreateObject ^("Outlook.Application"^)
>> echo "%fn%" oOL.Quit
cscript "%fn%"

Open in new window

Run it via psexec:
Psexec \\machine -c CloseOutlook.bat

Open in new window


Robocopy can't copy in use files.

If you want to copy open files, you can enable VSS and use hobocopy.  hobocopy will make use of the shadow copy to copy those files.

Some basic instructions.


Hi all, and sorry for abandoning.  I've been away, and am just back at this client today.

I understand you cannot copy in-use files, but the problem is that when (for example) a PST is in use, it doesn't copy it, *AND* it removes the old one from the destination.

What I can't figure out is why it seems to be removing the file from the destination.  here is the line from the batch file:

Robocopy \\MachineA\Data C:\BackupFolder\Data /E /COPYALL /XO /R:0 /W:0

I'm thinking there must be something about /XO that I'm not understanding?  I've looked in several users' Outlook folders on the backup drive, and the PST files are definitely not present.  When I let the backup run overnight, they are there on the backup drive in the morning.  I'm okay with missing the occasional backup, but not okay with Robocopy removing files.
"Batchelor", Developer and EE Topic Advisor
Top Expert 2015
This one is on us!
(Get your first solution completely free - no credit card required)


Thanks very much. Although not the answer anyone wants, it is at least an answer.  Now I know I'm not going crazy! :-)
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.