sqlserver2008 截断指定时间以前的事务日志的命令。
如题。 想每隔一个月截断上一个月的事务日志。
如:3月底删掉2月整个月的事务日志。
求截断指定时间以前的事务日志的方法。
[解决办法]
试试:
-- use the cursor to delete the expire bak
-- also could not user the cursor if you only want to delete the top 1 oldest bak
-- @filePath : the expire bak's path
declare fileCursor CURSOR for
SELECT * from
(
SELECT TOP 3 b.physical_device_name
FROM [msdb].[dbo].[backupset] a,[msdb].[dbo].[backupmediafamily] b
where a.media_set_id=b.media_set_id and [expiration_date]<GETDATE()
order by [expiration_date] asc
)
as filetable
declare @filePath varchar(100)
open fileCursor
fetch next from fileCursor into @filePath
while @@fetch_status=0
begin
declare @delCmd varchar(100)
set @delCmd =('del '+@filePath)
-- user xp_cmdshell to delete the bak
exec xp_cmdshell @delCmd
fetch next from fileCursor into @filePath
end
close fileCursor
deallocate fileCursor