Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_cleanup_log_shipping_history

  No additional text.


Syntax
create procedure sys.sp_cleanup_log_shipping_history
(
    @agent_id uniqueidentifier     -- primary/secondary ID
    ,@agent_type tinyint              -- 0 = Backup, 1 = Copy, 2 = Restore
)
as
begin
    set nocount on
    declare @retcode int
                ,@agent_idstring sysname
                ,@history_retention_period int
                ,@curdate_utc datetime
                ,@monitor_server sysname
                ,@monitor_server_security_mode int
    
    -- security check
    
    exec @retcode = sys.sp_MSlogshippingsysadmincheck
    if (@retcode != 0 or @@error != 0)
        return 1
    
    -- must be invoked from master db
    
    if (db_name() != N'master')
    begin
        raiserror(5001, 16,-1)
        return 1
    end
    
    -- validate agent_type
    
    if (@agent_type not in (0,1,2))
    begin
        raiserror(21055, 16, -1, '@agent_type','sp_MSadd_log_shipping_error_detail')
        return 1
    end
    
    -- validate agent
    
    if (sys.fn_MSvalidatelogshipagentid(@agent_id, @agent_type) = 0)
    begin
        select @agent_idstring = cast(@agent_id as sysname)
        raiserror(32016, 16, 1, @agent_idstring, @agent_type)
        return 1
    end
    
    -- get monitor server information
    
    if (@agent_type = 0)
    begin
        select @monitor_server = pd.monitor_server
                ,@monitor_server_security_mode = pd.monitor_server_security_mode
                ,@history_retention_period = mp.history_retention_period
        from msdb.dbo.log_shipping_primary_databases as pd join msdb.dbo.log_shipping_monitor_primary as mp
            on pd.primary_id = mp.primary_id
        where pd.primary_id = @agent_id
    end
    else
    begin
        
        -- there can be multiple secondaries for a secondary primary
        -- with different history retention periods - choose the highest
        
        select @monitor_server = s.monitor_server
                ,@monitor_server_security_mode = s.monitor_server_security_mode
                ,@history_retention_period = max(ms.history_retention_period)
        from msdb.dbo.log_shipping_secondary as s join msdb.dbo.log_shipping_monitor_secondary as ms
            on s.secondary_id = ms.secondary_id
        where s.secondary_id = @agent_id
        group by s.monitor_server, s.monitor_server_security_mode
    end
    
    -- cleanup now
    
    select @curdate_utc = getutcdate()
    exec @retcode = sys.sp_MSprocesslogshippingretentioncleanup
                    @agent_id = @agent_id
                    ,@agent_type = @agent_type
                    ,@monitor_server = @monitor_server
                    ,@monitor_server_security_mode = @monitor_server_security_mode
                    ,@history_retention_period = @history_retention_period
                    ,@curdate_utc = @curdate_utc
    if (@retcode != 0 or @@error != 0)
        goto UNDO
    
    -- all done
    
    return 0

UNDO:
    return 1
end

 
Last revision 2008RTM
News

  Query a named instance
Sybase+ASE+silent+install
SQL 2008 R2
Deprecated procedures in SQL2008
Reporting Services item-level role definitions
Create all your missing indexes
Converting datetime field
Start MSSQL Server Profiler at time
Replicating MSSQL Server views
Exploring Microsoft Sharepoint
The OLE DB provider "SQLNCLI10" for linked server indicates.
Mobile solar charger
Oracle to SQL Server replication
Cannot insert the value NULL into column
Undocumented Microsoft SQL Server 2008
VMware
Zoekmachine optimalisatie
SQL Servers hidden objects
FckEditor
Flash in Ajax
De hype die AJAX heet
Barcode scannen
MySQL; Gratis, makkelijk en snel!
PHP
sIFR; de combinatie tussen HTML en Flash