Tuesday, February 28, 2012

How to get cleanup old sql backup files

If you want to keep last 7 days sql backups files only there here you go

declare @cDate varchar(20)
select  @cdate =   LEFT( CONVERT(nvarchar(30), (GETDATE()-7), 126),10) -- make sure -7 days
--print @cDate
execute master.dbo.xp_delete_file 0,N'\\mssql\backups\',N'bak',@cdate

No comments: