SQL Server restore from backup

by Jeff Haynie on February 18, 2007 · Comments

I’m not a big user of Microsoft SQL Server, but sometimes you have to do what you need to for a customer.

This weekend, I ran into a problem. How do you restore a backup of a SQL Server database to a new machine? Seems easy enough. Right.

After some time reaching and experimenting, I found a simple way to do it. First, most likely you’re paths will be different from the machine that you exported the backup database to the one that you want to restore it to. You can determine this paths of the database backup by running the following command:

restore filelistonly from disk = 'c:∖mybackup.bak'

Of course, you’ll need to replace the path with the path to your backup file.

This command should return the internal database files, their names and locations and a bunch of other information. Once you have this, you can now properly restore it to the right location.

restore database MyDatabase from disk = 'c:∖mybackup.bak'
with move 'MyDatabase_Data' to
'c:∖Program Files∖MS SQL Server∖Data∖MyDatabase.mdf',
move 'MyDatabase_Log' to
'c:∖Program Files∖MS SQL Server∖Data∖MyDatabase.ldf'

Make sure you set the location to where you normally store your database files. Replace MyDatabase_Data and MyDatabase_Log with the names found in your backup database file.

Technorati technorati tags: , ,

Popularity: 14% [?]

If you enjoyed this post, make sure you subscribe to my RSS feed!

  • Bill J
    Nice tip. Many thanks!

    I don't use sql server as often as you but I remember a good tool I used for backup and restore.
    It was LiteSpeed.
    The process went quite smoothly, fast and without any extra scripts.
    I hope you will be able to find this tool useful for your tasks as well.
blog comments powered by Disqus

Previous post: SoCon07: how it came together

Next post: Laptop Woes