sp_add_log_shipping_primary_database (Transact-SQL)
Sets up the primary database for a log shipping configuration, including the backup job, local monitor record, and remote monitor record.
sp_add_log_shipping_primary_database [ @database = ] 'database', [ @backup_directory = ] 'backup_directory', [ @backup_share = ] 'backup_share', [ @backup_job_name = ] 'backup_job_name', [, [ @backup_retention_period= ] backup_retention_period] [, [ @monitor_server = ] 'monitor_server'] [, [ @monitor_server_security_mode = ] monitor_server_security_mode] [, [ @monitor_server_login = ] 'monitor_server_login'] [, [ @monitor_server_password = ] 'monitor_server_password'] [, [ @backup_threshold = ] backup_threshold ] [, [ @threshold_alert = ] threshold_alert ] [, [ @threshold_alert_enabled = ] threshold_alert_enabled ] [, [ @history_retention_period = ] history_retention_period ] [, [ @backup_job_id = ] backup_job_id OUTPUT ] [, [ @primary_id= ] primary_id OUTPUT] [, [ @backup_compression= ] backup_compression_option ]
sp_add_log_shipping_primary_database must be run from the master database on the primary server. This stored procedure performs the following functions:
Generates a primary ID and adds an entry for the primary database in the table log_shipping_primary_databases using the supplied arguments.
Creates a backup job for the primary database that is disabled.
Sets the backup job ID in the log_shipping_primary_databases entry to the job ID of the backup job.
Adds a local monitor record in the table log_shipping_monitor_primary on the primary server using supplied arguments.
If the monitor server is different from the primary server, adds a monitor record in log_shipping_monitor_primary on the monitor server using supplied arguments.
This example adds the database AdventureWorks as the primary database in a log shipping configuration.
DECLARE @LS_BackupJobId AS uniqueidentifier DECLARE @LS_PrimaryId AS uniqueidentifier EXEC master.dbo.sp_add_log_shipping_primary_database @database = N'AdventureWorks' ,@backup_directory = N'c:\lsbackup' ,@backup_share = N'\\tribeca\lsbackup' ,@backup_job_name = N'LSBackup_AdventureWorks' ,@backup_retention_period = 1440 ,@monitor_server = N'rockaway' ,@monitor_server_security_mode = 1 ,@backup_threshold = 60 ,@threshold_alert = 0 ,@threshold_alert_enabled = 0 ,@history_retention_period = 1440 ,@backup_job_id = @LS_BackupJobId OUTPUT ,@primary_id = @LS_PrimaryId OUTPUT ,@overwrite = 1 ,@backup_compression = 0 GO
