SQL Server Express备份和恢复到其他数据库批量
SQL Server Express backup and restore to other database batch
我正在尝试从我的实时数据库中外包一些流程,其中第三方工具正在导入数据,由于质量原因,在实时数据库中实施之前,这些数据首先必须 运行 通过一些 scripts/changes
所以我想我会在同一台服务器上创建第二个数据库来进行我的备份批次,每次我进行备份时我都会在新数据库中恢复备份,第三方工具正在导入数据。然后我使用这个数据库对另一个数据库进行一些更改,然后我将其更新为实时数据库。
批处理文件:
osql.exe -S (local)\WAWI -U user -P password -Q "BACKUP DATABASE eazybusiness TO DISK = 'c:\WaWi-Backups\eazybusiness.bak'"
osql.exe -S (local)\WAWI -U user -P password -d master -Q "restore database Mandant_2 FROM DISK ='c:\WaWi-Backups\eazybusiness.bak' with replace"
但是当 运行 运行脚本时,恢复命令抛出以下错误
Msg '1834', '16', status '1', server 'DBServer\WAWI', line 1
The file ' C:\Program Files\Microsoft SQL
Server\MSSQL11. WAWI\MSSQL\DATA\eazybusiness.mdf' can not be overwritten
be. It is used by the eazybusiness database.
Msg '3156', '16', '4' status, server 'DBServer\WAWI', line 1
The file 'eazybusiness' can not in ' C:\Program Files\Microsoft SQL
Server\MSSQL11. WAWI\MSSQL\DATA\eazybusiness.mdf' be restored.
Use WITH MOVE to a valid location for the file to identify.
Msg '1834', '16', status '1', server 'DBServer\WAWI', line 1
The file ' C:\Program Files\Microsoft SQL
Server\MSSQL11. WAWI\MSSQL\DATA\eazybusiness_log.ldf' cannot
be overridden. It is used by the eazybusiness database.
Msg '3156', '16', '4' status, server 'DBServer\WAWI', line 1
The file 'eazybusiness_log' cannot be in ' C:\Program Files\Microsoft SQL
Server\MSSQL11. WAWI\MSSQL\DATA\eazybusiness_log.ldf' restored
be. Use WITH MOVE to a valid location for the file to
identify.
Msg '3119', '16', status '1', server 'DBServer\WAWI', line 1
Problems have been found in the planning of the restore statement. Preceding
Messages contain detailed information.
Msg '3013', '16', status '1', server 'DBServer\WAWI', line 1
RESTORE DATABASE is stopped abnormally.
SpeakSelect voice optionsSearch this translation with BingThis is a good translationThis is a bad translation.
如何通过批量恢复另一个数据库中的备份?
您正在使用不同的名称但相同的文件属性还原备份。由于原始数据库存在,您正试图覆盖导致失败的同一个数据库。您需要使用 WITH MOVE 语法为每个数据库数据和日志文件指定不同的文件名 and/or 位置。
请参阅 RESTORE 文档,特别是第 "Copying a Database Using BACKUP and RESTORE" 部分。
样本:
RESTORE DATABASE TestDB
FROM AdventureWorksBackups
WITH MOVE 'AdventureWorks2012_Data' TO 'C:\MySQLServer\testdb.mdf',
MOVE 'AdventureWorks2012_Log' TO 'C:\MySQLServer\testdb.ldf';
GO
我正在尝试从我的实时数据库中外包一些流程,其中第三方工具正在导入数据,由于质量原因,在实时数据库中实施之前,这些数据首先必须 运行 通过一些 scripts/changes
所以我想我会在同一台服务器上创建第二个数据库来进行我的备份批次,每次我进行备份时我都会在新数据库中恢复备份,第三方工具正在导入数据。然后我使用这个数据库对另一个数据库进行一些更改,然后我将其更新为实时数据库。
批处理文件:
osql.exe -S (local)\WAWI -U user -P password -Q "BACKUP DATABASE eazybusiness TO DISK = 'c:\WaWi-Backups\eazybusiness.bak'"
osql.exe -S (local)\WAWI -U user -P password -d master -Q "restore database Mandant_2 FROM DISK ='c:\WaWi-Backups\eazybusiness.bak' with replace"
但是当 运行 运行脚本时,恢复命令抛出以下错误
Msg '1834', '16', status '1', server 'DBServer\WAWI', line 1
The file ' C:\Program Files\Microsoft SQL Server\MSSQL11. WAWI\MSSQL\DATA\eazybusiness.mdf' can not be overwritten be. It is used by the eazybusiness database.Msg '3156', '16', '4' status, server 'DBServer\WAWI', line 1
The file 'eazybusiness' can not in ' C:\Program Files\Microsoft SQL Server\MSSQL11. WAWI\MSSQL\DATA\eazybusiness.mdf' be restored. Use WITH MOVE to a valid location for the file to identify.Msg '1834', '16', status '1', server 'DBServer\WAWI', line 1
The file ' C:\Program Files\Microsoft SQL Server\MSSQL11. WAWI\MSSQL\DATA\eazybusiness_log.ldf' cannot be overridden. It is used by the eazybusiness database.Msg '3156', '16', '4' status, server 'DBServer\WAWI', line 1
The file 'eazybusiness_log' cannot be in ' C:\Program Files\Microsoft SQL Server\MSSQL11. WAWI\MSSQL\DATA\eazybusiness_log.ldf' restored be. Use WITH MOVE to a valid location for the file to identify.Msg '3119', '16', status '1', server 'DBServer\WAWI', line 1
Problems have been found in the planning of the restore statement. Preceding Messages contain detailed information.Msg '3013', '16', status '1', server 'DBServer\WAWI', line 1
RESTORE DATABASE is stopped abnormally. SpeakSelect voice optionsSearch this translation with BingThis is a good translationThis is a bad translation.
如何通过批量恢复另一个数据库中的备份?
您正在使用不同的名称但相同的文件属性还原备份。由于原始数据库存在,您正试图覆盖导致失败的同一个数据库。您需要使用 WITH MOVE 语法为每个数据库数据和日志文件指定不同的文件名 and/or 位置。
请参阅 RESTORE 文档,特别是第 "Copying a Database Using BACKUP and RESTORE" 部分。
样本:
RESTORE DATABASE TestDB
FROM AdventureWorksBackups
WITH MOVE 'AdventureWorks2012_Data' TO 'C:\MySQLServer\testdb.mdf',
MOVE 'AdventureWorks2012_Log' TO 'C:\MySQLServer\testdb.ldf';
GO