Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: Deleting old archive logs in NT (long with scripts)
Hi,
Later versions of forfiles (eg version 1.4) allow either the DDMMYYYY format (note the 4 digit year) or using a DD format for an interval.
Note that it is possible to get a DDMMYY value into an environment variable using the for command, eg:
for /f "tokens=2-4 delims=/ " %i in ('date/t') do set filedate=%i%j%k
To use this in a batch file use double percent signs
Below is a reply I have sent before outlining some other ways to do this:
The forfiles.exe program that comes with the NT Resource kit will allow you to do this, and can be made more user friendly by writing a "wrapper" bat file that just accepts (say) filespec and number of days. This is what I use.
The forfiles bat file can be obtained from http://www.ipass.net/~davesisk/oont_download.htm
There are also shareware / freeware programs that do delete on a time basis - eg delold from http://www.savilltech.com/delold/
Other users have previously suggested a cascading dir tree eg each day move files in dir day1 to day2, day2 to day3, .... and finally delete the files from the bottom most directory.
Or you can use a 3d-party shell, such as "Take Command/32" (http://www.jpsoft.com/) which WILL accept commands doing what you want (i.e. del c:\archivedest\*.* [d09-15-98, +3] which would delete all files from Sept15-Sept18). This has been reported by Oracle on Metalink to work well with the NT scheduler but I haven't used it. It is stated to coexist with the native CMD.EXE shell.
You can also use SQL Plus to spool out the required commands by querying the appropriate data dictionary tables.
--- An example wrapper script for forfiles would be @echo off rem PURPOSE rem delete_oldfiles.bat rem deletes files greater than or equal to x days old rem Note - directories are not deleted. rem does not delete read only, hidden or system files rem 18-Apr-2000 , Bruce Reardon : Creation. rem USEAGE rem Parameters - %1 = path , %2 = file mask , rem %3 = how many days old , %4 (optional) - recurse rem ASSUMPTIONS rem none. rem REQUIRES rem forfiles.exe - distributed with NT Resource kit rem that forfiles.exe be located at c:\nt4reskit rem SIDE EFFECTS rem envdelold env variable will be overwritten and deleted if it exists. rem MODIFICATIONSReceived on Wed Nov 22 2000 - 15:55:55 CST
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
rem Parameter validation. IF "%3"=="" goto param_problem :: not enough params IF NOT "%5"=="" goto param_problem :: too many params rem check parameter 3 is a valid number set envdelold= IF "%3"=="0" goto param3_ok set /a envdelold = 1*%3 2> nul: IF "%envdelold%"=="0" goto param3_problem IF "%envdelold%"=="" goto param3_problem
:param3_ok
IF NOT "%4"=="" IF NOT "%4"=="-s" goto param4_problem :: invalid param 4 IF NOT EXIST %1. goto param1_problem rem we now have 3 (possibly 4) parameters and they have been validated. echo %1 %2 %3 %4 rem the actual command - put quotes around to allow for names with spaces. c:\nt4reskit\forfiles -p%1 -m%2 %4 -d-%3 -c"cmd /c if @ISDIR==FALSE del 0x22_at_FILE0x22" goto end
:param_problem
echo %0 echo ERROR - Must pass in 3 parameters (4 max) echo Param 1 is the path echo Param 2 is file mask echo Param 3 is number of days echo Param 4 (optional) : if "-s" then recurse subdir's. echo. echo eg "%0 c:\temp *.* 5" would delete ALL files in c:\temp directory 5 or more days old goto end
:param1_problem
echo "%0 [-->[%1]<--] %2 %3 %4" echo ERROR - 1st parameter invalid echo Param 1 is the path and it must exist. echo. echo eg "%0 c:\temp *.* 5" would delete ALL files echo in c:\temp directory 5 or more days old goto end
:param3_problem
echo "%0 %1 %2 [-->[%3]<--] %4" echo ERROR - 3rd parameter invalid echo Param 3 is the number of days and it must be a valid number echo. echo eg "%0 c:\temp *.* 5" would delete ALL files echo in c:\temp directory 5 or more days old goto end
:param4_problem
echo "%0 %1 %2 %3 [-->[%4]<--]" echo ERROR - 4th parameter invalid echo Param 4 (optional) : must be "-s" (to recurse subdir's) or be blank. echo. echo eg "%0 c:\temp *.* 5 -s" would delete ALL files echo in c:\temp directory (incl subdirs) 5 or more days old goto end
:end
rem - batch file finished set envdelold= Regards, Bruce Reardon mailto:bruce.reardon_at_comalco.riotinto.com.au -----Original Message----- From: Guidry, Chris [mailto:chris.guidry_at_atcoelectric.com] Sent: Thursday, 23 November 2000 4:16 Hello, In the NT resource kit there is a utility called FORFILES.EXE which may be of some help. I have also seen it as freeware on the web. If you can get a DDMMYY format using DATE /T you've got it made. Please share it with the group if you succeed. HTH C:\>forfiles /? Batch processing of files in a directory or tree. emmanubo_at_microsoft.com FORFILES [-pPath] [-mSearch Mask] [-ccommand] [-dDDMMYY] [-s] [-?] -pPath Path where to start searching -mSearch Mask Search files according to <Search Mask> -cCommand Command to execute on each file(s) -dDDMMYY Select file with date>=DDMMYY -v Verbose mode -s Recurse into sub-directories -? Display this usage screen The following variables can be used in Command : @FILE, @PATH, @RELPATH