1

When attempting to mirror two folders using Robocopy, the option /MIR causes files in the destination to be deleted when the source files are in use. Specifically this happens when backing up my Outlook folder and the *.pst files are in use.

The output is as follows:

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows                              
-------------------------------------------------------------------------------

  Started : Tuesday, 18 August 2020 18:58:28
   Source : P:\Outlook\
     Dest : D:\_SyncFolderTest\To\Outlook\

    Files : *.*
        
  Options : *.* /BYTES /S /E /DCOPY:DA /COPY:DAT /PURGE /MIR /J /R:0 /W:30 

------------------------------------------------------------------------------

                      23    P:\Outlook\
        Newer           183116800   AVArchive_2018.pst
        Newer           128009216   AVArchive_2019.pst
        Newer           42427392    AVArchive_2020.pst
        Newer           403801088   AVOutlook.pst
        New File          131072    ~AVArchive_2018.pst.tmp
        New File          131072    ~AVArchive_2019.pst.tmp
        New File          131072    ~AVArchive_2020.pst.tmp
        New File          131072    ~AVOutlook.pst.tmp

------------------------------------------------------------------------------

                Total    Copied    Skipped  Mismatch    FAILED    Extras
    Dirs :          1         0          1         0         0         0
   Files :         23         4         15         0         4         0
   Bytes : 3545771008    524288 2787892224         0 757354496         0
   Times :    0:00:00   0:00:00                        0:00:00   0:00:00


   Speed :             37449142 Bytes/sec.
   Speed :             2142.857 MegaBytes/min.
   Ended : Tuesday, 18 August 2020 18:58:28

It is correct that AVOutlook.pst is newer, but can't copy it, doesn't raise an error, and deletes the older version in the dest. So not only did it not back up, but the previous backup is now gone. The exit code is the only clue that something went wrong: 8 = Some files or directories could not be copied.

I kind of understand that the dest old file must be removed and replaced in order to achieve a mirror image, but why no error, and why not recognise that files in the source and dest are related? Is this a shortcoming in Robocopy or a design decision? Is there a safer way?

2
  • @Pimp Juice IT Thanks, but I explicitly want the mirroring (purge) functionality so that my target doesn't grow with retained obsolete files. – avenmore Sep 9 '20 at 19:46
  • You can use the /purge switch without using the /mir switch as I stated. I suppose my comments were deleted by the mod before you could read. Simply don't use /mir with the other options. Just ping me back if you're interested and I'll share more detail. I'll check back again to see if the comment gets removed before you read. – Drink More Pimp Juice IT Sep 16 '20 at 14:08
2

Is this a shortcoming in Robocopy or a design decision?

It is correct that AVOutlook.pst is newer, but can't copy it, doesn't raise an error, and deletes the older version in the dest.

It is a design decision and is documented:

Robocopy will fail to copy files that are locked by other users or applications, so limiting the number of retries with /R:0 will speed up copying by skipping any in-use files.

Source: Robocopy "Robust File Copy" - Windows CMD - SS64.com

Is there a safer way?

Yes, use VSHADOW or DISKSHADOW:

The Windows Volume Shadow Copy service is the only Windows subsystem that can copy open files. Robocopy does not use the Volume Shadow Copy service, but it can backup a volume shadow that has already been created with VSHADOW or DISKSHADOW.

Source: Robocopy "Robust File Copy" - Windows CMD - SS64.com

doesn't raise an error

It does, and that is also documented (Robocopy uses EXIT CODES):

= New Option in Windows 8 and Windows 10

Robocopy EXIT CODES

Source: Robocopy "Robust File Copy" - Windows CMD - SS64.com

You can check these exit codes and take appropriate action in your batch files.

4
  • Why is the way the file is in use handled differently to the way that, for e.g. NTUSER.DAT, which can't be copied but raises an error. Why does it raise an error on the same outlook.pst file when the /B switch is used (and then doesn't delete the dest)? – avenmore Aug 18 '20 at 17:56
  • @avenmore Because /b is not the same as /mir? – DavidPostill Aug 18 '20 at 17:59
  • Combined, /B /MIR works intuitively - raises an error, doesn't delete matching name in dest, deletes other extras. But the /B option requires Administrator privileges which I want to avoid. – avenmore Aug 18 '20 at 18:18
  • I'll accept this as the answer although I'm still not happy that /MIR can be intentionally dangerous, but I think I've asked too many vague questions and perhaps need to state more clearly with facts why this appears wrong. – avenmore Aug 19 '20 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.