Command line scripts to restore the 4 system databases of MS SQL Server 2008

Posted by ciscokid on Server Fault See other posts from Server Fault or by ciscokid
Published on 2010-05-12T19:37:20Z Indexed on 2010/05/12 19:44 UTC
Read the original article Hit count: 306

Filed under:
|
|
|
|

Hi there,

can someone give me some advice on how to restore the 4 system databases (master, msdb, model, tempdb) of a sql server 2008 please?

I've already done some testing myself (on restoring the master database) with the following commad line script as a result:

::set variables

set dbname=master

set dbdirectory=C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA

title Restoring %dbname% database

net stop mssqlserver

cd C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Binn

sqlservr -m

sqlcmd -Slocalhost -E -Q "restore database master from disk='c:\master.bak' WITH REPLACE"

net start mssqlserver

pause

After the execution of the 'sqlservr -m' command (used to start the server instance in single-user mode, which is only necessary when restoring the MASTER database), the script stops. So in order to execute the last 2 commands I need to separate the script into 2 smaller scripts, and run them one after the other.

Does anyone has an idea on how I can merge them into one single script that runs completely without any interruption?

I also want to restore the other 3 system databases using command line scripts like this one. Can someone please advice me how I need to go on? I've already noticed that restoring the temdb is not so easy, but there has to be a way...

Looking forward to your advice!

© Server Fault or respective owner

Related posts about restore

Related posts about database