SQL Server 2012复制数据库失败


10

我想在同一SqlServer中复制数据库。因此,当我使用“复制数据库向导”时,它会引发错误:(我使用测试数据库执行了此步骤,并且工作正常!!!)

配置:

一个用户

方法:“使用SQL管理对象方法”

选择目标数据库的新名称。

错误:

标题:复制数据库向导

作业失败。检查目标服务器上的事件日志以获取详细信息。

- - - - - - - - - - - - - - - 纽扣:

在事件日志中:

  • 系统

    • 提供者

    [名称] SQLSERVERAGENT

    • 事件ID 208

    [资格赛] 16384 3级任务3关键字0x80000000000000

    • 创建时间

    [SystemTime] 2014-05-07T06:23:11.000000000Z EventRecordID 123672频道应用程序计算机Server1安全

  • 事件数据

    CDW_Server1_Server1_3 0x666DE807F406D7438C65B09171211D7B
    失败2014-05-07 10:52:50作业失败。作业由用户sa调用。运行的最后一步是步骤1(CDW_Server1_Server1_3_Step)。

日志文件的最后几行:

OnProgress,Server1,NT Service \ SQLSERVERAGENT,Server1_Server1_Transfer Objects Task,{066BD090-26F3-45D8-AD60-B207D56D44CE},{1CF7B713-F747-45FB-8936-5522651E0C7A},5/7/2014 10:08:46 AM,5 / 7/2014 10:08:46 AM,0,0x,1个数据库的数据库传输失败。OnProgress,Server1,NT Service \ SQLSERVERAGENT,Server1_Server1_Transfer Objects Task,{066BD090-26F3-45D8-AD60-B207D56D44CE},{1CF7B713-F747-45FB-8936-5522651E0C7A},5/7/2014 10:08:46 AM,5 / 7/2014 10:08:46 AM,100,0x,传输对象完成执行。OnTaskFailed,Server1,NT Service \ SQLSERVERAGENT,Server1_Server1_Transfer Objects Task,{066BD090-26F3-45D8-AD60-B207D56D44CE},{1CF7B713-F747-45FB-8936-5522651E0C7A},5/7/2014 10:08:46 AM,5 / 7/2014 10:08:46 AM,0,0x,(null)OnPostExecute,Server1,NT Service \ SQLSERVERAGENT,Server1_Server1_Transfer Objects Task,{066BD090-26F3-45D8-AD60-B207D56D44CE},{1CF7B713-F747-45FB-8936-5522651E0C7A},5/7/2014 10:08:46 AM,5/7/2014 10:08:46 AM,0, 0x,(null)OnWarning,Server1,NT Service \ SQLSERVERAGENT,CDW_Server1_Server1_1,{45A6144C-8DDD-49A6-A6BA-AE81E24826D5},{1CF7B713-F747-45FB-8936-5522651E0C7A},5/7/2014 10:08:46 AM,5/7/2014 10:08:46 AM,-2147381246,0x,SSIS警告代码DTS_W_MAXIMUMERRORCOUNTREACHED。执行方法成功,但是引发的错误数(1)达到允许的最大值(1);导致失败。当错误数量达到MaximumErrorCount中指定的数量时,就会发生这种情况。更改MaximumErrorCount或修复错误。{45A6144C-8DDD-49A6-A6BA-AE81E24826D5},{1CF7B713-F747-45FB-8936-5522651E0C7A},5/7/2014 10:08:46 AM,5/7/2014 10:08:46 AM,-2147381246 ,0x,SSIS警告代码DTS_W_MAXIMUMERRORCOUNTREACHED。执行方法成功,但是引发的错误数(1)达到允许的最大值(1);导致失败。当错误数量达到MaximumErrorCount中指定的数量时,就会发生这种情况。更改MaximumErrorCount或修复错误。{45A6144C-8DDD-49A6-A6BA-AE81E24826D5},{1CF7B713-F747-45FB-8936-5522651E0C7A},5/7/2014 10:08:46 AM,5/7/2014 10:08:46 AM,-2147381246 ,0x,SSIS警告代码DTS_W_MAXIMUMERRORCOUNTREACHED。执行方法成功,但是引发的错误数(1)达到允许的最大值(1);导致失败。当错误数量达到MaximumErrorCount中指定的数量时,就会发生这种情况。更改MaximumErrorCount或修复错误。

OnPostExecute,Server1,NT Service \ SQLSERVERAGENT,CDW_Server1_Server1_1,{45A6144C-8DDD-49A6-A6BA-AE81E24826D5},{1CF7B713-F747-45FB-8936-5522651E0C7A},5/7/2014 10:08:46 AM,5/7 / 2014 10:08:46 AM,0,0x,(null)DiagnosticEx,Server1,NT Service \ SQLSERVERAGENT,CDW_Server1_Server1_1,{45A6144C-8DDD-49A6-A6BA-AE81E24826D5},{1CF7B713-F747-45FB-8936-5522651E0C7A} ,5/7/2014 10:08:46 AM,5/7/2014 10:08:46 AM,0,0x,104546304 PackageEnd,Server1,NT Service \ SQLSERVERAGENT,CDW_Server1_Server1_1,{45A6144C-8DDD-49A6-A6BA- AE81E24826D5},{1CF7B713-F747-45FB-8936-5522651E0C7A},5/7/2014 10:08:46 AM,5/7/2014 10:08:46 AM,1,0x,包执行结束。


您应该提供有关如何配置副本数据库过程的更多数据。也许您是在文件级别通过自身复制数据库。
Vesper

我在向导中使用sa用户。和方法:“使用SQL管理对象方法”。并且我确定命名为新的DN名称。我使用测试数据库执行了此步骤,并且效果很好!!!!!。

使用新名称还原,也无法使用。它会抛出使用中的oldDB错误。我也

2
您必须确保在还原时更改物理文件名和逻辑名,否则您将尝试在将要使用的现有数据库文件之上进行还原。
2014年

在提供新名称后,在还原向导中。逻辑名称和物理名称不会自动更改。我只是可以更改物理名称而不合逻辑

Answers:


7

简单地将数据库备份到.bak,然后从.bak还原创建新数据库可能会更容易。

BACKUP DATABASE [aaa] TO DISK = N'E:\aaa.bak'

然后检查.bak中当前文件的逻辑名称和位置:

Restore filelistonly from disk ='E:\aaa.bak'

最后还原数据库,重命名文件以确保您不会覆盖现有数据库

restore database Newdatabasename
FROM disk = 'E:\aaa.bak'
WITH replace,
MOVE 'Logical data name' TO 'E:\Newdatabasename.MDF',
MOVE 'Logical log name' TO 'E:\Newdatabasename.LDF',
recovery --force

如果要在较低的服务器版本上进行复制,则不会。
watbywbarif

@watbywbarif问题是:in the same SqlServer
收起

3

下面是我为自己编写的用于复制数据库的脚本。它灵活,可以转换成存储过程。

评论将说明其作用。

在PROD中运行之前,先在测试服务器上对其进行测试!

/*
Author      :       KIN SHAH
Purpose     :       Written for dba.stackexchange.com
                -   This script will take the current database name and make a copy of it as
                    databaseName_copy_Month_Year e.g. [AdventureWorks2008R2_copy_August_2014]
                -   It will not replace the database and will fail if the copy database existed.
                -   Assuming that copy database is not currently present on the instance.
                -   It wont delete the backup made as a part of making a copy of the database. 
                    It will print out the location and then you can delete it
Any questions .. Let me know .... :-)

*/

IF object_id('tempdb..#temp1') IS NOT NULL
BEGIN
    DROP TABLE #temp1
END

IF object_id('tempdb..#temp2') IS NOT NULL
BEGIN
    DROP TABLE #temp2
END

IF object_id('tempdb..#temp3') IS NOT NULL
BEGIN
    DROP TABLE #temp3
END

/************************************************* CHANGE HERE STARTS !! ******************************************************/
DECLARE @dbname NVARCHAR(MAX)

SET @dbname = 'AdventureWorks2008R2' -- ** change HERE ***

--backup path goes here
DECLARE @path NVARCHAR(MAX)

-- Here the path is hard-coded  as all the server has 'D:\2restore' folder. This can be made as input parameter also !
SET @path = 'C:\crap_test' -- ** change HERE ***
    -- generates copy database name 

DECLARE @archivedbname NVARCHAR(MAX)

SET @archivedbname = @dbname + '_copy' + '_' + DATENAME(MONTH, GETDATE()) + '_' + CAST(DATEPART(YEAR, GETDATE()) AS VARCHAR(MAX))

--PRINT @archivedbname
/************************************************* CHANGE HERE ENDS !! ******************************************************/
-- check that the database to be archived is  there and is not a system database ...
IF @dbname IN (
        SELECT NAME
        FROM MASTER..sysdatabases
        WHERE DB_ID(NAME) > 4
        )
BEGIN
    SELECT 'The database is correct. starting Archiving Process .....'

    BEGIN TRY
        SELECT *
        INTO #temp1
        FROM MASTER.sys.master_files
        WHERE database_id = cast(DB_ID(@dbname) AS NVARCHAR(MAX))

        -- now get the logical and physical names of the database to be archived
        -- type 0 = data
        CREATE TABLE #temp2 (
            ldata NVARCHAR(MAX)
            ,pdata NVARCHAR(max)
            )

        DECLARE @ldata NVARCHAR(MAX)
        DECLARE @pdata NVARCHAR(MAX)

        SELECT @ldata = 'select [name],[physical_name] from #temp1 where  type = 0 and database_id =' + cast(DB_ID(@dbname) AS NVARCHAR(MAX))

        INSERT INTO #temp2
        EXEC (@ldata)

        SELECT @ldata = ldata
        FROM #temp2

        --PRINT @ldata
        SELECT @pdata = pdata
        FROM #temp2

        SELECT @pdata = left(@pdata, len(left(@pdata, LEN(@pdata) - 4)) - len(@ldata)) + @archivedbname + '.mdf'

        --PRINT @pdata
        -- type 1 = log
        CREATE TABLE #temp3 (
            llog NVARCHAR(MAX)
            ,plog NVARCHAR(max)
            )

        DECLARE @llog NVARCHAR(MAX)
        DECLARE @plog NVARCHAR(MAX)

        SELECT @llog = 'select [name],[physical_name] from #temp1 where  type = 1 and database_id =' + cast(DB_ID(@dbname) AS NVARCHAR(MAX))

        INSERT INTO #temp3
        EXEC (@llog)

        SELECT @llog = llog
        FROM #temp3

        --PRINT @llog
        SELECT @plog = plog
        FROM #temp3

        SELECT @plog = left(@plog, LEN(left(@plog, LEN(@plog) - 4)) - LEN(@llog)) + @archivedbname + '_log.ldf'

        --PRINT @plog
        -- now we will take backup of the database that is specified ....
        SELECT 'Taking backup of database ' + @dbname

        DECLARE @sql NVARCHAR(MAX)

        -- use compression using Redgate backup 
        SELECT @sql = 'backup database ' + @dbname + ' to disk =''' + @path + '\' + @dbname + '_FULL_' + convert(VARCHAR(10), getdate(), 112) + '.bak' + ''' with init, compression, stats =10'

        PRINT @sql

        EXEC (@sql)

        SELECT 'The backup is done for ' + @dbname
    END TRY

    BEGIN CATCH
        SELECT ERROR_NUMBER() AS ErrorNumber
            ,ERROR_SEVERITY() AS ErrorSeverity
            ,ERROR_STATE() AS ErrorState
            ,ERROR_PROCEDURE() AS ErrorProcedure
            ,ERROR_LINE() AS ErrorLine
            ,ERROR_MESSAGE() AS ErrorMessage
    END CATCH

    -- now restore the database as archive database          
    BEGIN TRY
        SELECT 'Starting restore part for ' + @archivedbname

        SELECT @sql = 'restore database ' + @archivedbname + ' from disk = ''' + @path + '\' + @dbname + '_FULL_' + CONVERT(VARCHAR(8), GETDATE(), 112) + '.bak' + ''' with recovery ' + ',' + ' move ''' + @ldata + ''' ' + 'to ' + '''' + @pdata + '''' + ',' + ' move ''' + @llog + ''' ' + ' to ' + '''' + @plog + ''''

        --print (@sql)
        EXEC (@sql)

        SELECT 'Restore is done sucessfully ! And the new database name is ' + @archivedbname + '!!'
    END TRY

    BEGIN CATCH
        SELECT ERROR_NUMBER() AS ErrorNumber
            ,ERROR_SEVERITY() AS ErrorSeverity
            ,ERROR_STATE() AS ErrorState
            ,ERROR_PROCEDURE() AS ErrorProcedure
            ,ERROR_LINE() AS ErrorLine
            ,ERROR_MESSAGE() AS ErrorMessage
    END CATCH

    SELECT 'Database is restored as Copy, Now you can delete the backup taken at ...' + @path + '\' + @dbname + '_full_' + CONVERT(VARCHAR(8), GETDATE(), 112) + '.bak'''
        -- delete the backup file
        --select @sql= 'exec master.dbo.xp_cmdshell ''Del '+@path+'\'+ @dbname+'_full_'+ CONVERT(VARCHAR(8), GETDATE(), 112)+'.bak'''
        --print (@sql)
        --EXEC (@sql)
END
ELSE
BEGIN
    SELECT ' The database is INCORRECT ! Check if the database exists or is not a system database'
END
GO

2

我遇到过同样的问题。我将SQL Server代理服务登录帐户更改为管理员。之后,一切都很好。我认为,代理服务无法读取/写入。


这是这里答案中最简单的解决方案。我永远不会怀疑登录帐户会导致此问题。
Lester Nubla '17

2

我对此有疑问。最终,我决定做两件事:

  1. 创建一个名为“ DTS包”的文件共享。这是因为我无法在向导中选择包目的地。确保您的SQL Server代理在其下运行的帐户的共享和ACL权限已满(默认为“ NT Service \ SQLSERVERAGENT”)。

在此处输入图片说明

  1. 将对SQL Server代理帐户的完全权限也添加到要在其中创建新数据库的目标文件夹中。

我还更改了日志记录以记录到文件,因此更容易诊断出问题。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.