0

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

 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)。我得到异常“备份数据库异常终止。”

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

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.

这可能是什么原因?

4

2 回答 2

0

这是创建文件夹的问题。

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

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

于 2013-02-26T08:14:50.853 回答
0

您可以尝试检查实例。

http://community.spiceworks.com/topic/157143-sql-server-2008-r2-multiple-instances-on-one-server

于 2013-02-25T09:41:52.843 回答