Merging or Copying data using Xcopy or Robocopy

I need to copy/merge data from c:\ to d:\ however it is possible that their are duplicate files, what are the switches i need to use to make sure that the copy program only keeps/copies the newer version of the file?
Who is Participating?
SamuraiCrowConnect With a Mentor Commented:
Here is the robocopy syntax:

robocopy "source" "destination" *.* /E /Copyall /R:1 /W:1 /IS

If you need to download it you can get it in the 2003 Resource Kit:

I've been a big robocopy fan since the NT4 days.  This syntax won't overwrite newer copies and will maintain the NTFS permissions.

Hope this helps.

Steve KnightIT ConsultancyCommented:
As long as the filenames are the same xcopy /d copies only newer files.  I tend to runit with

xcopy /d/e/h/r/k/o/y

which copies newer files in subdirectories (inc empty), hidden files, overwrites read only files, copies attibutes, acl & ownership and doesn't prompt to overwrite.

Robocopy with /MIR amongst other options will synchronise the dest from source (inc. deleting files that have been deleted from source which xcopy can't do).

Again I use:

/MIR - copy all files and subdirectories and remove files from dest. not in source
/R:2 - 2 retry for failed copies
/W:10 - Wait time 10 seconds between retries
/TEE - write output to log file and screen
/LOG+: - append output to filename
/NP - No Progress percentage as this messes up log file
/NJH - No Job header in log file

SET logfile=c:\backups\logs\backup.log
SET source=\\server\share
SET dest=C:\backups\server
SET filespec=*.zip
SET options=/MIR /R:2 /W:10 /TEE /LOG+:%LOGFILE% /NP /NJH

robocopy %source% %destination% %filespec% %options%


itmstechAuthor Commented:
Ok, I understand the commands and switches as I have been researching them and also testing. However, I have a slight problem. The files that exist in my destination directory are from a restore I did today which means that most if not everything has today's date there fore the /d:07-04-2006 switch I want to use with Xcopy is showing me 0 files to move because everything in the source is technically older than what is in my destination because of the restore.

however, I ran the following command: xcopy c:\data d:\restore /c /f /d:07-04-2006 /e /k /r /o /x and it copied the 437 files that changed out of the 125,000 that existed in the source.  However it also created the entire folder structure again.  I am afraid that if i now xcopy the data from the restore folder to my d:\ that I will overwrite folders that have data with folders that have nothing in it.

How to merge then? Ugggggg
Steve KnightIT ConsultancyCommented:
OK so is your merge problem that files are missing from the source folder which you are trying to put back from a restored folder? in which case, xcopy all the files from C: ignoring the /D option and it will overwrite any files on D: but any additional files will of course remain.  Doing it with robocopy /MIR would of course delete them.

xcopy will never delete any file or overwrite a full directory with a blank one - it will always copy over the top.

For a one off you could always just use explorer to do the copy.

Can you clarify for me which directories are the problem, I.e.

a : incomplete
b : complete but restored version
Steve KnightIT ConsultancyCommented:
Or maybe at least a split :-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.