sp_add_log_shipping_secondary_database (Transact-SQL)

为日志传送设置辅助数据库。

主题链接图标Transact-SQL 语法约定

语法

sp_add_log_shipping_secondary_database
[ @secondary_database = ] 'secondary_database',
[ @primary_server = ] 'primary_server', 
[ @primary_database = ] 'primary_database',
[, [ @restore_delay = ] 'restore_delay']
[, [ @restore_all = ] 'restore_all']
[, [ @restore_mode = ] 'restore_mode']
[, [ @disconnect_users = ] 'disconnect_users']
[, [ @block_size = ] 'block_size']
[, [ @buffer_count = ] 'buffer_count']
[, [ @max_transfer_size = ] 'max_transfer_size']
[, [ @restore_threshold = ] 'restore_threshold'] 
[, [ @threshold_alert = ] 'threshold_alert'] 
[, [ @threshold_alert_enabled = ] 'threshold_alert_enabled'] 
[, [ @history_retention_period = ] 'history_retention_period']

参数

  • [ @secondary_database = ] 'secondary_database'
    辅助数据库的名称。secondary_database 的数据类型为 sysname,无默认值。

  • [ @primary_server = ] 'primary_server'
    日志传送配置中 MicrosoftSQL Server 数据库引擎的主实例的名称。primary_server 的数据类型为 sysname,不能为 NULL。

  • [ @primary_database = ] 'primary_database'
    主服务器上的数据库的名称。primary_database 的数据类型为 sysname,无默认值。

  • [ @restore_delay = ] 'restore_delay'
    在还原给定备份文件前辅助服务器等待的时间(分钟)。restore_delay 的数据类型为 int,且不能为 NULL。默认值为 0。

  • [ @restore_all = ] 'restore_all'
    如果设置为 1,则在运行还原作业时,辅助服务器将还原所有可用的事务日志备份。否则,辅助服务器将在还原一个文件后停止。restore_all 的数据类型为 bit,且不能为 NULL。

  • [ @restore_mode = ] 'restore_mode'
    辅助数据库的还原模式。

    0 = 使用 NORECOVERY 还原日志。

    1 = 使用 STANDBY 还原日志。

    restore 的数据类型为 bit,且不能为 NULL。

  • [ @disconnect_users = ] 'disconnect_users'
    如果设置为 1,则在执行还原操作时,会断开用户与辅助数据库的连接。默认值为 0。disconnect_users 的数据类型为 bit,且不能为 NULL。

  • [ @block_size = ] 'block_size'
    用作备份设备的块大小(字节)。block_size 的数据类型为 int,默认值为 -1。

  • [ @buffer_count = ] 'buffer_count'
    备份或还原操作使用的缓冲区总数。buffer_count 的数据类型为 int,默认值为 -1。

  • [ @max_transfer_size = ] 'max_transfer_size'
    由 SQL Server 向备份设备发出的最大输入或输出请求的大小(字节)。max_transfersize 的数据类型为 int,可以为 NULL。

  • [ @restore_threshold = ] 'restore_threshold'
    两次还原操作之间允许的间隔时间(分钟),一旦超过此值,就会生成警报。restore_threshold 的数据类型为 int,且不能为 NULL。

  • [ @threshold_alert = ] 'threshold_alert'
    超过备份阈值时引发的警报。threshold_alert 的数据类型为 int,默认值为 14,420。

  • [ @threshold_alert_enabled = ] 'threshold_alert_enabled'
    指定超过 backup_threshold 时,是否引发警告。默认值一 (1) 表示引发警报。threshold_alert_enabled 的数据类型为 bit

  • [ @history_retention_period = ] 'history_retention_period'
    保持历史记录的时间长度(分钟)。history_retention_period 的数据类型为 int,默认值为 NULL。如果未指定值,则使用值 14420。

返回代码值

0(成功)或 1(失败)

结果集

注释

sp_add_log_shipping_secondary_database 必须从辅助服务器的 master 数据库中运行。此存储过程执行以下操作:

  1. 应在该存储过程之前调用 sp_add_log_shipping_secondary_primary,以初始化辅助服务器中的主日志传送数据库信息。

  2. 使用提供的参数在 log_shipping_secondary_databases 中为辅助数据库添加条目。

  3. 使用提供的参数在辅助服务器的 log_shipping_monitor_secondary 中添加本地监视记录。

  4. 若监视服务器和辅助服务器不同,则使用提供的参数在监视服务器的 log_shipping_monitor_secondary 中添加监视记录。

权限

只有 sysadmin 固定服务器角色的成员才可以运行此过程。

示例

该示例演示了在主数据库 AdventureWorks 位于主服务器 TRIBECA 中时,使用 sp_add_log_shipping_secondary_database 存储过程将数据库 LogShipAdventureWorks 添加为日志传送配置中的辅助数据库。

EXEC master.dbo.sp_add_log_shipping_secondary_database 
@secondary_database = N'LogShipAdventureWorks' 
,@primary_server = N'TRIBECA' 
,@primary_database = N'AdventureWorks' 
,@restore_delay = 0 
,@restore_mode = 1 
,@disconnect_users = 0 
,@restore_threshold = 45   
,@threshold_alert_enabled = 0 
,@history_retention_period = 1440 
GO