• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5735
  • Last Modified:

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?
0
itmstech
Asked:
itmstech
  • 3
1 Solution
 
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%

hth

Steve
0
 
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
0
 
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
etc.
0
 
SamuraiCrowCommented:
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:

http://www.microsoft.com/downloads/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&displaylang=en

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.

Crow
0
 
Steve KnightIT ConsultancyCommented:
Or maybe at least a split :-)
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now