Show pageOld revisionsBacklinksExport to PDFFold/unfold allBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== pears.DeleteOldDatabaseLogs ====== <WRAP center round info> Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace. </WRAP> ===== Original SQL ===== <code sql> COMMENT TO PRESERVE FORMAT ON PROCEDURE "pears"."DeleteOldDatabaseLogs" IS 'create function DeleteOldDatabaseLogs /* Application Maintained Function / Procedure - DO NOT EDIT*/ ( in @DaysToKeep smallint ) returns smallint begin --Deletes all files log files with pattern 000000AA.LOG in current log folder over a given age. Read only flags are ignored. declare @Command char(250); declare @Count smallint; declare @LogFilePathName char(250); declare @LogPath char(250); set @LogFilePathName = db_property(''LogName''); set @LogPath = "left"(@LogFilePathName,locate(@LogFilePathName,''\\\\'',-1)-1); set @Count = 0; for DeleteLoop as DeleteCursor no scroll cursor for select file_path as DeleteLogFilePathName from sp_list_directory(@LogPath) where file_type = ''F'' and upper("right"(file_path,length(file_path)-locate(file_path,''\\\\'',-1))) regexp ''^[[:digit:]]{6}[[:alnum:]]{2}\\\\.LOG$'' and modified_date_time < dateadd(day,(@DaysToKeep*-1),current date) and file_path <> @LogFilePathName for read only do set @Command = string(''DEL /F "'',DeleteLogFilePathName,''"''); call xp_cmdshell(@Command,''no_output)''); set @Count = @Count+1 end for; return @Count end' </code> database/procedures/pears_deleteolddatabaselogs.txt Last modified: 2026/08/07 19:24by 127.0.0.1