我在SQL 2008中有一项工作,该工作运行存储的proc来备份所有数据库。这每天通过sql server agent作业运行。
它每天都会成功退出,但是有些时候只有备份了一些数据库后才能成功退出。每次可以有不同数量的数据库。大多数情况下,它成功备份了所有数据库,但有时成功备份了2个,有时成功备份了5个,等等。
我在作业历史记录,事件查看器或SQL Server日志中看不到任何错误。
尽管该文件夹是可扩展存储卷上文件夹的“连接”,但备份仍在本地磁盘上进行。
操作系统是Windows 2003 64位,作为运行在Vmware ESXi 5主机上的虚拟机运行Sql Server 2008 Web版64位。
存储过程:
ALTER PROCEDURE [dbo].[backup_all_databases]
@path VARCHAR(255)='c:\backups\'
AS
DECLARE @name VARCHAR(50) -- database name
DECLARE @fileName VARCHAR(256) -- filename for backup
DECLARE @fileDate VARCHAR(20) -- used for file name
DECLARE @dbIsReadOnly sql_variant -- is database read_only?
DECLARE @dbIsOffline sql_variant -- is database offline?
DECLARE db_cursor CURSOR FOR
SELECT name
FROM master.dbo.sysdatabases
WHERE name NOT IN ('tempdb')
AND version > 0 AND version IS NOT NULL
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @name
WHILE @@FETCH_STATUS = 0
BEGIN
SET @fileName = @path + @name + '.bak'
SET @dbIsReadOnly = (SELECT DATABASEPROPERTY(@name, 'IsReadOnly')) -- 1 = Read Only
SET @dbIsOffline = (SELECT DATABASEPROPERTY(@name, 'IsOffline')) -- 1 = Offline
IF (@dbIsReadOnly = 0 OR @dbIsReadOnly IS NULL) AND @dbIsOffline =0
BEGIN
BACKUP DATABASE @name TO DISK = @fileName WITH INIT
WAITFOR DELAY '00:00:20'
END
FETCH NEXT FROM db_cursor INTO @name
END
CLOSE db_cursor
DEALLOCATE db_cursor
有什么建议吗?