代碼如下:
DECLARE @filename VARCHAR(255)
DECLARE @date DATETIME
SELECT @date=GETDATE()
SELECT @filename = 'G:\存放位置\數(shù)據(jù)庫名稱-'+CAST(DATEPART(yyyy,@date) as varchar)+'-'+CAST(DATEPART(mm,@date) as varchar)+'-'+CAST(DATEPART(dd,@date) as varchar)+'.bak'
BACKUP DATABASE [數(shù)據(jù)庫名稱] TO DISK = @filename WITH INIT
GO
DECLARE @OLDDATE DATETIME
SELECT @OLDDATE=GETDATE()-5
EXECUTE master.dbo.xp_delete_file 0,N'G:\存放位置',N'bak',@olddate,1
上面是一個(gè)備份最近5天的數(shù)據(jù)庫作業(yè)腳本。
更多信息請(qǐng)查看IT技術(shù)專欄