|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Yesterday @ 12:12 PM
Points: 241,
Visits: 360
|
|
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!
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 3:21 PM
Points: 5,317,
Visits: 11,307
|
|
It is as long as you also include the 'with replace' clause
---------------------------------------------------------------------
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Yesterday @ 12:12 PM
Points: 241,
Visits: 360
|
|
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?
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Yesterday @ 12:12 PM
Points: 241,
Visits: 360
|
|
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
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 3:21 PM
Points: 5,317,
Visits: 11,307
|
|
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.
---------------------------------------------------------------------
|
|
|
|
|
Say Hey Kid
      
Group: General Forum Members
Last Login: Today @ 10:31 AM
Points: 713,
Visits: 2,974
|
|
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, Cheers !
"Never take life too seriously, nobody gets out of it anyways ! When your love and skills unite, expect a masterpiece !"
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Yesterday @ 12:12 PM
Points: 241,
Visits: 360
|
|
Excellent catch... thank you very much! 
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...
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, June 04, 2013 2:54 AM
Points: 2,
Visits: 30
|
|
| you have to insert comma(",") after with replace..
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 4:08 PM
Points: 38,099,
Visits: 30,392
|
|
Please note: 2 year old (resolved) thread
Gail Shaw Microsoft Certified Master: SQL Server 2008, MVP 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
|
|
|
|