Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Restoring from one instance to another...


Restoring from one instance to another...

Author
Message
SQL_Enthusiast
SQL_Enthusiast
Old Hand
Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)

Group: General Forum Members
Points: 388 Visits: 422
Hello everyone!

I'm playing around today with backup and restore for an SSIS package. My goal is to backup from my DEVELOPMENT instance from database 197 and restore that to my PRODUCTION instance OVERTOP of my PROD database.

On line I find several T-SQL scripts that kind of make sense, but I trust you guys (and gals) over Google any day (hehe)

Here's what I found...


RESTORE DATABASE Business_Data_TSQL
FROM DISK='d:\Business_Data.bak'
WITH RECOVERY
MOVE 'Business_Data' TO 'D:\TSQL\Business_Data.mdf',
MOVE 'Business_Data_log' TO 'D:\TSQL\Business_Data_log.ldf', STATS=5



This makes sense up to the MOVE section. I understand what the MOVE is doing, I'm just concerned about the DEVELOPMENT database being called 197 and PRODUCTION database being called PROD. Is it as simple as saying:

MOVE '197' TO 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\PROD.mdf',
MOVE '197_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\PROD_Log.ldf'



Will that OVERWRITE the existing PROD.mdf and PROD_Log.ldf already in 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data'?

Thank you as always!
w00t
george sibbald
george sibbald
SSCertifiable
SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)

Group: General Forum Members
Points: 6348 Visits: 13687
It is as long as you also include the 'with replace' clause

---------------------------------------------------------------------
SQL_Enthusiast
SQL_Enthusiast
Old Hand
Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)

Group: General Forum Members
Points: 388 Visits: 422
I keep getting...


Msg 102, Level 15, State 1, Line 6
Incorrect syntax near 'MOVE'.



Here's my actual SQL


RESTORE DATABASE HCN_PROD2
FROM DISK ='C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\197.bak'
WITH REPLACE
MOVE '197' TO 'C:\Program Files\Microsoft SQL Server\MSSQL.4\MSSQL\Data\HCN_PROD2.mdf',
MOVE '197_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL.4\MSSQL\Data\HCN_PROD2_log.ldf',
MOVE '197_Audit' TO 'C:\Program Files\Microsoft SQL Server\MSSQL.4\MSSQL\Data\HCN_PROD2AUDIT.ndf',
STATS=5



What might I be missing?
SQL_Enthusiast
SQL_Enthusiast
Old Hand
Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)

Group: General Forum Members
Points: 388 Visits: 422
Never mind... I had a "moment"... Sorry

Thanks for the help!



RESTORE DATABASE [HCN_PROD2] FROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\197.bak' WITH FILE = 1, MOVE N'HCN_Data' TO N'C:\Program Files\Microsoft SQL Server\MSSQL.4\MSSQL\Data\HCN_PROD2.mdf', MOVE N'HCN_AUDIT' TO N'C:\Program Files\Microsoft SQL Server\MSSQL.4\MSSQL\Data\HCN_PROD2AUDIT.mdf', MOVE N'HCN_Log' TO N'C:\Program Files\Microsoft SQL Server\MSSQL.4\MSSQL\Data\HCN_PROD2_log.ldf', NOUNLOAD, REPLACE, STATS = 10
GO



george sibbald
george sibbald
SSCertifiable
SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)

Group: General Forum Members
Points: 6348 Visits: 13687
no probs.

FILE =1 should not be necessary. If you are always backing up to the same backup file name ensure you use the init clause in the backup, otherwise it will be appending and the backup fie will grow very large.

after the restore you may also need to change the database owner and synch orphaned user ids.

---------------------------------------------------------------------
SQLQuest29
SQLQuest29
Right there with Babe
Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)

Group: General Forum Members
Points: 746 Visits: 4311
just to add 50 Cents more to what george mentioned:

The restore would fail if it is not given exclusive access.

Add this before your restore:

alter database db_name_to_restore
set single_user with rollback immediate
waitfor delay '00:00:05'
alter database db_name_to_restore
set multi_user

-- from here starts restore code

-- sync orphaned users if any

HTH
Cheers !

______________________________________________________________________________________________________________________________________________________________________________________
HTH !
Kin
MCTS : 2005, 2008
Active SQL Server Community Contributor :-)
SQL_Enthusiast
SQL_Enthusiast
Old Hand
Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)Old Hand (388 reputation)

Group: General Forum Members
Points: 388 Visits: 422
Excellent catch... thank you very much! Whistling

The DB owner should be okay (at least it appears to be) and I added another step in the SSIS package to synch orphan users...
mukul.maheshwari28
mukul.maheshwari28
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 90
you have to insert comma(",") after with replace..
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47311 Visits: 44392
Please note: 2 year old (resolved) thread


Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search