Solved

xcopy Command

Posted on 2008-10-09
3
1,022 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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