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

Backup/restore and copying a database Expand / Collapse
Author
Message
Posted Thursday, March 27, 2014 10:52 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, May 15, 2014 10:21 AM
Points: 7, Visits: 17
This seems to be one area where the way I would have done this in Oracle just doesn't mesh with the SQL Server does things. I'm working on a project where I need to build a small database and then copy it to a server at the client's site. I can't connect directly, so I have to use a VPN connection and use Remote Desktop, copy the database backup from my machine to the cloud, then download it to the client machine. The project is still in the early stages, and the client is still sending me data in CSV files and Excel spreadsheets. I'm periodically needing to do a complete refresh of the database at the client. I've hacked my way through it a couple of times, but I need to know the proper way to do it. I get errors on the restore step, telling me the file is in use. Searching the web gets many what would seem to be the solution, but there's something I'm missing. I know this is one of those RTM situations, and I will, but for now, can someone tell me where I'm messing up?

Thanks,
Harry
Post #1555555
Posted Thursday, March 27, 2014 11:03 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, July 24, 2014 10:24 AM
Points: 373, Visits: 1,235
hboswell (3/27/2014)
This seems to be one area where the way I would have done this in Oracle just doesn't mesh with the SQL Server does things. I'm working on a project where I need to build a small database and then copy it to a server at the client's site. I can't connect directly, so I have to use a VPN connection and use Remote Desktop, copy the database backup from my machine to the cloud, then download it to the client machine. The project is still in the early stages, and the client is still sending me data in CSV files and Excel spreadsheets. I'm periodically needing to do a complete refresh of the database at the client. I've hacked my way through it a couple of times, but I need to know the proper way to do it. I get errors on the restore step, telling me the file is in use. Searching the web gets many what would seem to be the solution, but there's something I'm missing. I know this is one of those RTM situations, and I will, but for now, can someone tell me where I'm messing up?

Thanks,
Harry


Let me see if I understand.

Your have database A and you want to establish or refresh B with a copy of A? ... well, it depends of how remote or how they both are connected.

If you don't have a fast connection between both, and the refresh will be sporadically, then you take a FULL database backup of A and restore on top of B. At that time, database B will have all the changes you have performed on A at that point. Any subsequent change (after your backup) will be absent from B. This method will require or disconnect users and sessions on B during the restore.

You can also setup Tlog shipping. You need a fast connection between A and B, both need to be in FULL recovery model, and both will be in sync. Changes on A will be replicated to B.

Here...

http://technet.microsoft.com/en-us/library/ms186858.aspx#restoring_full_db

... you will find examples and explanation of RESTORE command.

Be careful with SQL logins and SIDs though. They won't be the same and you will have to manually reset.
Post #1555565
Posted Thursday, March 27, 2014 12:39 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, May 15, 2014 10:21 AM
Points: 7, Visits: 17
No connection at all between A and B, so I have to transfer the backup file via the cloud to Server B. Right now, a complete rebuild of B from A is sufficient. Later, it won't be that simple, but hopefully by then I'll have gotten acclimated to SQL Server.

Harry
Post #1555604
Posted Thursday, March 27, 2014 12:52 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, May 15, 2014 10:21 AM
Points: 7, Visits: 17
[Edit: I found the proper procedure and managed to accomplish what I wanted, using the "Restore Files and Filegroups" option, so this comment is now irrelevant]

Here's a related question: I want to make a copy of my database (database A in the above thread) on my server, to use as a test database. I had read that it could be done by following these steps in Management Studio:

1) Create a backup of the database you want to copy

2) In SSMS, right-click 'Databases' and select 'Restore Database'

3) Select the database you wish to copy from the 'From database' drop-down list in the 'Source for restore' section

4) Enter the name of the new database in the 'To database' field in the 'Destination for Restore' section - this cannot be the name of an existing database.

5) Click OK

But when I do that, I get the following error:

System.Data.SqlClient.SqlError: The file 'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\UMMC.mdf' cannot be overwritten. It is being used by database 'UMMC'. (Microsoft.SqlServer.SmoExtended)


I'm trying to create UMMCTEST.

Thanks,
Harry
Post #1555608
Posted Friday, March 28, 2014 5:29 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Today @ 9:19 AM
Points: 456, Visits: 1,682
I think you will need to do a restore with move.


restore database UMMCTEST

from disk = '[wherever your backup is held]'

with move '[your data file in the backup- probably called UMMC?]' to 'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\UMMCTEST.mdf'

,move '[your log file in the backup- probably called something like UMMC_log?]' to 'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\UMMCTEST_log.ldf'
'

I've had to guess at your paths in that example; usually I wouldn't put the data and log files on the C drive but I was basing my examples on what you've written below. Change them to whatever they should be in your environment.

If you don't know what your data and log files are called (their logical names), you can do;

restore filelistonly from disk = '[wherever your backup is held]'

Hope that makes sense.
Post #1555838
Posted Friday, March 28, 2014 5:29 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Today @ 9:19 AM
Points: 456, Visits: 1,682
(Double post, sorry.)
Post #1555839
Posted Friday, March 28, 2014 6:04 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, July 24, 2014 10:24 AM
Points: 373, Visits: 1,235
hboswell (3/27/2014)
[Edit: I found the proper procedure and managed to accomplish what I wanted, using the "Restore Files and Filegroups" option, so this comment is now irrelevant]

Here's a related question: I want to make a copy of my database (database A in the above thread) on my server, to use as a test database. I had read that it could be done by following these steps in Management Studio:

1) Create a backup of the database you want to copy

2) In SSMS, right-click 'Databases' and select 'Restore Database'

3) Select the database you wish to copy from the 'From database' drop-down list in the 'Source for restore' section

4) Enter the name of the new database in the 'To database' field in the 'Destination for Restore' section - this cannot be the name of an existing database.

5) Click OK

But when I do that, I get the following error:

System.Data.SqlClient.SqlError: The file 'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\UMMC.mdf' cannot be overwritten. It is being used by database 'UMMC'. (Microsoft.SqlServer.SmoExtended)


I'm trying to create UMMCTEST.

Thanks,
Harry


Yeah, probably the data and log path is not the same on both servers. Check the path on target server and restore with the WITH MOVE option, so you can actually refresh and overwrite database "B".
Post #1555852
Posted Friday, March 28, 2014 6:13 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 10:03 AM
Points: 15,561, Visits: 27,938
It's the MOVE option you need. The RESTORE statement will attempt to restore the files defined in the backup. So, in order to restore to a new database, you also have to define a new location for those files. You can read the details in the RESTORE section of Books Online. There's even an example down at the bottom of the screen.

----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1555858
Posted Friday, March 28, 2014 9:20 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, May 15, 2014 10:21 AM
Points: 7, Visits: 17
Thanks all. And I promise, I'm reading the manual as fast as I can.

Harry
Post #1555999
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse