Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help with bat file, would like to delete data 90 days or older.

Status
Not open for further replies.

blade10

IS-IT--Management
Feb 2, 2008
144
US
Hello-

I have a script (bat file, sorry its not vbscript) that copies specific db's from a server to a Snapdrive volume. the script works great but now my manager would the script to continue doing as it is BUT also to delete anything older than 90 days on that directory.

the script is run locally on the server that contains the db's and backs them up to this snapdrive location..

Can anyone help me get started with the logic behind checking the creation dates for files on that directory and if older than 90 days, delete it?

I have a slightly scrubbed version here:

@echo off
REM ****************************************************************************
REM ********* Database backup script **************************
REM ********* updated ***************************************************

REM --- Calculate date for folder date stamp
for /F "tokens=2-4 delims=/- " %%A in ('date/T') do set DATE=%%C%%A%%B
net use s: \\snapserver\dbdirectory /user:snapserver\dbdirectory Password
echo. >> "s:\backup.log"

REM ************ MAIN **********************************************************

date /t >> "s:\backup.log"
time /t >> "s:\backup.log"
REM backup files
net stop service >> "s:\backup.log"
cd "%programfiles%\nortel networks\dbdirectory\share\"
call csbackup.bat "c:\dbdirectory\%DATE%" >> "s:\dbdirectorybackup.log"
REM --- Echo date to log file, make directory, copy files from server
mkdir "s:\%DATE%" >> "s:\dbdirectorybackup.log"
xcopy "c:\dbdirectory\%DATE%\*.*" "s:\%DATE%" /s /e /v /R /Y >> "s:\dbdirectorybackup.log"
net start service >> "s:\dbdirectorybackup.log"
IF EXIST "s:\%DATE%\*" (rmdir /s /q "c:\dbdirectory\%DATE%" >> "s:\dbdirectory.log" ) ELSE (goto :ERRORMSG)
net use s: /del
goto :EOF

:ERRORMSG
echo Could not verify copied database files... >> "s:\dbdirectorybackup.log"
net use s: /del
goto :EOF

:EOF

thank you for any information..
 
Take a look at my CleanBadMail script in this FAQ: faq955-6503.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Thank you markdmac,

It will be useful, I'll try the snippets I'll need and get back to you

blade
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top