Quantcast
Channel: SQL Server Database Engine forum
Viewing all articles
Browse latest Browse all 12963

Restore DB from backup with move - need to set to single user mode first and then reset to multiuser?

$
0
0

Im going to restore a recent backup from a production server DB to a test server DB and I want to do it through tsql.  The DB already exists on the test server, I just want to overwrite it with a fresh copy.  There may or may not be some activity on the test server that is connected to the database, but its not important and can be abandoned/discarded.

This is what Im getting ready to do

First, get an idea of what the file paths are specified in the backup file
RESTORE FILELISTONLY FROM DISK = 'file_back_to_backup here .back .dat etc'

Then, set the DB to singleuser mode, and discard any connections/transactions currently started

ALTER DATABASE MyDBName
SET SINGLE_USER WITH
ROLLBACK IMMEDIATE

Then, do the restore, specifying the paths to the mdf/ldf files that already exist.

RESTORE DATABASE MyDBName
FROM DISK
WITH MOVE 'db logical name' TO 'new data path .mdf', MOVE 'log logical name' TO 'new log path.ldf';

Questions:
(1) If I specify the data and log file paths as ones that already exist, will they be overwritten?  This is what I want, as I just want to copy the prod db over to the test server.

(2) Do I need to explicitly reset the DB back to multiuser mode, or does this happen after the restore?

(3) Anything missing from the above script(s) ?  Suggestions?



Viewing all articles
Browse latest Browse all 12963

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>