Hero image for SQL Server Infrastructure & High Availability: RAID, Backup & DR

SQL Server Infrastructure & High Availability: RAID, Backup & DR

sql-server database infrastructure high-availability backup

Prerequisites: Understanding of SQL Server basics. This article focuses on DBA/Operations topics.

When your database serves millions of users, you need reliability, redundancy, and recovery. This is the infrastructure layer.


Part A: RAID — Protecting Against Disk Failure

1. What is RAID?

RAID (Redundant Array of Independent Disks) = Multiple disks working together for speed and/or safety.

RAID Array

Disk 1

Disk 2

Disk 3

Disk 4

Single Disk

1 Disk = 1 Point of Failure

2. RAID Levels Comparison

RAIDHow it WorksMin DisksCapacitySpeedFault ToleranceUse Case
RAID 0Striping only2100%⚡⚡⚡ Fast❌ NoneTemp/scratch
RAID 1Mirroring250%⚡ Normal✅ 1 diskOS drive
RAID 5Striping + parity3n-1 disks⚡⚡ Good✅ 1 diskGeneral use
RAID 6Striping + double parity4n-2 disks⚡ Medium✅ 2 disksCritical data, NAS
RAID 10Mirror + Stripe450%⚡⚡⚡ Fast✅ 1 per mirrorSQL Server
RAID 50RAID 5 + Striping6Varies⚡⚡ Good✅ 1 per RAID 5Large storage arrays
RAID 60RAID 6 + Striping8Varies⚡ Medium✅ 2 per RAID 6Enterprise storage

3. RAID Visual Explanation

RAID 0 (Striping) — Speed, No Safety

Disk 2

Disk 1

Data: A B C D E F G H

A, C, E, G

B, D, F, H

  • ✅ Read/Write speed: 2x (parallel access)
  • ❌ Any disk fails = ALL DATA LOST

RAID 1 (Mirroring) — Safety, Less Space

Mirror

Same Data

Data: A B C D

Disk 1: A B C D

Disk 2: A B C D

(Exact Copy)

  • ✅ One disk fails? The other has everything
  • ❌ Lose 50% capacity

RAID 5 (Striping + Parity) — Balanced

RAID 5 Array

Disk 1

A1, B2, Cp

Disk 2

A2, Bp, C1

Disk 3

Ap, B1, C2

p = Parity

(Can rebuild)

  • ✅ Any ONE disk can fail, data survives
  • ⚠️ Rebuild is slow and stresses remaining disks
  • ⚠️ Write Penalty: Slower writes due to parity calculation. Not recommended for write-heavy OLTP systems.

RAID 6 (Double Parity) — Extra Protection

RAID 6 Array (4+ disks)

Disk 1

A1, B2, Cp, Dq

Disk 2

A2, Bp, Cq, D1

Disk 3

Ap, Bq, C1, D2

Disk 4

Aq, B1, C2, Dp

p, q = Two Parity Blocks

(Different algorithms)

  • ✅ Any TWO disks can fail simultaneously, data survives
  • ⚠️ Write performance lower than RAID 5 (double parity calculation)
  • 📦 Popular for NAS and backup storage

RAID 10 (Mirror + Stripe) — Best for SQL Server

Mirror Set 2

Mirror Set 1

Mirror

Mirror

Disk 1

A, C

Disk 2

A, C

Disk 3

B, D

Disk 4

B, D

Striped Data

RAID 10 Advantages:

  • ✅ Fast reads AND writes
  • ✅ Can lose 1 disk per mirror
  • ❌ Need minimum 4 disks, 50% capacity

Microsoft recommends RAID 10 for SQL Server data files

RAID 10 Architecture

4. SQL Server & RAID Best Practices

File TypeRecommended RAIDReason
Data files (.mdf)RAID 10Heavy random I/O
Log files (.ldf)RAID 1 or RAID 10Sequential writes, critical
TempDBRAID 10 or RAID 0*High I/O, can recreate
BackupsRAID 5 or RAID 6Large sequential reads

*RAID 0 only if tempdb can be recreated on restart

☁️ Cloud Context: In cloud environments (AWS EBS, Azure Managed Disk), RAID is typically handled at the infrastructure layer. You focus on selecting IOPS and Throughput tiers instead of managing disk arrays directly.


Part B: Backup Strategies

5. Why Backup?

RAID protects against disk failure, but NOT against:

  • ❌ Accidental DELETE
  • ❌ Ransomware encryption
  • ❌ Application bugs corrupting data
  • ❌ Natural disasters

Backup = Your last line of defense

6. Backup Types

Backup Types

Daily

Hourly

Every 15 min

Full Backup

Differential

Transaction Log

TypeContainsSizeRestore Need
FullEntire databaseLargeJust this backup
DifferentialChanges since last FullMediumFull + this Diff
Transaction LogChanges since last LogSmallFull + all Logs

7. Backup Commands

-- 0. Integrity Check (Critical!)
-- Check for corruption BEFORE backing up
DBCC CHECKDB(MyDB) WITH NO_INFOMSGS;

-- 1. Full backup:
BACKUP DATABASE MyDB 
TO DISK = 'D:\Backups\MyDB_Full.bak'
WITH COMPRESSION, INIT, CHECKSUM;
-- CHECKSUM ensures page integrity during backup

-- 2. Differential backup:
BACKUP DATABASE MyDB 
TO DISK = 'D:\Backups\MyDB_Diff.bak'
WITH DIFFERENTIAL, COMPRESSION, CHECKSUM;

-- 3. Transaction log backup:
-- IMPORTANT: This truncates the log, allowing space reuse
BACKUP LOG MyDB 
TO DISK = 'D:\Backups\MyDB_Log.trn'
WITH COMPRESSION;

⚠️ Why DBCC CHECKDB First?

If you backup a corrupted database, your backup is also corrupted. Run DBCC CHECKDB regularly (weekly minimum) to catch corruption early.

📋 Log Truncation Explained

In Full Recovery Model, the transaction log grows forever until you back it up. BACKUP LOG marks old log records as reusable (“truncates” the log). This is why Full Recovery requires regular log backups — or your disk fills up!

8. Common Backup Strategies

Backup Strategies Overview

Simple Strategy (Small DBs)

Sunday: Full
Monday-Saturday: Full (daily)

Standard Strategy (Most DBs)

Sunday 12AM: Full
Mon-Sat 12AM: Differential
Every hour: Transaction Log

Enterprise Strategy (Mission-Critical)

Sunday 12AM: Full
Daily 12AM: Differential
Every 15 minutes: Transaction Log
Copy to offsite storage: Daily

9. Recovery Models

ModelLog Backup Possible?Point-in-Time Restore?Use Case
Simple❌ No❌ NoDev/Test
Full✅ Yes✅ YesProduction
Bulk-Logged✅ Yes⚠️ LimitedETL periods
-- Check recovery model:
SELECT name, recovery_model_desc FROM sys.databases;

-- Change recovery model:
ALTER DATABASE MyDB SET RECOVERY FULL;

10. Point-in-Time Recovery

-- Restore to specific time (requires FULL recovery model):
RESTORE DATABASE MyDB FROM DISK = 'MyDB_Full.bak' WITH NORECOVERY;
RESTORE LOG MyDB FROM DISK = 'MyDB_Log1.trn' WITH NORECOVERY;
RESTORE LOG MyDB FROM DISK = 'MyDB_Log2.trn' 
WITH STOPAT = '2024-03-15 14:30:00', RECOVERY;

Part C: Replication — Keeping Copies in Sync

11. Types of Replication

Replication Types

Snapshot

Transactional

Merge

Publisher

Subscriber

Subscriber

Subscriber

TypeHow it WorksLatencyUse Case
SnapshotPeriodic full copyHigh (minutes-hours)Reporting, rarely changed
TransactionalStream changes in near-real-timeLow (seconds)Read replicas
MergeBi-directional syncMediumMobile/disconnected

12. Transactional Replication Flow

Subscriber(Copy)Distributor(Queue)Publisher(Main DB)Subscriber(Copy)Distributor(Queue)Publisher(Main DB)1. Log Reader reads transaction log2. Store in distribution DB3. Distribution Agent pushes changesApply changes

Part D: Always On Availability Groups — Enterprise HA

13. What is Always On AG?

Always On Availability Groups = Multiple database replicas with automatic failover.

Always On Availability Group Architecture

Secondary Replicas

Primary Replica

Synchronous

Asynchronous

SQL Server 1

Read/Write

SQL Server 2

Read-Only

SQL Server 3

Read-Only

Listener: ag-listener.company.com

14. Sync vs Async Mode

ModeCommit BehaviorData Loss on FailoverLatencyUse Case
SynchronousWait for secondary to confirm❌ None (zero data loss)HigherSame datacenter
AsynchronousDon’t wait⚠️ PossibleLowerDR site (different city)

15. Failover Types

TypeTriggerDowntime
AutomaticPrimary failure detectedSeconds (30-60s typical)
Manual PlannedDBA initiatesSeconds
ForcedPrimary unreachablePotential data loss

15.1 Always On AG vs Failover Cluster Instance (FCI)

FeatureAlways On AGFailover Cluster Instance
ArchitectureShared-NothingShared-Storage
Data StorageEach node has own copySingle shared disk
Storage CostHigher (N copies)Lower (1 copy)
Failover ScopePer-databaseEntire instance
Read from Secondary✅ Yes❌ No
Requires SAN❌ No✅ Yes

When to choose?

  • AG: Modern choice. Better for DR across datacenters, readable secondaries, per-database control.
  • FCI: Legacy or when shared storage (SAN) already exists. Simpler but less flexible.

Part E: Disaster Recovery (DR)

16. Key Metrics: RTO and RPO

MetricMeaningQuestion
RTORecovery Time ObjectiveHow fast must we recover?
RPORecovery Point ObjectiveHow much data can we lose?
ScenarioRTORPOSolution
E-commerce1 hour5 minAlways On + Log shipping
Banking00Synchronous Always On
Archive system24 hours1 dayDaily backup to cloud

17. DR Strategy Tiers

Tier 4: Active-Active

Tier 3: Hot Standby

Tier 2: Warm Standby

Tier 1: Backup Only

Backup to tape/cloud

RTO: Hours-Days | RPO: Last backup

Log shipping to secondary

RTO: 1-4 hours | RPO: 15 min

Always On AG (async)

RTO: Minutes | RPO: Near-zero

Distributed AG

RTO: Seconds | RPO: Zero

18. Log Shipping — Simple DR

-- On Primary:
BACKUP LOG MyDB TO DISK = '\\FileShare\Logs\MyDB_Log.trn';

-- Copy job runs every 15 minutes to secondary

-- On Secondary:
RESTORE LOG MyDB FROM DISK = '\\FileShare\Logs\MyDB_Log.trn' 
WITH STANDBY = 'MyDB_Undo.ldf';

Summary: When to Use What

Technology Selection

RequirementSolution
Protect against disk failureRAID 10
Recover from accidental DELETEBackup + Point-in-time restore
Read replicas for reportingTransactional replication or AG
Automatic failover (same DC)Always On AG (synchronous)
DR site in another cityAlways On AG (async) or Log Shipping
Zero data loss requirementSynchronous Always On + SAN replication

Cost vs Protection

LevelComponentsCost
BasicRAID + Daily backup$
Standard+ Differential + Log backups$$
Professional+ Replication or Log Shipping$$$
Enterprise+ Always On AG + DR site$$$$
Mission Critical+ Active-Active + SAN replication$$$$$

Quick Reference: Backup Strategy

Small DB (< 10 GB):
  └── Full backup daily

Medium DB (10-100 GB):
  └── Full weekly + Diff daily + Log hourly

Large DB (100 GB+):
  └── Full weekly + Diff daily + Log every 15 min

Critical DB:
  └── Full weekly + Diff daily + Log every 5 min + Offsite copy

💡 Practice Questions

Conceptual

  1. Compare RAID 5, RAID 6, and RAID 10. Which would you use for SQL Server data files and why?

  2. Explain the difference between Full, Differential, and Transaction Log backups. How do they work together?

  3. What is the difference between Replication and Always On Availability Groups?

  4. Define RPO and RTO. How do they influence your backup/DR strategy?

Hands-on

-- Design a backup strategy for a 50GB database with RPO of 15 minutes and RTO of 1 hour.
-- List: backup types, frequencies, and retention period.
💡 View Answer

Backup Strategy:

  • Full backup: Weekly (Sunday night)
  • Differential backup: Daily (every night)
  • Transaction log backup: Every 15 minutes

Retention:

  • Keep 4 weeks of full backups
  • Keep 7 days of differential backups
  • Keep 24 hours of log backups

Recovery scenario (RTO < 1 hour):

  1. Restore latest full backup (~20 min for 50GB)
  2. Restore latest differential (~10 min)
  3. Restore transaction logs up to failure point (~10 min)
  4. Total: ~40 minutes ✅

Scenario

  1. Disaster Planning: Your company’s main datacenter loses power. You have an Always On Availability Group with a secondary in another city. Walk through the failover process.

  2. Capacity Planning: A database is growing 10GB per month. Current RAID 10 array is 80% full. What would you recommend?