Avatar of DaveWWW
DaveWWW
Flag for Canada asked on

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?
Storage SoftwareMicrosoft DOSWindows Batch

Avatar of undefined
Last Comment
DaveWWW

8/22/2022 - Mon
oBdA

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 ...)
ncomper

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
NVIT

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

Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
serialband

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
DaveWWW

ASKER
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.
ASKER CERTIFIED SOLUTION
Qlemo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
DaveWWW

ASKER
Thanks very much. Although not the answer anyone wants, it is at least an answer.  Now I know I'm not going crazy! :-)
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.