Question Locked

Batch Backup

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have created a batch file to backup data to cd on my windows XP machine. It has worked successfully for the past two years, but the programmer of one of the programs (located in the P:\ directory) has changed the internal backup event to create multiple daily backups. This now creates too many files (size) to fit on the cd. I have tried to append my batch to select only files modified today or in the past 2 days, but to no avail. Any help is appreciated.

@ECHO OFF
:START
XCOPY P:\*.* "C:\Documents and Settings\trevord\Local Settings\Application Data\Microsoft\CD Burning" /-Y /H /D /E
COPY F:\datafuel\BACK_U~1\Server\DFDBBA~1.MDB "C:\Documents and Settings\trevord\Local Settings\Application Data\Microsoft\CD Burning" /-Y
COPY F:\works\FLEETM~1\FLEETD~1.MDB "C:\Documents and Settings\trevord\Local Settings\Application Data\Microsoft\CD Burning" /-Y

7 replies

by toivo talikka

A lot depends how you run this script. It should be fine if it is run interactively, especially if you use /-Y which causes it to prompt to confirm before overwriting files.

I have used heaps of similar scripts, but this style instead:

c:
cd \my_backup_folder
xcopy \\servername\?mgmt system folder?\*.* /d /e /q /c

The above script runs either interactively or as a scheduled job.

If your script runs as a scheduled job, you need to change the mapped drive to a UNC notation \\servername\sharename before your script can access the folder.

When you run a scheduled job, you also need to make sure that the username and password are valid. Check the status by going to Scheduled Tasks, click View - Details and what it says under Last Run Time, Status and Last Result.

You may appreciate that there are valid reasons why programmers do the heavy lifting in IT, not CEO/CFO/Partner :-)

by peterr

It is run as a user interactive bacth. My main concern is how to limit the amount of files backed up to those ammended in the last 2 days. I have tried to insert /d:t-2 or /d:(date) for today only, but it does not recognise it. Thanks for your help.

by toivo talikka

Enter the date in the following format and it should work:

/D:01-17-2007

by peterr

Thanks Toivo. Is there any way that I can get the user to enter that date in when running the batch file each day? Maybe a prompt for it in the dos window? Or even get the computer to automatically update it each day? Maybe a comparison to computer clock? Thanks Again

by toivo talikka

Here is how a date can be prompted. It does not validate it, though. Forget the FOR loop but you can see how the date is passed to another script which then refers to it by /D:%1 in the XCOPY parameters:

@echo off
set /P date_in=Enter date mm-dd-yyyy:
@echo date = %date_in%
@echo press Enter to continue
@echo press Ctrl-C to stop the deletion of older files from Archive folders
pause
@echo starting loop
for /F %%i in ('dir /AD /B /S Archive*') do archivesub.cmd %date_in% "%%i"
@echo end of loop

Both scripts were published in 2005:
http://totaldata.biz/techtips/batchfile.html

Calculating even yesterday's date from today's date in a batch file is notoriously difficult, here is one example:

http://www.robvanderwoude.com/datetiment.html#Yesterday

If you want to automate the running of this task further, it is best done in a proper programming language where a couple of lines of code will do the trick. KiXtart is one such language, suited for Windows environment and it is also free. For details, see http://kixtart.org.

by peterr

A little bit of jigging, but it's working a treat. You saved me hours!!! Thanks Toivo.

This discussion is closed to new replies.