Solved

xcopy Command

Posted on 2008-10-09
3
1,002 Views
Last Modified: 2010-05-18
I have the attached command (bat file) that I use to backup the entire contents of one drive to another.  However, the way it is currently written, it makes a new copy of every file/folder every time it runs - even if nothing has changed.  That means that it takes forever to run.

What I would really like is for it to:
1) look through every file on the 'D' drive
2) For each of those files, evaluate whether that file was modified since/after the copy that is currently on the 'G' drive.  If so, then re-copy that file onto G, otherwise, do nothing.

Could somebody tell me how to re-write to do such?
echo Begin copy >copyd.txt

date /t >>copyd.txt

time /t >>copyd.txt

echo Copying d:\* to g:\Backup >>copyd.txt

xcopy d:\* g:\Backup\ /y /i /e /v /c /h /o >>copyd.txt 2>&1

echo End copy >>copyd.txt

date /t >>copyd.txt

time /t >>copyd.txt

cls

Open in new window

0
Comment
Question by:timoteoga
3 Comments
 
LVL 3

Accepted Solution

by:
Robbals earned 500 total points
ID: 22681263

xcopy /D copies only files that are newer than the existing files.....
0
 
LVL 38

Expert Comment

by:Shift-3
ID: 22681486
Robocopy is a good tool for this as it is more reliable and has more options than xcopy.  Its default behavior is to skip identical files which already exist in the destination.
http://en.wikipedia.org/wiki/Robocopy
0
 
LVL 16

Expert Comment

by:t0t0
ID: 22723969
Yes... You are almost there....

Just add a /M switch to your XCOPY command. This will reset the file's archive attribute.

The next time you run your batch file, all your files on D: will have their archive attributes turned off but they will still be copied to G:

From then on, every time you run your batch file only those files with their archive attributes set will be copied to G:

So, if any files change on D: for any reason, the system automatically sets the file's archive attribute back on again so that when you run your batch file at a later date, only those files that have actually changed will be copied to G:

Neat eh?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

863 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

24 Experts available now in Live!

Get 1:1 Help Now