SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Backup/restore and copying a database


Backup/restore and copying a database

Author
Message
hboswell
hboswell
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 40
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
sql-lover
sql-lover
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1573 Visits: 1930
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.
hboswell
hboswell
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 40
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
hboswell
hboswell
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 40
[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
Beatrix Kiddo
Beatrix Kiddo
SSCrazy
SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)

Group: General Forum Members
Points: 2668 Visits: 4391
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.
Beatrix Kiddo
Beatrix Kiddo
SSCrazy
SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)

Group: General Forum Members
Points: 2668 Visits: 4391
(Double post, sorry.)
sql-lover
sql-lover
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1573 Visits: 1930
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".
Grant Fritchey
Grant Fritchey
SSC-Dedicated
SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)

Group: General Forum Members
Points: 39161 Visits: 32616
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 Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
hboswell
hboswell
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 40
Thanks all. And I promise, I'm reading the manual as fast as I can.

Harry
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