sp_addpublication_스냅샷(Transact-SQL)

적용 대상:SQL ServerAzure SQL Managed Instance

지정된 발행물의 스냅샷 에이전트 만듭니다. 이 저장 프로시저는 게시 데이터베이스의 게시자에서 실행됩니다.

Important

원격 배포자를 사용하여 게시자를 구성할 때 job_login 및 job_password 비롯한 모든 매개 변수에 제공된 값은 일반 텍스트로 배포자로 전송됩니다. 이 저장 프로시저를 실행하기 전에 게시자와 해당 원격 배포자 간의 연결을 암호화해야 합니다. 자세한 내용은 연결 암호화를 위한 SQL Server 데이터베이스 엔진 구성을 참조하세요.

Transact-SQL 구문 표기 규칙

구문

sp_addpublication_snapshot
    [ @publication = ] N'publication'
    [ , [ @frequency_type = ] frequency_type ]
    [ , [ @frequency_interval = ] frequency_interval ]
    [ , [ @frequency_subday = ] frequency_subday ]
    [ , [ @frequency_subday_interval = ] frequency_subday_interval ]
    [ , [ @frequency_relative_interval = ] frequency_relative_interval ]
    [ , [ @frequency_recurrence_factor = ] frequency_recurrence_factor ]
    [ , [ @active_start_date = ] active_start_date ]
    [ , [ @active_end_date = ] active_end_date ]
    [ , [ @active_start_time_of_day = ] active_start_time_of_day ]
    [ , [ @active_end_time_of_day = ] active_end_time_of_day ]
    [ , [ @snapshot_job_name = ] N'snapshot_job_name' ]
    [ , [ @publisher_security_mode = ] publisher_security_mode ]
    [ , [ @publisher_login = ] N'publisher_login' ]
    [ , [ @publisher_password = ] N'publisher_password' ]
    [ , [ @job_login = ] N'job_login' ]
    [ , [ @job_password = ] N'job_password' ]
    [ , [ @publisher = ] N'publisher' ]
    [ , [ @distributor_security_mode = ] distributor_security_mode ]
    [ , [ @distributor_login = ] N'distributor_login' ]
    [ , [ @distributor_password = ] N'distributor_password' ]
[ ; ]

인수

[ @publication = ] N'publication'

게시의 이름입니다. @publication 기본값이 없는 sysname입니다.

[ @frequency_type = ] frequency_type

스냅샷 에이전트 실행되는 빈도입니다. @frequency_type int이며 다음 값 중 하나일 수 있습니다.

설명
1 한 번
4 (기본값) 매일
8 매주
16 매월
32 매월 빈도 간격을 기준으로 합니다.
64 SQL Server 에이전트 시작하는 경우
128 컴퓨터가 유휴 상태일 때 실행

[ @frequency_interval = ] frequency_interval

@frequency_type 설정된 빈도에 적용할 값입니다. @frequency_interval int이며 다음 값 중 하나일 수 있습니다.

frequency_type 값 frequency_interval 영향
1 @frequency_interval 사용되지 않습니다.
4 (기본값) @frequency_interval 일마다, 기본값은 매일입니다.
8 @frequency_interval 다음 중 하나 이상입니다(| (비트 OR) 논리 연산자:

1 = 일요일 |

2 = 월요일 |

4 = 화요일 |

8 = 수요일 |

16 = 목요일 |

32 = 금요일 |

64 = 토요일
16 해당 월의 @frequency_interval 일입니다.
32 @frequency_interval 다음 값 중 하나입니다.

1 = 일요일 |

2 = 월요일 |

3 = 화요일 |

4 = 수요일 |

5 = 목요일 |

6 = 금요일 |

7 = 토요일 |

8 = 일 |

9 = 평일 |

10 = 주말
64 @frequency_interval 사용되지 않습니다.
128 @frequency_interval 사용되지 않습니다.

[ @frequency_subday = ] frequency_subday

freq_subday_interval 단위입니다. @frequency_subday int이며 이러한 값 중 하나일 수 있습니다.

설명
1 한 번
2 둘째
4 (기본값) Minute
8 Hour

[ @frequency_subday_interval = ] frequency_subday_interval

frequency_subday 간격(분)입니다. @frequency_subday_interval 기본값5int입니다.

[ @frequency_relative_interval = ] frequency_relative_interval

스냅샷 에이전트 실행되는 날짜입니다. @frequency_relative_interval 기본값1int입니다.

[ @frequency_recurrence_factor = ] frequency_recurrence_factor

frequency_type 사용되는 되풀이 요소입니다. @frequency_recurrence_factor 기본값0인 int입니다.

[ @active_start_date = ] active_start_date

스냅샷 에이전트 처음 예약된 날짜로 형식이 지정됩니다yyyyMMdd. @active_start_date 기본값0int입니다.

[ @active_end_date = ] active_end_date

스냅샷 에이전트 예약이 중지된 날짜로, 형식은 다음과 같습니다yyyyMMdd. @active_end_date 9999년 12월 31일을 의미하는 기본값99991231인 int입니다.

[ @active_start_time_of_day = ] active_start_time_of_day

스냅샷 에이전트 처음 예약된 시간이며 형식은 다음과 같습니다HHmmss. @active_start_time_of_day 기본값0인 int입니다.

[ @active_end_time_of_day = ] active_end_time_of_day

스냅샷 에이전트 예약이 중지되고 형식이 HHmmss지정된 하루 중 시간입니다. @active_end_time_of_day 기본값235959인 int입니다. 즉, 24시간 시계에서 측정된 대로 오후 11시 59분 59분입니다.

[ @snapshot_job_name = ] N'스냅샷_job_name'

기존 작업이 사용되는 경우 기존 스냅샷 에이전트 작업 이름의 이름입니다. @스냅샷_job_name 기본값NULL은 nvarchar(100)입니다. 이 매개 변수는 내부용이며 새 게시를 만들 때 지정해서는 안 됩니다. @스냅샷_agent_name 지정한 경우 @job_login @job_password합니다.NULL

[ @publisher_security_mode = ] publisher_security_mode

참고 항목

Microsoft Entra ID 는 이전에 Azure AD(Azure Active Directory)라고 했습니다.

게시자에 연결할 때 에이전트가 사용하는 보안 모드입니다. @publisher_security_mode 기본값1int입니다. SQL Server가 아닌 게시자에 대해 값을 0 지정해야 합니다. 가능하면 Windows 인증 사용합니다. 다음 값은 보안 모드를 정의합니다.

  • 0 는 SQL Server 인증을 지정합니다.
  • 1는 Windows 인증 지정합니다.
  • 2 는 SQL Server 2022(16.x) CU 6부터 Microsoft Entra 암호 인증을 지정합니다.
  • 3 는 SQL Server 2022(16.x) CU 6부터 Microsoft Entra 통합 인증을 지정합니다.
  • 4 는 SQL Server 2022(16.x) CU 6부터 Microsoft Entra 토큰 인증을 지정합니다.

[ @publisher_login = ] N'publisher_login'

게시자에 연결할 때 사용되는 로그인입니다. @publisher_login sysname이며 기본값은 .입니다NULL. @publisher_security_mode 경우 @publisher_login0지정해야 합니다. @publisher_loginNULL @publisher_security_mode 1경우 @job_login 지정된 계정은 게시자에 연결할 때 사용됩니다.

[ @publisher_password = ] N'publisher_password'

게시자에 연결할 때 사용되는 암호입니다. @publisher_password sysname이며 기본값은 .입니다NULL.

Important

스크립트 파일에 인증 정보를 저장하지 마세요. 보안 향상을 위해 런타임에 로그인 이름과 암호를 제공하는 것이 좋습니다.

[ @job_login = ] N'job_login'

에이전트가 실행되는 계정에 대한 로그인입니다. Azure SQL Managed Instance에서 SQL Server 계정을 사용합니다. @job_login 기본값NULL인 nvarchar(257)입니다. 이 계정은 항상 배포자에 대한 에이전트 연결에 사용됩니다. 새 스냅샷 에이전트 작업을 만들 때 이 매개 변수를 제공해야 합니다.

SQL Server가 아닌 게시자의 경우 sp_adddistpublisher(Transact-SQL)지정된 것과 동일한 로그인이어야 합니다.

[ @job_password = ] N'job_password'

에이전트가 실행되는 Windows 계정의 암호입니다. @job_password 기본값이 없는 sysname입니다. 새 스냅샷 에이전트 작업을 만들 때 이 매개 변수를 제공해야 합니다.

Important

스크립트 파일에 인증 정보를 저장하지 마세요. 보안 향상을 위해 런타임에 로그인 이름과 암호를 제공하는 것이 좋습니다.

[ @publisher = ] N'publisher'

SQL Server 이외 게시자를 지정합니다. @publisher sysname이며 기본값은 .입니다NULL.

@PUBLISHER SQL Server 게시자에서 스냅샷 에이전트 만들 때 사용하면 안 됩니다.

[ @distributor_security_mode = ] distributor_security_mode

정보를 제공하기 위해서만 확인됩니다. 지원 안 됨 향후 호환성은 보장되지 않습니다.

[ @distributor_login = ] N'distributor_login'

정보를 제공하기 위해서만 확인됩니다. 지원 안 됨 향후 호환성은 보장되지 않습니다.

[ @distributor_password = ] N'distributor_password'

정보를 제공하기 위해서만 확인됩니다. 지원 안 됨 향후 호환성은 보장되지 않습니다.

반환 코드 값

0 (성공) 또는 1 (실패).

설명

sp_addpublication_snapshot는 스냅샷 복제본(replica)tion, 트랜잭션 복제본(replica) 및 병합 복제본(replica)에 사용됩니다.

예제

-- To avoid storing the login and password in the script file, the values 
-- are passed into SQLCMD as scripting variables. For information about 
-- how to use scripting variables on the command line and in SQL Server
-- Management Studio, see the "Executing Replication Scripts" section in
-- the topic "Programming Replication Using System Stored Procedures".

DECLARE @publicationDB AS sysname;
DECLARE @publication AS sysname;
DECLARE @login AS sysname;
DECLARE @password AS sysname;
SET @publicationDB = N'AdventureWorks'; 
SET @publication = N'AdvWorksProductTran'; 
-- Windows account used to run the Log Reader and Snapshot Agents.
SET @login = $(Login); 
-- This should be passed at runtime.
SET @password = $(Password); 

-- Enable transactional or snapshot replication on the publication database.
EXEC sp_replicationdboption 
    @dbname=@publicationDB, 
    @optname=N'publish',
    @value = N'true';

-- Execute sp_addlogreader_agent to create the agent job. 
EXEC sp_addlogreader_agent 
    @job_login = @login, 
    @job_password = @password,
    -- Explicitly specify the use of Windows Integrated Authentication (default) 
    -- when connecting to the Publisher.
    @publisher_security_mode = 1;

-- Create a new transactional publication with the required properties. 
EXEC sp_addpublication 
    @publication = @publication, 
    @status = N'active',
    @allow_push = N'true',
    @allow_pull = N'true',
    @independent_agent = N'true';

-- Create a new snapshot job for the publication, using a default schedule.
EXEC sp_addpublication_snapshot 
    @publication = @publication, 
    @job_login = @login, 
    @job_password = @password,
    -- Explicitly specify the use of Windows Integrated Authentication (default) 
    -- when connecting to the Publisher.
    @publisher_security_mode = 1;
GO

사용 권한

sysadmin 고정 서버 역할 또는 db_owner 고정 데이터베이스 역할의 멤버만 실행할 sp_addpublication_snapshot수 있습니다.