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 tags: database, sqlserver, mssql
Popularity: 14% [?]
Other popular articles you might enjoy:
If you enjoyed this post, make sure you subscribe to my RSS feed!