Search This Blog

Showing posts with label How to cleanup SQL old backup files. Show all posts
Showing posts with label How to cleanup SQL old backup files. Show all posts

How to cleanup SQL old 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