I have read that Robocopy does not replace existing files (even if different) in the destination. But I can't find a Command Line switch for that. Is it enabled by default?
Windows – Does Robocopy SKIP copying existing files
robocopywindows
Related Solutions
The short answer is that when robocopy
is copying these folders from one server to another, I suspect that it is seeing the timestamps differently than you expect, so it is deciding that the existing files on the destination are older than the same files on the source. This could be due to differences in the time/timezone/DST settings on the two machines.
When robocopy
analyzes the files before copying, it classifies each file into one of these classes:
Lonely files: exist on source but not destination.
Newer files: have Newer timestamp on source, (size and attributes: N/A).
Older files: have Older timestamp on source, (size and attributes: N/A).
Changed files: have same timestamp, but different size (attributes: N/A).
Same files: have same timestamp, size, and attributes.
Tweaked files: have same timestamp and size, but different attributes.
Extra files: exist on destination but not source.
Mismatched: is a file on one, and a directory on the other, in source
and destination.
By default (and with the command line options you have given), robocopy
will copy Lonely
, Newer
, and Changed
files. Files in the other classes will not be copied, and will either be simply reported in the output and/or log, or completly ignored.
If robocopy
is copying a file and overwriting an existing file on the destination, then robocopy
thinks that either the timestamo of the source file is before (Newer
) the timestamp of the destination file, or the file sizes are different (Changed
).
In order to tell exactly what's happening to each file, you could run robocopy
with the "/L"
and "/V"
command line options. Using the "/L"
options tells robocopy
to not do any actual copying, and only list what would otherwise be copied. Using the "/V"
options tells robocopy
to to provide Verbose details.
This will show why robocopy
has decided to copy (and skip) each file. So, for example using robocopy
to copy an example fileset.
Here is a listing of the files:
Directory of C:\folder1
02/28/2014 12:48 PM 327 File1.txt
02/28/2014 02:03 PM 333 File2.txt
2 File(s) 660 bytes
Directory of C:\folder2
02/28/2014 12:43 PM 327 File1.txt
02/28/2014 02:03 PM 327 File2.txt
2 File(s) 654 bytes
In this example, the files named File1.txt
, are the same size in the source and destination folders, but has a Newer
timestamp in Folder1
. And, the files named File2.txt
, have the same timestamp in the source and destination folders, but have different (Changed
) file sizes.
Running robocopy
to copy Folder1
to Folder2
, with the "/L"
and "/V"
command line options looks like this.
C:\>robocopy "C:folder1" "c:folder2" /E /L /V
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Fri Feb 28 21:07:29 2014
Source : C:\folder1\
Dest : C:\folder2\
Files : *.*
Options : *.* /V /L /S /E /COPY:DAT /R:1000000 /W:30
------------------------------------------------------------------------------
2 C:\folder1\
Newer 327 File1.txt
Changed 333 File2.txt
------------------------------------------------------------------------------
Total Copied Skipped Mismatch FAILED Extras
Dirs : 1 0 1 0 0 0
Files : 2 2 0 0 0 0
Bytes : 660 660 0 0 0 0
Times : 0:00:00 0:00:00 0:00:00 0:00:00
Ended : Fri Feb 28 21:07:29 2014
If you run robocopy
with the "/L"
and "/V"
command line options on your set of files, it should give you the information of why robocopy
is unexpectedly copying these files.
I suspect that robocopy
is seeing the timestamps differently than you expect, and is deciding that the files on the source are Newer
than the same existing files on the destination. This could be due to differences in the time/timezone/DST settings on the two machines.
Windows – Copy all files, skip those already existing, and delete those in destination not in source
I'd use something like this:
robocopy <Source> <Destination> /E /COPY:DAT /XO /PURGE /R:1 /W:1
From robocopy's help:
/PURGE :: delete dest files/dirs that no longer exist in source.
/XO :: eXclude Older files.
Best Answer
Only if you explicitly ask it to.
The help says:
As you can see in the /X area, there are multiple options that can support your demand:
depending on what exactly you want -
/XC
excludes all changed files, for example.