Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Restoring from one instance to another... Expand / Collapse
Author
Message
Posted Wednesday, August 18, 2010 1:59 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Monday, March 24, 2014 9:05 PM
Points: 387, Visits: 418
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!
Post #971445
Posted Wednesday, August 18, 2010 2:26 PM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 4:24 PM
Points: 5,847, Visits: 12,580
It is as long as you also include the 'with replace' clause

---------------------------------------------------------------------

Post #971473
Posted Wednesday, August 18, 2010 4:18 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Monday, March 24, 2014 9:05 PM
Points: 387, Visits: 418
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?
Post #971513
Posted Wednesday, August 18, 2010 4:39 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Monday, March 24, 2014 9:05 PM
Points: 387, Visits: 418
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


Post #971514
Posted Thursday, August 19, 2010 3:48 AM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 4:24 PM
Points: 5,847, Visits: 12,580
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.


---------------------------------------------------------------------

Post #971710
Posted Thursday, August 19, 2010 7:52 PM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Today @ 3:29 PM
Points: 734, Visits: 3,561
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
Post #972257
Posted Friday, August 20, 2010 9:39 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Monday, March 24, 2014 9:05 PM
Points: 387, Visits: 418
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...
Post #972631
Posted Tuesday, October 23, 2012 2:54 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, January 05, 2014 10:48 PM
Points: 2, Visits: 48
you have to insert comma(",") after with replace..
Post #1375913
Posted Tuesday, October 23, 2012 2:56 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 11:47 AM
Points: 41,525, Visits: 34,442
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

Post #1375915
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse