-- 完全备份
-- 注意: 一切都从完全备份开始 DECLARE @Path VARCHAR(1000), @FileName VARCHAR(1000), @WeekDay VARCHAR(20) SET @WeekDay = CASE DATEPART(WEEKDAY, GETDATE()) WHEN 1 THEN '星期天' WHEN 2 THEN '星期一' WHEN 3 THEN '星期二' WHEN 4 THEN '星期三' WHEN 5 THEN '星期四' WHEN 6 THEN '星期五' WHEN 7 THEN '星期六' END
SET @Path = 'D:\BackData\'
SET @FileName = @Path + @WeekDay + '完全备份.BAK' BACKUP DATABASE [TestDB] TO DISK = @FileName WITH INIT ,NOUNLOAD ,NAME = N'TestDB完全备份' ,NOSKIP ,STATS = 10 ,NOFORMAT
-- 差异备份
-- 注意: 在执行差异备份之前, 必须先执行一次成功的数据库完全备份 DECLARE @Path VARCHAR(1000), @WeekDay VARCHAR(20), @FileName VARCHAR(1000), @Hour VARCHAR(4) SET @WeekDay = CASE DATEPART(WEEKDAY, GETDATE()) WHEN 1 THEN '星期天' WHEN 2 THEN '星期一' WHEN 3 THEN '星期二' WHEN 4 THEN '星期三' WHEN 5 THEN '星期四' WHEN 6 THEN '星期五' WHEN 7 THEN '星期六' END SET @Path = 'D:\BackData\' SET @Hour = CONVERT(VARCHAR(2), DATEPART(HOUR, GETDATE())) + '点' SET @FileName = @Path + @WeekDay + @Hour + '差异备份.BAK' BACKUP DATABASE [TestDB] TO DISK = @FileName WITH INIT ,NOUNLOAD ,DIFFERENTIAL ,NAME = N'TestDB差异备份' ,NOSKIP ,STATS = 10 ,NOFORMAT
-- 日志备份
-- 注意: 在进行日志备份之前必须先进行一次成功的数据库完全备份 DECLARE @Path VARCHAR(1000), @WeekDay VARCHAR(20), @FileName VARCHAR(1000), @Hour VARCHAR(4) SET @WeekDay = CASE DATEPART(WEEKDAY, GETDATE()) WHEN 1 THEN '星期天' WHEN 2 THEN '星期一' WHEN 3 THEN '星期二' WHEN 4 THEN '星期三' WHEN 5 THEN '星期四' WHEN 6 THEN '星期五' WHEN 7 THEN '星期六' END SET @Path = 'D:\BackData\' SET @Hour = CONVERT(VARCHAR(2), DATEPART(HOUR, GETDATE())) + '点' SET @FileName = @Path + @WeekDay + @Hour + '日志备份.BAK' BACKUP LOG [TestDB] TO DISK = @FileName WITH INIT ,NOUNLOAD ,NAME = N'TestDB日志备份' ,NOSKIP ,STATS = 10 ,NOFORMAT |
SQL SERVER备份脚本
最新推荐文章于 2024-06-07 11:04:18 发布