what databases are already set up in the log-shipping, and which ones are not?

All we need is an easy explanation of the problem, so here it is.

I am setting up log-shipping from server1 to server2.

there are many databases on server1 and I want to automate the process.

I have already done a few databases manually, while I am working on the automating process.

First question is:

How can I easily find out which databases are already set up in the log-shipping and which ones are not?

Currently to get a list of databases not yet on log-shipping I am doing the following:

    if object_id('tempdb.dbo.#log_shipping_monitor ') is not null
       drop table #log_shipping_monitor 

    create table #log_shipping_monitor  
    (  
        status bit null  
        ,is_primary bit not null default 0  
        ,server sysname   
        ,database_name sysname  
        ,time_since_last_backup int null  
        ,last_backup_file nvarchar(500) null  
        ,backup_threshold int null  
        ,is_backup_alert_enabled bit null  
        ,time_since_last_copy int null  
        ,last_copied_file nvarchar(500) null  
        ,time_since_last_restore int null  
        ,last_restored_file nvarchar(500) null  
        ,last_restored_latency int null  
        ,restore_threshold int null  
        ,is_restore_alert_enabled bit null  
        ,ts timestamp not null  
        ,primary key (is_primary, server, database_name)  
        ,unique (ts)  
    )  



    insert into #log_shipping_monitor
    ([status]
    ,[is_primary]
    ,[server]
    ,[database_name]
    ,[time_since_last_backup]
    ,[last_backup_file]
    ,[backup_threshold]
    ,[is_backup_alert_enabled]
    ,[time_since_last_copy]
    ,[last_copied_file]
    ,[time_since_last_restore]
    ,[last_restored_file]
    ,[last_restored_latency]
    ,[restore_threshold]
    ,[is_restore_alert_enabled])
exec master.dbo.sp_executesql    @stmt=N'exec sp_help_log_shipping_monitor'
                                ,@params=N'@verbose bit'
                                , @Verbose=0

SELECT d.NAME, d.recovery_model_desc 
  FROM sys.databases d
where d.name not in 
         (
            select l.database_name
            from #log_shipping_monitor l
            where l.[server] = @@SERVERNAME

          )
      and d.database_id > 5 
      and d.state_desc = 'ONLINE'
order by d.name 

this is working fine and gives me the following result:

what databases are already set up in the log-shipping, and which ones are not?

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

that worked fine but there is a much easier way to monitor and have a look at the log shipping settings by using the log shipping tables in the msdb.

for instance:

msdb.dbo.log_shipping_primary_databases

Stores one record for the primary database in a log shipping
configuration. This table is stored in the msdb database.

 select * from msdb.dbo.log_shipping_primary_databases

what databases are already set up in the log-shipping, and which ones are not?

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply