Link to home
Start Free TrialLog in
Avatar of kpurchase

asked on

Create If/then batchfile

We have a simple batch file that uses the xcopy command to backup one of our archives to our backup drive. The archive is very large and so it's takes a long time to run. We run the same batchfile everyday, so it's really a full backup job every time. There are 11 main folders and and a number of subdirectories under each of them. We are looking for a command that looks at the highest folder's modified date on the original archive and only backs it up if it has changed. The command should continue to drill through the folder stuctures only backing up the files that have changed. If the modified date has not changed on the folder we want it to move on. We have tried usiing switches but they still look at every file and compare the dates when it doesn't need to. If the modified date on the folder hasn't changed no files in that folder have changed either. Here is an example of what we are using. This works but we  need a faster way to back it up.

set SOURCEROOT=\\Archive1
set DESTPATH=Databackup\Archive1

Avatar of Frosty555
Flag of Canada image

Note this simple test. The modified date did not change by altering files that were deep in the folder tree. It only takes effect on files directly inside a given folder. Keep that in mind.
This is much easier using Robocopy, which is available as part of the 2003 Resource Kit.  By default it only copies files which have changed.

You could use a command like this:

robocopy "%sourceroot%" "%driveletter%%destpath%Archive1" /E /ZB

Open in new window

Avatar of kpurchase


Thanks for the quick response. I have a few more questions. If I run a batchfile that clears the archive bit on the original archive when someone changes a file deep down in that folders structure will it change the archive bit to set on the top folder, or only on the folder in which this file is directly in? Can robocopy workaround this issue of the top folder date not being modified or would we have the same problem we have now? Do you have any other suggestions for how we could do this?
Modifying a file only changes its archive bit, not those of its parent folders.

However, this shouldn't matter as Robocopy checks both timestamp and size on each individual file when determining whether they've been changed.
The only true way to know if a file has changed since your last backup is to hash the file. Robocopy won't do that because it's overkill. Checking the date/time stamp and file size is usually a good robust way to be 99% sure that the file has or has not changed - that's why RoboCopy does it that way! Archive bits, and modified dates on folders just aren't very reliable.
Avatar of kpurchase

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial