05 Sep, 2009
Restoring a SQL database to a new host with limited accessibility
I’ve taken a side job for some extra cash, which involves some web development work, including MS SQL database stuff. Up until now, I’ve only worked on SQL databases that I have complete administrative access to… i.e., they are steps away from me and I’ve set them up personally. This means that I’m very comfortable with importing, exporting, backing up, restoring, etc…. up until this project.
Here’s the scenario: I have a .BAK file of the database that was hosted on a MSSQL Server 2005 at my previous employers data-center. I need to re-create that database on a hosted MS SQL Server 2005 system at GoDaddy.com. No worries, I thought. I will just create my new database, do a manual back up of it. Then restore it and point it to my .BAK file from the previous server. That concept is old-hat to me, as I’ve done it countless times… on systems that I have complete control and access to. This time it’s on a server that I have limited access to. GoDaddy only permits SQL restores from files that were created by the host system, and stored on it’s local disk. And… I have no rights to place my .BAK file onto the host db server. So, I put on my thinking cap and thunk this one out.
Now, I must fully expose that I am not a SQL DBA in any way, shape, or form. Systems Administration is my background… I can install, configure, and maintain the heck out of a MS SQL database. But, I have extremely limited skills with SQL programming and queries. So, here’s what I came up with:
I have SQL 2005 Express running on my Vista system. Figured I could use that to my advantage here to get the data moved. I’ll break it down into pieces. I have SQL Express connected to my local instance, as well as the remote instance.
- Create a new database (in my local instance, I created a new database… we’ll call it dbFOO)
- Make a back up of dbFOO
- Do a restore of dbFOO, and change it to grab the data from the .BAK file from the old system (this is the step that I would have loved to be able to do on the remote database server)
- Change the options so that it overwrites the existing database
- On the remote instance, create a new database named dbFOO (db names must be the same since we’re using some queries and we want to limit how much manual editing we need to do)
- On the local instance, right-click on one of the tables and choose “Script Table as… > CREATE To > Clipboard”
- On the remote instance, right-click on the database and choose “New Query”
- In the query window, paste your clipboard contents
- since your database names are the same, this query will run without issues on the remote instance.
- Execute the query. Boom, the table is now created on the remote instance. Rinse and repeat for the rest of the local instance tables.
- Tip: keep that query window open, and just replace the sql script with the once for the next table and execute it. A little time-saver.
- Once the tables are created, right-click on the dbFOO database on the remote instance. Choose “Tasks > Import Data”
- WAIT! SQL Express doesn’t have DTS built in, so how am I able to do this? I once had SQL 2000 Ent. Mgr. installed and I held on to the admin tools, which included DTS. It does spit out some errors when starting up, but I just launch dtswizard.exe and I’m able to use it for my SQL 2005 Express databases.
- Choose the local instance as your source, and your remote instance as your destination. Set up dbFOO as the database, of course.
- Go through all of the wizard steps, choose the option for “copy data from one or more tables or views”.
- Check the boxes for all the tables and make any adjustments. (I had to enable identity inserts)
- Finish the wizard and blam, there is all of the data.
Are there other ways to accomplish what I needed? Maybe so. Is this the most graceful way to accomplish what I needed? Probably not. Do I care? Nope… I got what I needed done. It actually took me longer to write this post than it did to do all the steps listed above.
If you have other ideas or ways that this could have been done, please leave a comment. I love to document this stuff for other out there that could be in the same pickle I was, to give them some ideas or help in their situation.








