Tuesday, March 20, 2012

Script Master DB Restore

I will be transferring database from one server to another along with the master and msdb database for use as a disaster recovery server. On the second server, I'd like to script the loading of all the databases (including the master). I can stop the SQL
Service using NET STOP MSSQLSERVER. Then, I can place the database in single user mode using the command "sqlservr -m". Next, I used OSQL to restore the master database (which restores the database and stops the sql server - inherently). The problem is th
at the command "sqlservr -m" leave the command shell open. I must close the window by manually typing <ctrl-c> and exiting the shell. I want this to be a hands-off operation. Any suggestions?
Thanks!
Adam
First I believe if you just create a cmd file and run your sqlservr -m from
there I think it will kill the window.
Jeff Duncan
MCDBA, MCSE+I
"Adam" <ahafner@.itape.com> wrote in message
news:B4188C24-EC76-40F1-BD02-A583C87A3075@.microsoft.com...
> I will be transferring database from one server to another along with the
master and msdb database for use as a disaster recovery server. On the
second server, I'd like to script the loading of all the databases
(including the master). I can stop the SQL Service using NET STOP
MSSQLSERVER. Then, I can place the database in single user mode using the
command "sqlservr -m". Next, I used OSQL to restore the master database
(which restores the database and stops the sql server - inherently). The
problem is that the command "sqlservr -m" leave the command shell open. I
must close the window by manually typing <ctrl-c> and exiting the shell. I
want this to be a hands-off operation. Any suggestions?
> Thanks!
> Adam
|||Have you tried the "exit" command?
----
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"Adam" <ahafner@.itape.com> wrote in message
news:B4188C24-EC76-40F1-BD02-A583C87A3075@.microsoft.com...
> I will be transferring database from one server to another along with the
master and msdb database for use as a disaster recovery server. On the
second server, I'd like to script the loading of all the databases
(including the master). I can stop the SQL Service using NET STOP
MSSQLSERVER. Then, I can place the database in single user mode using the
command "sqlservr -m". Next, I used OSQL to restore the master database
(which restores the database and stops the sql server - inherently). The
problem is that the command "sqlservr -m" leave the command shell open. I
must close the window by manually typing <ctrl-c> and exiting the shell. I
want this to be a hands-off operation. Any suggestions?
> Thanks!
> Adam
|||When you run the "sqlservr -m" the command shell hangs until <ctrl-c> typed. If you create a .bat file with the commands "sqlservr -m" followed on the next line by "exit", the "exit" command would not be executed until the <cntrl-c> was entered to end the
"sqlservr -m" command.
|||When you run the "sqlservr -m" the command shell hangs until <ctrl-c> typed. If you create a .bat file with the commands "sqlservr -m" followed on the next line by "exit", the "exit" command would not be executed until the <cntrl-c> was entered to end the
"sqlservr -m" command.
|||"Adam" <ahafner@.itape.com> wrote in message
news:B4188C24-EC76-40F1-BD02-A583C87A3075@.microsoft.com...
> I will be transferring database from one server to another along with the
master and msdb database for use as a disaster recovery server. On the
second server, I'd like to script the loading of all the databases
(including the master). I can stop the SQL Service using NET STOP
MSSQLSERVER. Then, I can place the database in single user mode using the
command "sqlservr -m". Next, I used OSQL to restore the master database
(which restores the database and stops the sql server - inherently). The
problem is that the command "sqlservr -m" leave the command shell open. I
must close the window by manually typing <ctrl-c> and exiting the shell. I
want this to be a hands-off operation. Any suggestions?
Try using:
start sqlservr -m
|||Try using the TSQL "SHUTDOWN" command inside the script you run through OSQL.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"Adam" <ahafner@.itape.com> wrote in message news:B4188C24-EC76-40F1-BD02-A583C87A3075@.microsoft.com...
> I will be transferring database from one server to another along with the master and msdb database for use
as a disaster recovery server. On the second server, I'd like to script the loading of all the databases
(including the master). I can stop the SQL Service using NET STOP MSSQLSERVER. Then, I can place the database
in single user mode using the command "sqlservr -m". Next, I used OSQL to restore the master database (which
restores the database and stops the sql server - inherently). The problem is that the command "sqlservr -m"
leave the command shell open. I must close the window by manually typing <ctrl-c> and exiting the shell. I
want this to be a hands-off operation. Any suggestions?
> Thanks!
> Adam
|||Hi,
Since you are setting up a Disaster recovery server, instead of restoring
the databases one one by , you have a alternate method which is very easy.
I have done this many times and succeeded always.This will work out if
you're moving to a different machine with the same logical drive layout
(Same folder structure) same as production.
Steps:-
1. Install the SQL Server and the same service pack as on your existing
machine.
2 Stop the SQL service on your old machine. Copy the entire SQL7/SQL 2000
folder and it's subfolders,
plus any separate folders containing logs or data, to the new machine.
Also copy over any other folders containing
data that you want to move to the new machine.
3. Start the SQL Server service in new machine. Login to query analyzer and
execute sp_dropserver <drop server> and use sp_addserver <new server>,Local
4. Stop and Start the SQL Server service
5. Check all the database are running fine.
6. Start the SQL Server in production server.
Have a look into Vyas's site
http://vyaskn.tripod.com/moving_sql_server.htm
Thanks
Hari
MCDBA
"Adam" <ahafner@.itape.com> wrote in message
news:B4188C24-EC76-40F1-BD02-A583C87A3075@.microsoft.com...
> I will be transferring database from one server to another along with the
master and msdb database for use as a disaster recovery server. On the
second server, I'd like to script the loading of all the databases
(including the master). I can stop the SQL Service using NET STOP
MSSQLSERVER. Then, I can place the database in single user mode using the
command "sqlservr -m". Next, I used OSQL to restore the master database
(which restores the database and stops the sql server - inherently). The
problem is that the command "sqlservr -m" leave the command shell open. I
must close the window by manually typing <ctrl-c> and exiting the shell. I
want this to be a hands-off operation. Any suggestions?
> Thanks!
> Adam
|||I can not bring down the production server at any time during the day (24x7).

No comments:

Post a Comment