Link to home
Start Free TrialLog in
Avatar of itmstech
itmstech

asked on

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?
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

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%

hth

Steve
Avatar of itmstech
itmstech

ASKER

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
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
etc.
ASKER CERTIFIED SOLUTION
Avatar of SamuraiCrow
SamuraiCrow

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or maybe at least a split :-)