sp_change_log_shipping_primary_database (Transact-SQL)

更改主数据库设置。

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

语法

sp_change_log_shipping_primary_database [ @database = ] 'database'
[, [ @backup_directory = ] 'backup_directory'] 
[, [ @backup_share = ] 'backup_share'] 
[, [ @backup_retention_period = ] 'backup_retention_period']
[, [ @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_compression = ] backup_compression_option ] 

参数

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

  • [ @backup_directory = ] 'backup_directory'
    主服务器上备份文件夹的路径。backup_directory 的数据类型为 nvarchar(500),无默认值,且不能为 NULL。

  • [ @backup_share = ] 'backup_share'
    主服务器上备份目录的网络路径。backup_share 的数据类型为 nvarchar(500),无默认值,且不能为 NULL。

  • [ @backup_retention_period = ] 'backup_retention_period'
    在主服务器上的备份目录中保留日志备份文件的时间长度(分钟)。backup_retention_period 的数据类型为 int,无默认值,且不能为 NULL。

  • [ @monitor_server_security_mode = ] 'monitor_server_security_mode'
    连接到监视服务器所用的安全模式。

    1 = Windows 身份验证。

    0 = SQL Server 身份验证。

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

  • [ @monitor_server_login = ] 'monitor_server_login'
    访问监视服务器所用的帐户的用户名。

  • [ @monitor_server_password = ] 'monitor_server_password'
    访问监视服务器所用的帐户的密码。

  • [ @backup_threshold = ] 'backup_threshold'
    从上一次备份到引发 threshold_alert 错误前的时间(分钟)。backup_threshold 的数据类型为 int,默认值为 60 分钟。

  • [ @threshold_alert = ] 'threshold_alert'
    超过备份阈值时引发的警报。threshold_alert 的数据类型为 int,且不能为 NULL。

  • [ @threshold_alert_enabled = ] 'threshold_alert_enabled'
    指定超过 backup_threshold 时,是否引发警告。

    1 = 启用。

    0 = 禁用。

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

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

  • [ @backup_compression = ] backup_compression_option
    指定日志传送配置是否使用备份压缩。只有 SQL Server 2008 Enterprise(或更高版本)支持此参数。

    0 = 禁用。从不压缩日志备份。

    1 = 启用。始终压缩日志备份。

    2 = 使用备份压缩默认值服务器配置选项的设置。此为默认值。

返回代码值

0(成功)或 1(失败)

结果集

注释

必须从主服务器上的 master 数据库运行 sp_change_log_shipping_primary_database。此存储过程执行以下操作:

  1. 根据需要更改 log_shipping_primary_database 记录中的设置。

  2. 根据需要,使用提供的参数更改主服务器上 log_shipping_monitor_primary 中的本地记录。

  3. 如果监视服务器不是主服务器,根据需要使用提供的参数更改监视服务器上 log_shipping_monitor_primary 中的记录。

权限

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

示例

此示例将阐释如何使用 sp_change_log_shipping_primary_database 更新与主数据库 AdventureWorks 关联的设置。

EXEC master.dbo.sp_change_log_shipping_primary_database 
 @database = N'AdventureWorks' 
, @backup_directory = N'c:\LogShipping' 
, @backup_share = N'\\tribeca\LogShipping' 
, @backup_retention_period = 1440 
, @backup_threshold = 60 
, @threshold_alert = 0 
, @threshold_alert_enabled = 1 
, @history_retention_period = 1440 
,@monitor_server_security_mode = 1
,@backup_compression = 1