Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> ฐานข้อมูล

Log Shipping สำหรับ SQL Server AlwaysOn Databases ที่มีอยู่: Practical DR Guide

บทนำ

Post อธิบายวิธี Setup Log Shipping ซึ่งเป็น Disaster Recovery (DR) Solution กับ Existing Microsoft® SQL Server® AlwaysOn-configured Databases

Introduction

AlwaysOn Availability Group (AG) Feature เป็น High-availability และ Disaster Recovery Solution ให้ Enterprise-level Alternative แทน Database Mirroring Introduced ใน SQL Server 2012 (11.x) AlwaysOn AGs Maximize Availability ของ User Databases Set สำหรับ Enterprise AGs Support Failover Environment สำหรับ Discrete Set ของ User Databases (Availability Databases) ที่ Failover Together รองรับ Read-write Primary Databases 1 Set และ Secondary Databases 1-8 Sets Optionally AGs ทำให้ Secondary Databases Available สำห Read-only Access และ Backup Operations บางอย่าง

SQL Server Log Shipping Enable Auto Send Transaction Log Backups จาก Primary Database บน Primary Server Instance ไป Secondary Databases บน Separate Secondary Server Instances Transaction Log Backups ถูก Apply ให้แต่ละ Secondary Database แยกกัน

Reasons Why You Might Need AlwaysOn Log Shipping

Assume ว่า Already Configured AlwaysOn ระหว่าง Primary Replica Server และ Secondary Replica และ AlwaysOn ใช้ใน Main Data Center อาจต้องใช้ Log Shipping ถ้าไม่สามารถ Expand Required Windows Server Failover Cluster (WSFC) Config ไป DR Site เหตุผล:

  • Infrastructure หรือ Staff ไม่ Maintain WSFC Configs ระหว่าง Different Sites ได้
  • ไม่ Leverage Target Server ใน DR Site ใน WSFC Config เพราะมัน Already Part ของ WSFC Config อื่น
  • Service Level Agreements (SLAs) บน Recovery Point Objective (RPO) และ Recovery Time Objective (RTO) บังคับ Fast Recovery จาก Manual Error ซึ่ง Realize ได้เฉพาะด้วย Delayed Recovery Restoring Transaction Log Backups บน 1 Instance ของ HA และ DR Strategy

ดังนั้น ต้อง Supply Target Server ใน DR Site ด้วย Log Shipping Ship Transaction Log จาก Backups ใน Main Site บน Current Primary

Prerequisites สำหรับ Log Shipping

ก่อน Setup Log Shipping Ensure Meet Prerequisites:

  • Primary Database ต้องใช้ Full หรือ Bulk-logged Recovery Model Switch เป็น Simple Recovery ทำให้ Log Shipping หยุดทำงาน
  • ก่อน Configure Log Shipping ต้อง Create Shared Path ให้ Transaction Log Backups Available ไป Secondary Server
  • Log-shipping Stored Procedures ต้องการ Membership ใน Sysadmin Fixed Server Role
  • Backup Shared Path ควรมี Read/Write Permissions ให้ SQL Server Service Account

Configure Log Shipping DR Solution Example

ใน Example Already Setup AlwaysOn ระหว่าง Primary Replica Server ชื่อ PRIMEHEAD และ Secondary Replica ชื่อ HEAD2

Log Shipping สำหรับ SQL Server AlwaysOn Databases ที่มีอยู่: Practical DR Guide

Section นี้ให้ Step-by-step Solution Configure Log Shipping บน Database ที่เป็นส่วนหนึ่งของ AlwaysOn AG แล้ว

Step 1

Configure Log Shipping สำหรับ Database AdventureWork2014 ระหว่าง PRIMEHEAD และ DR Server HEAD3

ขณะ Configure Log Shipping บน Database ให้ Full Backup AdventureWork2014 และ Restore บน HEAD3 ด้วย Non-recovery ต้อง Create Shared Folder บน PRIMEHEAD เก็บ Log Backup ที่ LSCopy (Log Shipping) Job ใช้

Step 2

Right-click Database Select Properties Click Transaction Log Shipping ด้านซ้ายของ PRIMEHEAD Click Checkbox Enable this as a primary database in a log shipping configuration

Log Shipping สำหรับ SQL Server AlwaysOn Databases ที่มีอยู่: Practical DR Guide

Step 3

Click Backup Setting Configure LS Backup Option Select Network-shared Path สำหรับ LS Backup

Log Shipping สำหรับ SQL Server AlwaysOn Databases ที่มีอยู่: Practical DR Guide

Step 4

จุดนี้ Schedule LS Backup ตาม Requirements แต่ใน Scenario ใช้ Default Settings

Step 5

เพิ่ม DR Server Click Add

Log Shipping สำหรับ SQL Server AlwaysOn Databases ที่มีอยู่: Practical DR Guide

Step 6

Click Connect Connect ไป HEAD3 DR Server

Log Shipping สำหรับ SQL Server AlwaysOn Databases ที่มีอยู่: Practical DR Guide

Step 7

Tab Initialize Secondary Database Select Option ที่ 3 เพราะ Database Initialized บน HEAD3 แล้ว

Step 8

Click Tab Copy Files ใน Box Destination folder for copied files Type Path ที่ Transaction Log Backups ถูก Copy สำหรับ Scenario ใช้ C:\LSCopyAlwaysOn

Log Shipping สำหรับ SQL Server AlwaysOn Databases ที่มีอยู่: Practical DR Guide

Step 9

Tab Restore Transaction Log Under Database state when restoring backups เลือก No recovery mode หรือ Standby mode

Example เลือก No recovery mode หมายถึง DR Database ไม่ Accessible ถ้าเลือก Standby Mode DR Database Available ให้ End User ใน Read-only Mode

Log Shipping สำหรับ SQL Server AlwaysOn Databases ที่มีอยู่: Practical DR Guide

Step 10

Click OK เริ่ม Log Shipping

Log Shipping สำหรับ SQL Server AlwaysOn Databases ที่มีอยู่: Practical DR Guide

Screen แสดง:

Log Shipping สำหรับ SQL Server AlwaysOn Databases ที่มีอยู่: Practical DR Guide

Step 11

Check Log Shipping Status Right-click DR Server HEAD3 Instances Select Reports -> Standard Reports -> Transactional Log Shipping Status ถ้า Screen ต่อไปปรากฏ Log Shipping Healthy และ Working As Expected

Log Shipping สำหรับ SQL Server AlwaysOn Databases ที่มีอยู่: Practical DR Guide

ถ้า AG Failover ระหว่าง PRIMEHEAD และ HEAD2 เกิดขึ้น Log Shipping Interrupted จนกว่า Configure ตาม AG Specifications

ตอนนี้ Configure Log Shipping จาก HEAD2 ไป HEAD3 ซึ่งจะไม่ Impact Log Shipping Functionality แม้ Failover ในอนาคตระหว่าง AG Replicas Log Backup จะเกิดขึ้นบน Same Path/Location เสมอ ไม่ว่า Replica ไหนเป็น Primary

ต้อง Initiate Failover ระหว่าง Replicas ก่อน Initiate Failover Complete Steps:

  1. Execute LS Backup Job บน Primary Replica และ Disable Job
  2. Execute LS Copy และ Restore Job บน Secondary Replica แล้ว Disable It

Right-click AG Select Failover Option

Log Shipping สำหรับ SQL Server AlwaysOn Databases ที่มีอยู่: Practical DR Guide

หรือใช้ T-SQL Commands Trigger AG Failover แบบ Manual:

USE master; GO
ALTER AVAILABILITY GROUP [AGName] FAILOVER GO

หลัง Failover Complete Window แสดง:

Log Shipping สำหรับ SQL Server AlwaysOn Databases ที่มีอยู่: Practical DR Guide

Step 12

หลัง AG Failover ระหว่าง PRIMEHEAD และ HEAD2 Current Primary Instance คือ HEAD2

Follow Same Steps Configure Log Shipping จาก Current Primary Server/Node HEAD2 ไป DR Server HEAD3 ขณะ Configure เลือก Same Shared Path ที่ใช้ตอน LS Config ระหว่าง PRIMEHEAD และ HEAD3 คือ \Avail2017\lsbackup

Step 13

หลัง Log Shipping ระหว่าง HEAD2 (Current Primary) และ HEAD3 Complete LS Backup Job สร้างบน HEAD2 และ Another Set ของ LS Copy และ LS Restore Jobs สร้างบน HEAD3

Initiate Failover ระหว่าง AG Replicas อีกครั้ง ก่อน Initiate Ensure Complete Steps:

  1. Execute LS Backup Job บน Primary (HEAD2) และ Disable Job
  2. Execute LS Copy และ Restore Job บน Secondary (HEAD3) แล้ว Disable It

Step 14

หลัง Final Failover Current Primary คือ PRIMEHEAD HEAD2 คือ Secondary Replica HEAD3 คือ DR Server เพราะ LS Backup Jobs มีอยู่ทั้ง 2 Servers (Primary และ Secondary) ต้อง Modify LS Backup Job บน PRIMEHEAD และ HEAD2 ให้ Ensure ว่ามัน Take Log Backup จาก Current Primary เท่านั้น

เพิ่ม Code นี้ใน Job Step 1:

Declare @dbname as varchar(20)
Set @dbname='AdventureWorks2014'
If sys.fn_hadr_backup_is_preferred_replica (@dbname)<>1
begin
RAISERROR (50005,-- Message id,
16, -- Severity,
1, --State,
N'This is not the primary server backup is rolled back');
end

ภาพประกอบ:

Log Shipping สำหรับ SQL Server AlwaysOn Databases ที่มีอยู่: Practical DR Guide

หลังแก้ไข LS Backup Job จะ Fail บน Secondary Server แต่ Run Fine บน Primary

Step 15

เพราะมี 2 Sets ของ LS Copy และ Restore Jobs บน HEAD3 DR Server ต้อง Ensure ว่า Only One Set Runs At a Time Keep Jobs Enabled ที่สร้างตอน Configure Log Shipping ระหว่าง HEAD2 และ HEAD3 และ Disable อีก Set

ภาพรายละเอียด:

Log Shipping สำหรับ SQL Server AlwaysOn Databases ที่มีอยู่: Practical DR Guide

ตอนนี้ Configure Log Shipping บน Database ที่เป็นส่วนหนึ่งของ AlwaysOn AG สำเร็จแล้ว ไม่ว่า Server ไหนทำงานเป็น Primary Log Shipping จะ In Sync

Note: แนะนำอย่างยิ่งอย่าเปลี่ยนแปลง Production โดยไม่ Test ก่อน Implement Solution นี้ใน Production ให้ Implement Config ใน Test Environment ก่อน

Validation:

a) Ensure Backup Job Running Successfully บน Current Primary Replica b) Backup Path ตรงกับ Shared Path c) Copy และ Restore Jobs ที่สร้างตอน LS Config จาก HEAD2 ไป HEAD3 ควร Run Properly บน DR Server d) Check Transactional Log Shipping Status ใน Standard Report Section

สรุป

Configure Log Shipping บน Highly Available Database ให้ DR Server Setup ใน Different Data Center Setup นี้ช่วยกรณี Disaster และทำให้ Business Unaffected ด้วย Minimal Manual Effort แม้ Servers ใน Data Center อื่น Impact

ใช้แท็บ Feedback เพื่อแสดงความคิดเห็นหรือถามคำถาม

เพิ่มประสิทธิภาพสภาพแวดล้อมด้วยบริการผู้เชี่ยวชาญ

ผู้เชี่ยวชาญ Rackspace Application Services (RAS) ให้บริการ Professional และ Managed Services ครอบคลุม Portfolio หลากหลาย:

  • Platform สำหรับ eCommerce และ Digital Experience
  • Enterprise Resource Planning (ERP)
  • Business Intelligence
  • Salesforce Customer Relationship Management (CRM)
  • Databases
  • Email Hosting และ Productivity

เรามอบ:

  • Unbiased Expertise: ลดความซับซ้อนและนำทางการ Modernization เน้นความสามารถที่สร้างคุณค่าทันที
  • Fanatical Experience™: รวมแนวทาง Process First. Technology Second.® พร้อม Technical Support ให้ Soluation ครบวงจร
  • Unrivaled Portfolio: ประยุกต์ประสบการณ์ Cloud มากมายช่วยเลือกและ Deploy เทคโนโลยีที่เหมาะสมบน Cloud ที่เหมาะสม
  • Agile Delivery: ตรงจุดที่คุณอยู่ในการเดินทางและทำให้ความสำเร็จของเราสอดคล้องกับคุณ

แชทตอนนี้เพื่อเริ่มต้น