我试图恢复我的数据库的SQL Server备份文件,但它抛出一个错误如下:

备份集保存现有数据库以外的数据库的备份

我的数据库是SQL Server 2008,备份文件是2005年的。

会有什么问题呢?


当前回答

如果您正在使用脚本方法,并且有关于LDF和MDF文件的错误,您可以首先查询备份文件中的备份集中文件的逻辑名称(和其他详细信息),使用以下命令:

-- Queries the backup file for the file list in backup set, where Type denotes 
-- type of file. Can be L,D,F or S
-- info: https://learn.microsoft.com/en-us/sql/t-sql/statements/restore-statements-filelistonly-transact-sql
RESTORE FILELISTONLY FROM DISK = 'C:\Temp\DB_backup.bak'
GO

你会得到类似如下的结果:

然后你可以在查询中使用这些逻辑名称:

    -- Script assumes you want MDF and LDF files restored on separate drives. Modify for your scenario
    RESTORE DATABASE DB 
    FROM DISK='C:\Temp\DB_backup.bak'
    WITH REPLACE,
      MOVE 'DB' TO 'E:\MSSQL\Data\DB.mdf', -- "DB" is the mdf logical name from query above
      MOVE 'DB_log' TO 'F:\MSSQL\Logs\DB.ldf'; -- "DB_log" is LDF logical name from query above

关于RESTORE filelist的更多信息可以从SQL Server文档中找到。

其他回答

如果您正在使用脚本方法,并且有关于LDF和MDF文件的错误,您可以首先查询备份文件中的备份集中文件的逻辑名称(和其他详细信息),使用以下命令:

-- Queries the backup file for the file list in backup set, where Type denotes 
-- type of file. Can be L,D,F or S
-- info: https://learn.microsoft.com/en-us/sql/t-sql/statements/restore-statements-filelistonly-transact-sql
RESTORE FILELISTONLY FROM DISK = 'C:\Temp\DB_backup.bak'
GO

你会得到类似如下的结果:

然后你可以在查询中使用这些逻辑名称:

    -- Script assumes you want MDF and LDF files restored on separate drives. Modify for your scenario
    RESTORE DATABASE DB 
    FROM DISK='C:\Temp\DB_backup.bak'
    WITH REPLACE,
      MOVE 'DB' TO 'E:\MSSQL\Data\DB.mdf', -- "DB" is the mdf logical name from query above
      MOVE 'DB_log' TO 'F:\MSSQL\Logs\DB.ldf'; -- "DB_log" is LDF logical name from query above

关于RESTORE filelist的更多信息可以从SQL Server文档中找到。

您可以恢复到一个新的数据库,验证文件名语法,它将在日志文件中,对于新的SQL版本将是“_log”后缀

AD检查覆盖现有的数据库标志在选项卡

Fabio

我也有同样的问题,但在PS上。我把它留在这里,以防有人试图做同样的事情

Restore-SqlDatabase -ServerInstance "<your instance name>" -Database "<your db name>" -BackupFile "<backup file route>.bak" -ReplaceDatabase

记住使用Set-ExecutionPolicy Unrestricted -Force和import import-module sqlps。完成后,不要忘记将执行策略设置为受限。

我试图将一个生产数据库恢复到同一台服务器上的一个登台数据库。

在我的案例中,唯一有效的是恢复到一个新的空白数据库。这工作得很好,没有尝试覆盖生产文件(如果您只是将生产备份文件恢复到现有的登台数据库,则会覆盖生产文件)。然后删除旧数据库并重命名-文件将保留新的临时名称,但在我的情况下,这是好的。

(或者先删除暂存数据库,然后恢复到与暂存数据库同名的新数据库)

这帮助我从系统驱动器导入备份文件

Create a database with the same name(preferably) as your .bak file database name Right click the database > Tasks > Restore > Database Under "Source for restore" select "From Device" Select the .bak file selecting the path from the system Select the check box for the database in the list box below Under "Select a Page" on the right Select "Options" Select the checkbox labeled "Preserve the replication settings(WITH KEEP_REPLICATION) Select the checkbox for Overwrite the existing database(WITH REPLACE) Now Go back to the General page and click OK to restore the database...