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

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

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

会有什么问题呢?


当前回答

:

1)在使用RESTORE命令时使用WITH REPLACE(如果使用GUI,则在Options ->覆盖现有数据库(WITH REPLACE))。

2)删除冲突的旧数据库,使用restore命令重新恢复。

查看链接了解更多细节。

其他回答

USE [master];
GO

CREATE DATABASE db;
GO

CREATE DATABASE db2;
GO

BACKUP DATABASE db TO DISK = 'c:\temp\db.bak' WITH INIT, COMPRESSION;
GO

RESTORE DATABASE db2
  FROM DISK = 'c:\temp\db.bak'
  WITH REPLACE,
  MOVE 'db' TO 'c:\temp\db2.mdf',
  MOVE 'db_log' TO 'c:\temp\db2.ldf';

首先创建一个同名的空白数据库。然后选择恢复选项

在左侧窗格的选项下,不要忘记选择

覆盖现有数据库 保留复制设置

就是这样

我只是想解决这个问题。

从以管理员身份运行到这里和其他地方找到的建议,我尝试了所有方法;为我解决这个问题的是在文件属性选项卡中检查“重新安置文件”选项。

希望这能帮助到其他人。

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

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...

如果您正在使用脚本方法,并且有关于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文档中找到。