Backup/restore and copying a database

  • 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

  • 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.

  • 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

  • [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

  • 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.

  • (Double post, sorry.)

  • 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".

  • 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

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Thanks all. And I promise, I'm reading the manual as fast as I can.

    Harry

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply