Back to Scripting | Daily Deletion/Compession of Archive Logs by Age
ORACLE archived redo logs are written to the archive log destination by the ORACLE instance, but are never deleted by ORACLE. If the archive log destination becomes full, the database will halt (disallowing further transactions and even logons) until the condition is corrected. The script below will delete archive logs that are three or more days old, and compress archive logs that are one or more days old. The script uses the FORFILES command (see the download page to obtain an updated version) to perform the file selection by age, and the COMPACT command (included with the NT Resource Kit) to perform NTFS compression. A generally accepted approach is to get two backups of each archive log before deleting it from disk, so adjust the age selection parameter based upon your organization's backup schedule.
ManageArchives.cmdREM Record an event to the NT Event Log LOGEVENT -S I "Oracle MANAGE ARCHIVES job started" REM Start a new job log DATE /T > D:\Scheduled\JobLogs\ManageArchives.log ECHO ******************************************************** >> D:\Scheduled\JobLogs\ManageArchives.log ECHO *** The following files will be DELETED *** >> D:\Scheduled\JobLogs\ManageArchives.log ECHO ******************************************************** >> D:\Scheduled\JobLogs\ManageArchives.log ECHO DATE FILE SIZE >> D:\Scheduled\JobLogs\ManageArchives.log ECHO -------------------------------------------------------- >> D:\Scheduled\JobLogs\ManageArchives.log REM Add a listing of the files that will be deleted to the job log FORFILES -Pk:\orant\archive -Marc*.* -D-3 -C"CMD /C Echo @FDATE @PATH\@FILE @FSIZE >> d:\Scheduled\JobLogs\ManageArchives.log" REM Delete archive logs that are D days old FORFILES -Pk:\orant\archive -Marc*.* -D-3 -C"CMD /C DEL @FILE" REM Add a finished message to the job log ECHO -------------------------------------------------------- >> D:\Scheduled\JobLogs\ManageArchives.log ECHO *** File DELETION finished >> D:\Scheduled\JobLogs\ManageArchives.log ECHO *** File COMPRESSION started >> D:\Scheduled\JobLogs\ManageArchives.log REM Perform NTFS compression on archive logs 1 day old or older FORFILES -Pk:\orant\archive -Marc*.* -D-1 -C"CMD /C COMPACT /C @FILE" ECHO *** File COMPRESSION finished >> D:\Scheduled\JobLogs\ManageArchives.log REM Record an event to the NT Event Log LOGEVENT -S I "Oracle MANAGE ARCHIVES job finished" REM Done EXIT
Adding this job to the schedulerAT 10:00PM /EVERY:M,T,W,Th,F,S,Su "D:\Scheduled\ManageArchives.cmd"