Solved

xcopy command line parameters

Posted on 2003-12-10
16
6,414 Views
Last Modified: 2012-05-04
Below are the xcopy command-line parameters:

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

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.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Lets say that I backup

c:\dir1   to   d:\backup\dir1

I use, practically all of the command-line args...so I do a recursive, all sub directories...etc.

I DO THIS EVERY DAY

Now, lets say that I DELETE c:\dir1\myfiles\documents\not_important.doc

When the xcopy runs, I want the destination (d:\backup\dir1\myfiles\documents\not_important.doc) to be removed...since it no longer exists in the source.

Do I need to write another program (or find another program) to do this?  What do ya'll suggest?

If there is a free program out there that does this, it needs to also copy over the permissions (ACLs etc.).  But I haven't found one.

Thanks IA for any info.



0
Comment
Question by:ramble
  • 6
  • 6
  • 3
  • +1
16 Comments
 
LVL 3

Assisted Solution

by:peter_fleur
peter_fleur earned 250 total points
Comment Utility
We use robocopy for these kind of processes. It copies permissions and it can make mirrors of complete directory structures.
You can find robocopy on the resource kits of microsoft:

http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en

Hope this will answer your question.

Peter
0
 

Author Comment

by:ramble
Comment Utility

This looks like it will work.  I'll work on it today.  robocopy has a command line parameter:
            /PURGE : delete dest files/folders that no longer exist in source.
That appears to be what I'm looking for.

Although it's labeled for 2003 Server, I'm guessing that it will work on 2000
0
 
LVL 3

Expert Comment

by:peter_fleur
Comment Utility
It will work on a Windows 2000 machine. They upgraded the resource kits but the tools are all the same except for some new extra 2003 files. You can also use the /mirror line parameter. I don't really know the difference now but it's described in the /?

Peter
0
 
LVL 37

Expert Comment

by:Bing CISM / CISSP
Comment Utility
quoted from RK's documenation: RoboCopy is a 32-bit Windows command-line application that simplifies the task of maintaining an identical copy of a folder TREE in multiple locations, either on the same computer or in separate network locations. RoboCopy can provide time-efficient maintenance of mirror images of large folder trees on network servers separated by slow or unreliable wide area networks (WANs) links.

RoboCopy can maintain directory TREE, not their content, so i dont think it is what ramble needs.

ramble, it sounds that you need a full content synchronization of folder(s)?
0
 

Author Comment

by:ramble
Comment Utility

Well, I'm going to experiment with it a little.  Initially, it sure looks to me that it does everything xcopy does...but more.  bbao: what makes you think it doesn't maintain their content as well?

http://www.ss64.com/nt/robocopy.html

bbao: you are correct, I'm wanting full content synchronziation as well.  


0
 

Author Comment

by:ramble
Comment Utility

Hey...on that link I posted above...down below called "related links", it looks like scopy might be good.  Sure seems simple to use.  Do you guys have any experience with scopy?

0
 
LVL 3

Expert Comment

by:peter_fleur
Comment Utility
In my experience robocopy does copy content too. It keep the NTFS security too so not only the tree but also the files in it. And you can make a mirror with the /MIR command line function.

Peter
0
 
LVL 37

Expert Comment

by:Bing CISM / CISSP
Comment Utility
scopy is retired, replaced by new version of xcopy of windows 2000.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 37

Expert Comment

by:Bing CISM / CISSP
Comment Utility
peter_fleur, yes, robocopy does copy content too, as well as other *copy utilities do. but what ramble needs is  "full content synchronization of folder(s)", please read above posts.
0
 
LVL 37

Accepted Solution

by:
Bing CISM / CISSP earned 50 total points
Comment Utility
hi folks, i got idea!

try the following commands:

attrib d:\backup\dir1 -a /s
xcopy c:\dir1 d:\backup\dir1 /s /v /e /z
del d:\backup\dir1 /a-a /f /s /q

it does exactly what you want: copy all the source dir and its content to the backup folder, then delete all the files that do not exist at source locations.

btw, i would suggest you use replace.exe to replace xcopy.exe, to prevent copy duplicate files, but be sure you should have right archive attribute set for all files.

hope it helps,
bbao
0
 
LVL 1

Expert Comment

by:notch_ur_head
Comment Utility
hahaha,

then what is the need for the backup if it also deletes the file when it is deleted from the source??

-notch_ur_head
0
 
LVL 37

Expert Comment

by:Bing CISM / CISSP
Comment Utility
yes, it does!
0
 

Author Comment

by:ramble
Comment Utility

notch_ur_head: That's actually what I'm looking for.  Without it, then the the files in the backup (or the overall backup set) would become bloated with time...full of old temporary files that nobody wants anymore.

I have 20 120GB harddrive (firewire & USB 2.0)...so I propagate the backups down the line...eg. D=>E, E=>F,F=G... Then I run a weekly tape backup for archival purposes.

But, thanks to all,  I have plenty of backup info.  I'll probably use robocopy or xxcopy:

robocopy and xxcopy comparison: http://www.xxcopy.com/xxcopy30.htm

bbao: I'm still not sure, maybe I'm being dense, why you don't think robocopy (or xxcopy for that matter) wouldn't work???  It seems to be relatively robust, and the /PURGE or /MIR option appears to do exactly what your script is doing.

Do you mind expanding on that?
0
 
LVL 37

Expert Comment

by:Bing CISM / CISSP
Comment Utility
ramble, just had a try robocopy 1.96 on my machine, yes! it does what my batch does and even better and more. i am wondering why my robocopy /? only shows /mir option, so i did think robocopy does not support those options. in fact, i did not know robocopy before, and nice to learn about such a power tool. anyway, my batch is not bad too, especially when you work on old systems or those without RK installed, hehe ;-)
0
 

Author Comment

by:ramble
Comment Utility

Thanks All!
0
 

Author Comment

by:ramble
Comment Utility
Thanks_ramble

Just Ignore the last comment
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
A safe way to clean winsxs folder from your windows server 2008 R2 editions
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now