How to Backup Kafka Topics to S3: A Production Runbook
To backup Kafka to S3, prepare an independent bucket, grant scoped access,
select the required topics, and set storage.backend: s3. Then run
kafka-backup backup --config s3-backup.yaml and validate the stored result.
This workflow keeps topic data and recovery metadata outside the Kafka cluster. It creates a recovery path that broker replication alone cannot provide.
A successful upload is not recovery proof. Run integrity validation after each backup, then rehearse a restore into an isolated topic or cluster.
Choose the right Kafka-to-S3 pattern
Several tools can move Kafka records into S3. They do not produce the same recovery outcome.
OSO Kafka Backup captures records, topic configuration, original offsets, and consumer group positions. It also supports millisecond-precision restore windows. These features make it suitable for operational recovery.
Kafka Connect S3 Sink is strong at exporting records into analysis-friendly objects. It fits teams that already run Connect and need an archive or data-lake feed. However, it does not preserve consumer group positions as a backup tool.
Native Kafka replication keeps partitions available across brokers. A cross-cluster replicator can also keep another cluster current. Both approaches can copy a bad write or deletion before an operator responds.
| Pattern | Primary outcome | Consumer positions | Historical restore point | Good fit |
|---|---|---|---|---|
| OSO Kafka Backup to S3 | Recoverable backup | Built in | Yes | Topic recovery and disaster recovery |
| Kafka Connect S3 Sink | Record archive | No | Based on exported object layout | Analytics and long-term record access |
| Kafka replication | Live redundant copy | Tool dependent | No | Availability and warm standby |
| Console consumer export | One-off record dump | No | Manual | Small development tasks |
The Kafka backup strategies guide compares these patterns across wider recovery requirements. This runbook focuses on a recoverable S3 backup.
Plan the S3 recovery boundary
Start with the incident that the backup must survive. Cluster loss requires a copy outside the brokers. Account compromise may require a separate AWS account and tighter deletion controls.
Choose a bucket region close to the backup process. This reduces transfer delay and avoids unnecessary cross-region traffic. Confirm any residency requirements before records leave the Kafka environment.
Use a dedicated key prefix for each source cluster and environment. A structure
such as production/orders-cluster makes access policies and lifecycle rules
easier to review.
Enable bucket versioning and default encryption through your normal AWS controls. Versioning can protect an earlier object version from an accidental overwrite. It does not replace a tested backup retention policy.
Define the following before the first run:
- The exact topics and consumer groups in scope
- The maximum acceptable time between recovery points
- The time allowed to retrieve and restore the data
- The owner of backup failures and restore drills
- The retention period for each backup class
S3 lifecycle rules can move older objects into archive storage. Those tiers may require retrieval before the backup can be read. Include that delay in recovery tests and runbooks.
Prepare S3 access without static credentials
Prefer short-lived AWS credentials. Use an EC2 instance profile for an EC2 host, or IAM Roles for Service Accounts for an EKS workload.
OSO Kafka Backup uses the AWS credential chain when keys are absent from the YAML file. This keeps long-lived credentials out of source control and deployed configuration.
The backup identity needs access to the intended bucket and objects. The repository's AWS setup policy includes these actions:
| Scope | Required actions | Purpose |
|---|---|---|
| Bucket | s3:ListBucket, s3:GetBucketLocation | Find and inventory stored backups |
| Objects | s3:GetObject, s3:PutObject, s3:DeleteObject | Write, validate, read, and manage backup objects |
Restrict the policy resources to the backup bucket and intended prefix. Do not grant broad S3 access when the process serves one backup location.
Confirm the active identity and bucket access before testing Kafka:
aws sts get-caller-identity
aws s3 ls s3://company-kafka-backups/production/
The AWS S3 setup guide includes bucket, policy, instance-role, and IRSA examples. Apply the controls required by your organization around those examples.