Quantcast
Channel: Red Gate forums: SQL Backup 7
Viewing all articles
Browse latest Browse all 713

RE: Possible restore issue with 7.3.0.383 to replace database

$
0
0
I don't recall anything changed with regards to how the REPLACE function worked. The most important thing is getting the database logical names to match, and SQL Server handles the rest. Note that the following examples use native SQL Server backup/restore commands, and the results would be identical if you used SQL Backup commands.

E.g. this fails because the logical names in the backup set do not match that of the 'db2' database:

Code:
CREATE DATABASE db1 ON PRIMARY (NAME = 'db1_dat', FILENAME = 'f:\data\db1\db1.mdf') LOG ON (name = 'db1_log', FILENAME = 'f:\data\db1\db1.ldf')
GO
CREATE DATABASE db2 ON PRIMARY (NAME = 'db2_dat', FILENAME = 'f:\data\db2\db2.mdf') LOG ON (name = 'db2_log', FILENAME = 'f:\data\db2\db2.ldf')
GO
BACKUP DATABASE db1 TO DISK = 'f:\data\db1.bak'
GO
RESTORE DATABASE db2 FROM DISK = 'f:\data\db1.bak' WITH REPLACE
GO


This succeeds because we restored 'db2' from the 'db1' backup set, preserving the logical names:

Code:
DROP DATABASE db2
GO
RESTORE DATABASE db2 FROM DISK = 'f:\data\db1.bak' WITH MOVE 'db1_dat' TO 'f:\data\db2\db2.mdf', MOVE 'db1_log' TO 'f:\data\db2\db2.ldf', REPLACE
GO
RESTORE DATABASE db2 FROM DISK = 'f:\data\db1.bak' WITH REPLACE
GO


This also works because the logical names of both databases match.

Code:
DROP DATABASE db2
GO
CREATE DATABASE db2 ON PRIMARY (NAME = 'db1_dat', FILENAME = 'f:\data\db2\db2.mdf') LOG ON (name = 'db1_log', FILENAME = 'f:\data\db2\db2.ldf')
GO
RESTORE DATABASE db2 FROM DISK = 'f:\data\db1.bak' WITH REPLACE
GO

Viewing all articles
Browse latest Browse all 713

Trending Articles