如何使用备份和还原创建数据库副本

问题描述:

我正在尝试使用SQL Server Management Studio 2012创建本地数据库的副本。我找到了几种解决方案。其中之一-备份和还原数据库作为新数据库- HERE

Using SQL Server Management Studio 2012, I'm trying to create a copy of a local database. I found a few variants of solution. One of them - backup and restore database as new one - HERE.

当前创建名称为 Rewards2_bak 的数据库备份。该文件副本放入系统目录 C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup\

Currently create database backup with name Rewards2_bak. This copy of file place in to system catalog C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup\

下一步-创建查询以将数据库还原为现有数据库的副本

Next step - create query for restoring database as copy of existing one

GO
use master
RESTORE FILELISTONLY
    FROM Rewards2_bak

RESTORE DATABASE Rewards2_Copy
    FROM Rewards2_bak
    WITH RECOVERY,
    MOVE 'Rewards2_data' TO 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\Rewards2_copy.mdf',
    MOVE 'Rewards2_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\Rewards2_log_copy.ldf'
GO

错误,我没有备份设备 Rewads2_backup 。我是对的,在这种情况下,我可以使用设备(例如文件)以及文件位置?想想缺少的东西...

Got error, that I don't have a backup device Rewads2_backup. I'm right understand that in this case like device i can use file, and also file location? Think something missing...

要创建备份,请使用下一个查询(都可以)

For creating backup use next query (all OK)

USE Rewards2;
GO
BACKUP DATABASE Rewards2
TO DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup\Rewards2_bak.bak'
   WITH FORMAT,
      MEDIANAME = 'SQLServerBackups',
      NAME = 'Full Backup of Rewards2';
GO

也尝试在SQL Server 2012中使用工具任务->备份任务->恢复,但出现错误-无法创建备份。 (具有管理员权限的启动程序)

Also try to use tools in SQL Server 2012 Task --> Backup and Task --> Restore, but got error - can't create backup. (Launched program with Administrator rights)

这是我配置还原复制的屏幕

This is screen how I config restore to copy

但是我有错误,我可以t覆盖数据库文件 Rewards2 。这是一个问题-如果我输入数据库新名称 Rewards2_copy ,为什么它要覆盖 Rewards2 。还是我理解有问题?

But I have error, that I can't overwrite database file Rewards2. And this is question - why it wants to overwrite Rewards2 if I put new name of database Rewards2_copy. Or I understand something wrong?

当然,这是用于复制数据库的更多可能的变体,但确实希望为该解决方案找到问题。我犯错的地方/我忘记或不明白的地方。

Shure, that ther is a few more possible variants for making copy of database, but really whant to find problem for this solution. Where i make mistake/ what I forget or don't understand.

从备份还原数据库时,它将使用与原始数据库相同的文件名。
您需要在还原期间更改这些文件名。

When you restore a database from a backup it will use the same file names as the original database. You need to change these file names during the restore.

在还原窗口上,转到文件标签。在此窗口中,您有一列名为还原为
更改您看到的每个文件的还原为列中路径末尾的文件名。

On the restore window go to the Files tab. On this window you have a column called Restore As. Change the file names at the end of the path in the column Restore As for each of the files you see.