?
Solved

xcopy Command

Posted on 2008-10-09
3
Medium Priority
?
1,035 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Accepted Solution

by:
Robbals earned 2000 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 learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

762 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