Robocopy - Looking for help with syntax

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?
LVL 1
DaveWWWAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
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 ...)
ncomperCommented:
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 supportCommented:
To close outlook remotely properly, you can make a .vbs script called by CloseOutlook.bat:

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

IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

serialbandCommented:
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.
https://github.com/candera/hobocopy

Some basic instructions.
http://www.howtogeek.com/howto/windows-vista/backupcopy-files-that-are-in-use-or-locked-in-windows/?PageSpeed=noscript
DaveWWWAuthor Commented:
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.
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Surprisingly you are correct! This has been reported at least since Vista, see e.g. https://social.technet.microsoft.com/Forums/en-US/402843b9-e313-445a-8c79-90beff995b5b/robocopy-deleting-usable-destination-files, and I've logged the file operations on W10 (!) performed by RoboCopy - it actively kills the destination file on fail. That are really bad news, as there is no direct workaround (using RoboCopy).

The above link uses an additional backup location as intermediate destination, and copies from there, leaving existing files intact.
Another approach is to create a user without deletion permission on the target folder, and running RoboCopy with that user. This is just an idea - no clue whether it works.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DaveWWWAuthor Commented:
Thanks very much. Although not the answer anyone wants, it is at least an answer.  Now I know I'm not going crazy! :-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Storage Software

From novice to tech pro — start learning today.