BACKUP DATABASE异常终止

时间:2013-02-25 09:37:16

标签: stored-procedures sql-server-2008-r2 backup

我有一个存储过程,它为特定数据库执行数据库备份,如下所示:

 ALTER PROC [dbo].[SP_Backup]
    @DataBaseName NVARCHAR(500) = NULL 
    @fullPath NVARCHAR(500) OUTPUT
AS 
    BEGIN
        DECLARE @dbpath NVARCHAR(500);
            SELECT  @DataBaseName = DB_NAME()
            SELECT  @dbpath = physical_name
            FROM    sys.database_files
            WHERE   ( name = N'myDb' );
            SELECT  @fullPath = SUBSTRING(@dbpath, 0,
                                LEN(@dbpath) - CHARINDEX('\',
                                REVERSE(@dbpath)
                                + '\') + 1);
            SELECT  @fullPath = @fullPath + N'\Backups\' + @DataBaseName + N'.bak'
            BACKUP DATABASE @DataBaseName
        TO DISK = @fullPath;
    END;

问题是,它确实可以在一台服务器上运行,而不能在另一台服务器上运行(服务器在同一台机器上.-- sql 2008 r2)。我得到异常“BACKUP DATABASE正在异常终止。”

备份文件夹具有相同的权限设置,如下所示:

C:\Program Files\Microsoft SQL Server\MSSQL10_50.Server1\MSSQL\DATA\Backup
C:\Program Files\Microsoft SQL Server\MSSQL10_50.Server2\MSSQL\DATA\Backup

和sql用户也一样;

在日志文件中有以下信息:

Error: 18204, Severity: 16, State: 1.
BackupDiskFile::CreateMedia: Backup device 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.Server2\MSSQL\DATA\Backups\myDb.bak' failed to create. Operating system error 3(failed to retrieve text for this error. Reason: 1815).
Error: 3041, Severity: 16, State: 1.
BACKUP failed to complete the command BACKUP DATABASE myDb. Check the backup application log for detailed messages.

可能是什么原因?

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

这是创建文件夹的问题。

SELECT  @fullPath = @fullPath + N'\Backups\' + @DataBaseName + N'.bak'

server1有“Backups”文件夹,sql可以保存备份,但是server2上没有这个文件夹