Implementing Backup and Recovery

1. Understanding Backup Strategies

Strategy Description Detail
Replication RF is first defense Not backup
Mirror Cluster MM2 to remote DR copy
Sink to Storage S3/GCS connector Cold archive

Example: Why RF isn't backup

Bad delete/produce replicates instantly to all replicas.
Backup = independent point-in-time copy.

2. Backing Up Topic Data

Method Description Detail
S3 Sink Stream to object store Connector
Partitioning By time/field Restorable
Format Avro/Parquet Schema-aware

Example: S3 sink backup

{
  "connector.class": "io.confluent.connect.s3.S3SinkConnector",
  "topics": "orders",
  "s3.bucket.name": "kafka-backup",
  "format.class": "io.confluent.connect.s3.format.avro.AvroFormat"
}

3. Backing Up Consumer Offsets

Method Description Detail
Export Offsets consumer-groups dump CSV/reset file
MM2 Checkpoints Cross-cluster offsets Failover
Restore --from-file reset Reapply

Example: Export offsets

kafka-consumer-groups.sh --bootstrap-server localhost:9092 \
  --group orders-svc --describe --offsets > offsets-backup.txt

4. Backing Up Schemas

Method Description Detail
_schemas Topic Source of truth Mirror it
REST Export Dump all subjects JSON
Restore POST to new registry Re-register

Example: Export all schemas

for s in $(curl -s localhost:8081/subjects | jq -r '.[]'); do
  curl -s "localhost:8081/subjects/$s/versions/latest" > "$s.json"
done

5. Backing Up Configuration

Config Description Detail
Topic Configs describe all topics Recreate
ACLs acls --list Security
Broker Configs server.properties Version control

Example: Backup topic configs

kafka-topics.sh --bootstrap-server localhost:9092 \
  --describe > topic-configs-backup.txt

6. Implementing Point-in-Time Recovery

Aspect Description Detail
Timestamp Seek offsetsForTimes Replay from T
Archive Restore Reload from S3 Source connector
Reset to Time --to-datetime Group rewind

Example: Reset group to timestamp

kafka-consumer-groups.sh --bootstrap-server localhost:9092 \
  --group orders-svc --reset-offsets \
  --to-datetime 2025-01-01T00:00:00.000 --all-topics --execute

7. Restoring from Backup

Step Description Detail
Recreate Topic Same partitions/RF From config
Replay Data S3 source connector Re-produce
Verify Counts Match expectations Validate

Example: S3 source restore

{
  "connector.class": "io.confluent.connect.s3.source.S3SourceConnector",
  "s3.bucket.name": "kafka-backup",
  "topics.dir": "topics",
  "topic.regex.list": "orders:.*"
}

8. Recovering Consumer Groups

Step Description Detail
Restore Offsets From backup file --from-file
Translated MM2 mapping on DR Cross-cluster
Verify Position Describe group Confirm

Example: Restore offsets from file

kafka-consumer-groups.sh --bootstrap-server localhost:9092 \
  --group orders-svc --reset-offsets \
  --from-file offsets-backup.csv --execute

9. Testing Recovery Procedures

Aspect Description Detail
Restore Drill Scheduled test Validate RTO
Data Integrity Checksum/count No loss
Document Runbook updated Repeatable

Example: Verify restored count

kafka-run-class.sh kafka.tools.GetOffsetShell \
  --bootstrap-server localhost:9092 --topic orders --time -1

10. Automating Backup Process

Aspect Description Detail
Continuous Sink Always-on S3 connector No gaps
Scheduled Export Cron offsets/configs Periodic
Lifecycle Retention on bucket Cost + compliance

Example: Cron config backup

# Daily config + offset snapshot
0 2 * * * /opt/scripts/kafka-backup.sh >> /var/log/kbackup.log 2>&1