0
我們有一項工作,每天晚上運行腳本以在我們所有數據庫上進行完整備份。最近,我們注意到有時會跳過最後兩個數據庫,但不是全部。我們有一個跟蹤表,我們在進行備份時插入每個數據庫的狀態。在最後兩個數據庫被跳過的晚上,這些數據庫的狀態也不會記錄在跟蹤表中。我們無法弄清楚爲什麼會跳過這些數據庫。這是我們所使用的備份腳本:完整備份偶爾會跳過某些數據庫
DECLARE @dbname VARCHAR(100),
@dbid INT,
@rcmodel VARCHAR(50),
@state VARCHAR(60),
@date VARCHAR(50),
@time VARCHAR(50),
@sql VARCHAR(3000),
@dir VARCHAR(1000),
@path VARCHAR(100),
@type VARCHAR(10)
SET @path = 'E:\Backups\'
SET @type = 'Full'
SET @date = REPLACE(CONVERT(date,GETDATE(),101),'-','_')
SET @time = REPLACE(CONVERT(TIME(0), GETDATE()),':','_')
SET @path = @path + CONVERT(VARCHAR(30),@@SERVERNAME) + '\' + @type + '\'
DECLARE BackupCur CURSOR FOR
SELECT NAME, database_id, recovery_model_desc, state_desc
FROM sys.databases
WHERE NAME <> 'tempdb'
OPEN BackupCur
FETCH NEXT FROM BackupCur INTO @dbname, @dbid, @rcmodel, @state
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO backuptrackingtable (db, statedesc, datecreated)
values (@dbname, @state, GETDATE())
IF @type = 'Full' AND @state = 'ONLINE'
BEGIN
SET @dir = 'EXECUTE master.dbo.xp_create_subdir N'''[email protected][email protected]+''''
SET @sql = 'BACKUP DATABASE '[email protected]+' TO DISK = N'''[email protected][email protected]+'\'[email protected]+'_'[email protected]+'.bak'' WITH NOFORMAT, INIT, SKIP, REWIND, NOUNLOAD, COMPRESSION'
PRINT 'Backing up ' + @dbname
EXEC (@dir)
EXEC (@sql)
END
IF @type = 'Log' AND @dbid > 4 AND @rcmodel = 'FULL' AND @state = 'ONLINE'
BEGIN
SET @dir = 'EXECUTE master.dbo.xp_create_subdir N'''[email protected][email protected]+''''
SET @sql = 'BACKUP LOG '[email protected]+' TO DISK = N'''[email protected][email protected]+'\'[email protected]+'_'[email protected]+'__'[email protected]+'.bak'' WITH NOFORMAT, INIT, SKIP, REWIND, NOUNLOAD, COMPRESSION'
PRINT 'Backing up ' + @dbname
EXEC (@dir)
EXEC (@sql)
END
FETCH NEXT FROM BackupCur INTO @dbname, @dbid, @rcmodel, @state
END
CLOSE BackupCur
DEALLOCATE BackupCur
屬於http://dba.stackexchange.com/ – Aaron 2012-01-18 21:12:41