SQL backup and history cleanup

Apr 13, 2013 15:21

чтобы не придумывать в следующий раз..

declare @result nvarchar(200)
declare @mmm varchar(2), @mm varchar(2)
declare @ddd varchar(2), @dd varchar(2)

set @mm = cast(datepart(mm, getdate()) as varchar)
set @mmm = case when len(@mm) < 2 then '0'+@mm else @mm end
set @dd = cast(datepart(dd, getdate()) as varchar)
set @ddd = case when len(@dd) < 2 then '0'+@dd else @dd end

select @result = N'C:\temp\rms-backup-' + cast(datepart(yyyy, getdate()) as varchar) + @mmm + @ddd + cast(datepart(hh, getdate()) as varchar) + N'.bak'

BACKUP DATABASE [rms] TO  DISK = @result WITH NOFORMAT, NOINIT,  NAME = N'rms-Full Database Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10

declare @dt nvarchar(50)
set @dt = cast(dateadd(dd, -14, getdate()) as smalldatetime)

EXECUTE master.dbo.xp_delete_file 0,N'C:\temp',N'bak',@dt
GO

ремайндер

Previous post Next post
Up