SQL服务器完全备份作业正在跳过数据库

时间:2013-10-10 16:54:57

标签: sql-server-2008 database-backups

我的SQL服务器上运行了一个月工作。

  • 它将所有在线数据库备份到“\ Backupserver \ e $ \ MonthEndBackups \”的位置。

  • Job在下面运行USP:exec [usp_dba_BackupDatabases] 3 (http://screencast.com/t/l7IS5TZK

  • 它在每个月的最后一天运行。

我们的数据库分散在多台服务器上,这项工作在这些服务器上运行,而且过去一直有效。

我们在同一台服务器(同一个SQL实例)上整合了所有数据库,这个作业似乎没有备份所有数据库。我不知道为什么?我的工作有失败的通知(电子邮件),也写入日志文件。

http://screencast.com/t/8ioTZdqEMg9x http://screencast.com/t/VI3d4GLBTGoX

但没有任何失败,因此日志上没有任何内容,也没有显示电子邮件通知。

我知道它不起作用,因为我没有看到文件夹中的完整备份。

这是日程安排:

http://screencast.com/t/waeGwLSa

可能出现什么问题?我没有在数据库中看到任何未备份的模式。有更大的数据库正在备份。

有人能想到为什么会发生这种情况吗?有什么方法可以解决这个问题吗?

USE [DBA]
GO

/****** Object:  StoredProcedure [dbo].[usp_dba_BackupDatabases]    Script Date: 10/01/2013 11:10:26 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[usp_dba_BackupDatabases] 
    @pBackupType        SMALLINT
    ,@pDatabaseName     sysname = NULL

AS



SET NOCOUNT ON


DECLARE @vDatabase sysname, @sql VARCHAR(MAX), @vBackupFileFullPath VARCHAR(MAX)

DECLARE c CURSOR FOR 
SELECT  name FROM sys.sysdatabases
WHERE name NOT IN('tempdb', 'model')
    AND DATABASEPROPERTYEX (name,'STATUS') IN( 'ONLINE')
    AND (name  = @pDatabaseName OR @pDatabaseName IS NULL)

OPEN c
FETCH NEXT FROM c INTO @vDatabase
WHILE @@FETCH_STATUS = 0 
BEGIN

SELECT CONVERT(VARCHAR,GETDATE(),121)
    PRINT '|-->' + CONVERT(VARCHAR,GETDATE(),121) +' Backup Start for database ' + @vDatabase 

    IF @pBackupType = 1
        BEGIN
            SET @vBackupFileFullPath = '\\Backupserver\d$\' + @@SERVERNAME +'\' + @vDatabase +'_DB_'
                +REPLACE(REPLACE(REPLACE(CONVERT(VARCHAR(16),GETDATE(),112),'-',''),' ',''),':','') +'.bak'
            SET @sql  = 'BACKUP DATABASE ' + @vDatabase + ' TO  DISK = N' + CHAR(39) + @vBackupFileFullPath +  char(39) 
            + ' WITH FORMAT, INIT,  NAME = N' + CHAR(39) + @vDatabase + ' -Full Database Backup' + CHAR(39) + ', SKIP, NOREWIND, NOUNLOAD,  STATS = 5, CHECKSUM'
        END


    IF @pBackupType = 2
        BEGIN
            SET @vBackupFileFullPath = '\\Backupserver\d$\' + @@SERVERNAME + '\Differential\' + @vDatabase +'_Diff_'
                 +REPLACE(REPLACE(REPLACE(CONVERT(VARCHAR(16),GETDATE(),121),'-',''),' ',''),':','') +'.bak'        
            SET @sql  = 'BACKUP DATABASE ' + @vDatabase + ' TO  DISK = N' + CHAR(39) +  @vBackupFileFullPath + char(39)
                 + ' WITH DIFFERENTIAL , FORMAT, INIT, NAME = N' + CHAR(39) + @vDatabase 
                                + ' -Differential Database Backup' + CHAR(39) + ', SKIP, NOREWIND, NOUNLOAD,  STATS = 5, CHECKSUM'              
        END

    IF @pBackupType = 3
        BEGIN
            SET @vBackupFileFullPath = '\\Backupserver\e$\MonthEndBackups\' + @@SERVERNAME +'_'+ @vDatabase +'_db.bak'
            SET @sql  = 'BACKUP DATABASE ' + @vDatabase + ' TO  DISK = N' + CHAR(39) + @vBackupFileFullPath  + char(39) 
                + ' WITH COPY_ONLY, FORMAT, INIT,  NAME = N' + CHAR(39) + @vDatabase + ' -Full Month End Database Backup' + CHAR(39) + ', SKIP, NOREWIND, NOUNLOAD,  STATS = 5, CHECKSUM'           
        END

    PRINT ' |'+ @sql  
    EXEC (@sql )


    --VERIFY BACKUP

    IF @pBackupType = 1
        SET @sql  = 'RESTORE VERIFYONLY FROM DISK = N' + CHAR(39) + @vBackupFileFullPath +  char(39) 
                    + ' WITH  FILE = 1,  NOUNLOAD,  NOREWIND'

    IF @pBackupType = 2
        SET @sql  = 'RESTORE VERIFYONLY FROM DISK = N' + CHAR(39) + @vBackupFileFullPath + char(39)
                 + ' WITH  FILE = 1,  NOUNLOAD,  NOREWIND'

    IF @pBackupType = 3
        SET @sql  = 'RESTORE VERIFYONLY FROM DISK = N' + CHAR(39) + @vBackupFileFullPath + char(39) 
                    + ' WITH  FILE = 1,  NOUNLOAD,  NOREWIND'

    --PRINT '   |'+ @sql  
    --EXEC (@sql )



    PRINT '|-->' + CONVERT(VARCHAR,GETDATE(),121) +' Backup Complete for database ' + @vDatabase 
    PRINT '' 

    FETCH NEXT FROM c INTO @vDatabase
END

CLOSE c
DEALLOCATE c



GO

1 个答案:

答案 0 :(得分:2)

尝试使用以下选项(修复可能会破坏当前循环和also break sp_MSforeachdb的选项,因为我已记录herehere以及corrected here) :

DECLARE c CURSOR LOCAL FAST_FORWARD FOR
-----------------^^^^^^^^^^^^^^^^^^

...

WHILE @@FETCH_STATUS <> -1
---------------------^^^^^

另外,please, please, please stop declaring VARCHAR without length