我有一个mssql脚本,我想将其用于每日完整备份和日志备份,我无法理解如何添加CHECKSUM值来使其正常工作,任何人都可以帮助我解决这个问题:
DECLARE @name VARCHAR(50) -- database name
DECLARE @path VARCHAR(256) -- path for backup files
DECLARE @fileName VARCHAR(256) -- filename for backup
DECLARE @fileDate VARCHAR(20) -- used for file name
SET @path = 'C:\Backup\'
SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112)
+ '_'
+ REPLACE(CONVERT(VARCHAR(20),GETDATE(),108),':','')
DECLARE db_cursor CURSOR FOR
SELECT name
FROM master.dbo.sysdatabases
WHERE name NOT IN ('master','model','msdb','tempdb')
AND DATABASEPROPERTYEX(name, 'Recovery') IN ('FULL','BULK_LOGGED')
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @name
WHILE @@FETCH_STATUS = 0
BEGIN
SET @fileName = @path + @name + '_' + @fileDate + '.TRN'
BACKUP LOG @name TO DISK = @fileName
FETCH NEXT FROM db_cursor INTO @name
END
CLOSE db_cursor
DEALLOCATE db_cursor
答案 0 :(得分:1)
您的命令应如下所示:
BACKUP LOG @name TO DISK = @fileName with checksum
您可以在以下Enable or Disable Backup Checksums During Backup or Restore (SQL Server)和此处的BACKUP (Transact-SQL)下找到此语法 错误管理选项
答案 1 :(得分:0)
我认为您真正想要的是一个RESTORE VERIFYONLY,它将检查已创建的备份文件的状态。
RESTORE VERIFYONLY FROM DISK = @fileName;