Showing posts with label script. Show all posts
Showing posts with label script. Show all posts

Wednesday, March 28, 2012

Log shipping script

We are currently setting up log shipping using SQL 2000. We have a local
server on a 15 minute delay and a remote server on a 3 hour delay. I am
curious as to the process of recovering the logs in the event of a failover.
Has somebody ever done a script, or know of a way to automate the process of
"catching up" the application of the log files in the event of a failover?
Specifically I am looking to automate the process of recognizing the last
log applied and then applying the subsequent logs required to bring the DB
back online.
Any help would be appreciated.
Thanks
Ron
Please don't multi-post.
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Ron VZ" <rvanzant@.premierbankcard.com> wrote in message
news:uYUCrvlQEHA.368@.TK2MSFTNGP09.phx.gbl...
> We are currently setting up log shipping using SQL 2000. We have a local
> server on a 15 minute delay and a remote server on a 3 hour delay. I am
> curious as to the process of recovering the logs in the event of a
failover.
> Has somebody ever done a script, or know of a way to automate the process
of
> "catching up" the application of the log files in the event of a failover?
> Specifically I am looking to automate the process of recognizing the last
> log applied and then applying the subsequent logs required to bring the DB
> back online.
>
> Any help would be appreciated.
>
> Thanks
>
> Ron
>

Log shipping script

We are currently setting up log shipping using SQL 2000. We have a local
server on a 15 minute delay and a remote server on a 3 hour delay. I am
curious as to the process of recovering the logs in the event of a failover.
Has somebody ever done a script, or know of a way to automate the process of
"catching up" the application of the log files in the event of a failover?
Specifically I am looking to automate the process of recognizing the last
log applied and then applying the subsequent logs required to bring the DB
back online.
Any help would be appreciated.
Thanks
RonPlease don't multi-post.
--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Ron VZ" <rvanzant@.premierbankcard.com> wrote in message
news:uYUCrvlQEHA.368@.TK2MSFTNGP09.phx.gbl...
> We are currently setting up log shipping using SQL 2000. We have a local
> server on a 15 minute delay and a remote server on a 3 hour delay. I am
> curious as to the process of recovering the logs in the event of a
failover.
> Has somebody ever done a script, or know of a way to automate the process
of
> "catching up" the application of the log files in the event of a failover?
> Specifically I am looking to automate the process of recognizing the last
> log applied and then applying the subsequent logs required to bring the DB
> back online.
>
> Any help would be appreciated.
>
> Thanks
>
> Ron
>

Monday, March 26, 2012

Log shipping reconciliation

I have a database reconciliation script that runs between two databases and
reconciles object counts and table counts etc between the two.
Is there a way to run such a script across a primary and secondary in log
shipping configuration. As the secondary is in RESTORING state it's not
accessible. Therefore is it possible to do something like bring it briefly up
to standby state, run the reconciliation and then take it back to restoring
again? Would this work and are there any gotchas?
Cheers.
Here is an example of how to do it:
there are two databases logshippingtestbak and logshippingtest.
I backup loshippingtest and restore this backup into the database
logshippingtestback with no recovery
backup log logshippingtest to disk='c:\logshippingtestlog.bak'
GO
--restoring my first log
restore log logshippingtestbak from disk='c:\logshippingtestlog.bak' with
norecovery
GO
select * from logshippingtestbak.dbo.sysobjects
Server: Msg 927, Level 14, State 2, Line 1
Database 'logshippingtestbak' cannot be opened. It is in the middle of a
restore.
--i backup another log
backup log logshippingtest to disk='c:\logshippingtestlog.bak'
--i restore it with the standby option
restore log logshippingtestbak from disk='c:\logshippingtestlog.bak' with
standby ='c:\standby.bak'
--i read this database
select * from logshippingtestbak.dbo.sysobjects
--I restore the same log this time with norecovery
restore log logshippingtestbak from disk='c:\logshippingtestlog.bak' with
norecovery
--I verify this database is inaccessible again.
select * from logshippingtestbak.dbo.sysobjects
Server: Msg 927, Level 14, State 2, Line 1
Database 'logshippingtestbak' cannot be opened. It is in the middle of a
restore.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Kev" <Kev@.discussions.microsoft.com> wrote in message
news:5722A586-57E3-41AA-B6DF-021F50F7F2CB@.microsoft.com...
>I have a database reconciliation script that runs between two databases and
> reconciles object counts and table counts etc between the two.
> Is there a way to run such a script across a primary and secondary in log
> shipping configuration. As the secondary is in RESTORING state it's not
> accessible. Therefore is it possible to do something like bring it briefly
> up
> to standby state, run the reconciliation and then take it back to
> restoring
> again? Would this work and are there any gotchas?
> Cheers.
|||Is it possible to do something like:
restore database [logshippingtestbak] with
standby=''c:\logshippingtestlog.bak'
<do the reconciliation>
restore database [logshippingtestbak] with norecovery
or do you always need to restore the last transaction log to switch modes.
Cheers
Kev.
"Hilary Cotter" wrote:

> Here is an example of how to do it:
> there are two databases logshippingtestbak and logshippingtest.
> I backup loshippingtest and restore this backup into the database
> logshippingtestback with no recovery
> backup log logshippingtest to disk='c:\logshippingtestlog.bak'
> GO
> --restoring my first log
> restore log logshippingtestbak from disk='c:\logshippingtestlog.bak' with
> norecovery
> GO
> select * from logshippingtestbak.dbo.sysobjects
> Server: Msg 927, Level 14, State 2, Line 1
> Database 'logshippingtestbak' cannot be opened. It is in the middle of a
> restore.
> --i backup another log
> backup log logshippingtest to disk='c:\logshippingtestlog.bak'
> --i restore it with the standby option
> restore log logshippingtestbak from disk='c:\logshippingtestlog.bak' with
> standby ='c:\standby.bak'
> --i read this database
> select * from logshippingtestbak.dbo.sysobjects
> --I restore the same log this time with norecovery
> restore log logshippingtestbak from disk='c:\logshippingtestlog.bak' with
> norecovery
> --I verify this database is inaccessible again.
> select * from logshippingtestbak.dbo.sysobjects
> Server: Msg 927, Level 14, State 2, Line 1
> Database 'logshippingtestbak' cannot be opened. It is in the middle of a
> restore.
>
>
> --
> Hilary Cotter
> Looking for a SQL Server replication book?
> http://www.nwsu.com/0974973602.html
> Looking for a FAQ on Indexing Services/SQL FTS
> http://www.indexserverfaq.com
>
> "Kev" <Kev@.discussions.microsoft.com> wrote in message
> news:5722A586-57E3-41AA-B6DF-021F50F7F2CB@.microsoft.com...
>
>
|||It doesn't have to be the last transaction log, but it would have to be the
next one in the chain. Consider if you dump each hour, you might not have
another log for 1 hour or so.
Also you don't need to put it back into norecovery, the next log applied
will. I prefer to put it back into norecovery so my users can't access it
and then interfer with the next tlog restore.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Kev" <Kev@.discussions.microsoft.com> wrote in message
news:629337E7-A409-49C3-9C99-7510FC802069@.microsoft.com...[vbcol=seagreen]
> Is it possible to do something like:
> restore database [logshippingtestbak] with
> standby=''c:\logshippingtestlog.bak'
> <do the reconciliation>
> restore database [logshippingtestbak] with norecovery
> or do you always need to restore the last transaction log to switch modes.
> Cheers
> Kev.
>
> "Hilary Cotter" wrote:
|||Would my bit of sql work?
"Hilary Cotter" wrote:

> It doesn't have to be the last transaction log, but it would have to be the
> next one in the chain. Consider if you dump each hour, you might not have
> another log for 1 hour or so.
> Also you don't need to put it back into norecovery, the next log applied
> will. I prefer to put it back into norecovery so my users can't access it
> and then interfer with the next tlog restore.
> --
> Hilary Cotter
> Looking for a SQL Server replication book?
> http://www.nwsu.com/0974973602.html
> Looking for a FAQ on Indexing Services/SQL FTS
> http://www.indexserverfaq.com
>
> "Kev" <Kev@.discussions.microsoft.com> wrote in message
> news:629337E7-A409-49C3-9C99-7510FC802069@.microsoft.com...
>
>
|||No, you would have to restore the log, like this
restore log [logshippingtestbak] from disk='c:\mylog' with
standby=''c:\logshippingtestlog.bak'
<do the reconciliation>
restore log [logshippingtestbak] from disk='c:\mylog1.bak' with norecovery
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Kev" <Kev@.discussions.microsoft.com> wrote in message
news:10217BE0-4F01-44D0-B7F6-6E6661B385F9@.microsoft.com...[vbcol=seagreen]
> Would my bit of sql work?
> "Hilary Cotter" wrote:
|||Are there any disadvantages to keeping it in standby mode all the time?
Presumably you can still restore in the same way - you just have to be
careful that nobody tries to access it at the wrong time.
Kev.
"Hilary Cotter" wrote:

> No, you would have to restore the log, like this
> restore log [logshippingtestbak] from disk='c:\mylog' with
> standby=''c:\logshippingtestlog.bak'
> <do the reconciliation>
> restore log [logshippingtestbak] from disk='c:\mylog1.bak' with norecovery
>
> --
> Hilary Cotter
> Looking for a SQL Server replication book?
> http://www.nwsu.com/0974973602.html
> Looking for a FAQ on Indexing Services/SQL FTS
> http://www.indexserverfaq.com
>
> "Kev" <Kev@.discussions.microsoft.com> wrote in message
> news:10217BE0-4F01-44D0-B7F6-6E6661B385F9@.microsoft.com...
>
>

Monday, March 12, 2012

log shipping failover to stand by server

Hi Guys
in logshipping to fail over to stand by server do i have
to do any role change
as far as i know i have to run following script at the
stand by server. am i right?
RESTORE DATABASE database_name WITH RECOVERY
EXEC SP_DBOPTION 'database_name', 'read
only', 'false'
EXEC SP_DBOPTION 'database_name', 'dbo use
only', 'false'
pls advice me
Thanks
Biju
Biju,
have a look at 'log shipping, role changes' in BOL. You don't need to run
your script manually, but run
sp_change_primary_role
sp_change_secondary_role
sp_change_monitor_role
Usually the logins have already been transferred so there's nothing else to
do. These sprocs are useful because they'll try to get the last log (the
live one) if at all possible.
HTH,
Paul Ibison
|||BUT I DONT want to change roles.
>--Original Message--
>Biju,
>have a look at 'log shipping, role changes' in BOL. You
don't need to run
>your script manually, but run
>sp_change_primary_role
>sp_change_secondary_role
>sp_change_monitor_role
>Usually the logins have already been transferred so
there's nothing else to
>do. These sprocs are useful because they'll try to get
the last log (the
>live one) if at all possible.
>HTH,
>Paul Ibison
>
>.
>
|||Biju,
the name is perhaps slightly unintuitive. sp_change_secondary_role:
(a) Copies the final production database transaction log backup to the
standby server along with any additional transaction log backups that were
not previously copied.
(b) Disables the log-shipping transaction copy job on the standby server.
(c) Restores all transaction log backups not previously restored to the
standby database and initiates the recovery of the standby database.
(d) Terminates and rolls back all pending transactions.
(e) Sets the access level of the standby database after completion of the
system stored procedure to multiuser mode.
(f) Creates a log-shipping database maintenance plan on the new primary
server for the new production database. The SQL Server Agent job defined in
this plan backs up the transaction log of the new production database to the
folder location you specified when you set up log shipping.
HTH,
Paul Ibison