Link to home
Start Free TrialLog in
Avatar of jmorin1
jmorin1

asked on

XCOPY Switches

I am confused with regard to the switches in xcopy.

I want to copy files from a server to another location.

/s/e[creates subdirectorys and empty subdirectories]
/d [copies files only if the source files are newer than the destination files.

what does /m and /k do?  

I am running the xcopy command as follows and it appears to be copying modified files at the source based on the /d switch.  I want to make sure that I am doing this correctly.  Could I get an explanation on what reseting the archive bit does with /m and /k? Is it resetting a date stamp based on the source file pertaining to when it was last copied or backed up?  Am I way off base?
Avatar of Harisha M G
Harisha M G
Flag of India image

Hi jmorin1,
Copies files and directory trees.

XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W]
                           [/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T] [/U]
                           [/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z]
                           [/EXCLUDE:file1[+file2][+file3]...]

  source       Specifies the file(s) to copy.
  destination  Specifies the location and/or name of new files.
  /A           Copies only files with the archive attribute set,
               doesn't change the attribute.
  /M           Copies only files with the archive attribute set,
               turns off the archive attribute.
  /D:m-d-y     Copies files changed on or after the specified date.
               If no date is given, copies only those files whose
               source time is newer than the destination time.
  /EXCLUDE:file1[+file2][+file3]...
               Specifies a list of files containing strings.  Each string
               should be in a separate line in the files.  When any of the
               strings match any part of the absolute path of the file to be
               copied, that file will be excluded from being copied.  For
               example, specifying a string like \obj\ or .obj will exclude
               all files underneath the directory obj or all files with the
               .obj extension respectively.
  /P           Prompts you before creating each destination file.
  /S           Copies directories and subdirectories except empty ones.
  /E           Copies directories and subdirectories, including empty ones.
               Same as /S /E. May be used to modify /T.
  /V           Verifies each new file.
  /W           Prompts you to press a key before copying.
  /C           Continues copying even if errors occur.
  /I           If destination does not exist and copying more than one file,
               assumes that destination must be a directory.
  /Q           Does not display file names while copying.
  /F           Displays full source and destination file names while copying.
  /L           Displays files that would be copied.
  /G           Allows the copying of encrypted files to destination that does
               not support encryption.
  /H           Copies hidden and system files also.
  /R           Overwrites read-only files.
  /T           Creates directory structure, but does not copy files. Does not
               include empty directories or subdirectories. /T /E includes
               empty directories and subdirectories.
  /U           Copies only files that already exist in destination.
  /K           Copies attributes. Normal Xcopy will reset read-only attributes.
  /N           Copies using the generated short names.
  /O           Copies file ownership and ACL information.
  /X           Copies file audit settings (implies /O).
  /Y           Suppresses prompting to confirm you want to overwrite an
               existing destination file.
  /-Y          Causes prompting to confirm you want to overwrite an
               existing destination file.
  /Z           Copies networked files in restartable mode.

The switch /Y may be preset in the COPYCMD environment variable.
This may be overridden with /-Y on the command line.


Bye
---
Harish
jmorin1,
    You can see whether the archieve bit is set by using
dir /aa
jmorin1,
    In Windows, you can see file attributes by right clicking and going to properties :)
Avatar of jmorin1
jmorin1

ASKER

Let me better explain my dillema.  I have 2 remote workstations that I want to move files from.  Let's call them server1 and workstation1.   I want to copy files from the workstation to the server.  I also want to execute this routine without overwriting files that have remained unchanged and new files.  If I am doing this from a workstation unrelated to the two do I have to map a network drive to both server1 and workstation1?  

Can I write a batch job that maps the drive i.e. [net use] and copies the files and disconnects the mapping upon completion?  

I don't think you require a mapping in the server.
Just a map of server on workstation is suffecient.

You can write batch file also for that.
ASKER CERTIFIED SOLUTION
Avatar of Carlo-Giuliani
Carlo-Giuliani
Flag of Canada image

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
SOLUTION
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

Ooops!   Sorry, there is a big error in what I wrote earlier.  XCOPY does not clear the archive bit be default.  It seems that it only clears the archive bit when using the /M option, and that only copies file with the archive bit set on.   This means you *cannot* combine full and differential copies in the way I suggested.  In fact, it makes the /M and /A options pretty useless, IMHOP.

I would go with ROBOCOPY.  I'm not sure if it's included with Win2K3 server, or if you have to install a server resource kit.
You can download it from http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en

I agree with Carlo-Giuliani.  ROBOCOPY would be the better solution.  I am pretty sure that you have to get it from the Resource Kit.  

I didn't realize that you could use UNC paths with xcopy or robocopy.  Looks like I learned something too.  Thanks!
robocopy is a good choice, however it will fail to copy files that you dont have the permission.
I always use robocopy and scopy in conjunction for all my migration projects.
http://www.xxcopy.com/ is a very good solution (for me at least).

And in XCOPY?

net use Y: \\Workstation1\C$
net use Z: \\Server1\C$
XCOPY /D /E /C /I /H /Y Y: Z:
net use Y: /del
net use Z: /del

I think you can do this with UNC naming as well. But I think that would require quotes around the name.
Hi;

I think if you want to 'mirror' your drives your answer is ROBOCOPY.  You can download Robocopy from the location provided by Carlo.
Simply create 2 shares (source, destination) and a batch file. Schedule your batchfile and ensure ROBOCOPY is reachable (either in same directory or in your path directories such as C:\winnt\system32)

The command you might want to use is:

robocopy \\workstation\share \\server\share /E /Z /MIR /R:10 /W:90 /ETA /LOG+:AppendLog.log

This will MIRROR your files from the Workstation to the Share.  Files deleted on the WS are also being deleted on the Server, it will copy empty and full subdirs, in restartable mode and if the connection drops it will wait 90 seconds before retry. It does that max. 10 times. ETA is the Estimated time of Arrival, can be replaces by /NP (No Progress).  /LOG+: is creating a log and appending to exsting log.  You could make it more dynamic of course by using  a log per day using a variable.

If you do robocopy /??? you will get a very detailed help.  You can for example set Attiributes and check for them, so rather then using mirror you will check for that. Also you can use /SEC to copy the security information (both source / dest must be NTFS).

Let me know your results.

split, based on best answers according to page expert?  As in my opinion posting a xcopy /? output is not very helpful if the person asks for clarification.
BTW. The newest version of robocopy is found in the Windows 2003 RK-Tools Kit.
It's available on: http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&DisplayLang=en

This version is (for as far as I've tested) running under Windows 2000, but has some new options which might be useful.

One thing: I could't extract the rktools pack completely under W2K, so I used a WXP machine for that. After that, no problem on using the Tools.
OOPS...location already posted...SMART.