Skip to main content

CLI Basics

OSO Kafka Backup provides a powerful command-line interface with 12 commands for backup, restore, and offset management operations.

Global Options

All commands support these global options:

OptionDescription
-v, --verboseEnable verbose logging (use -vv for trace level)
--helpShow help for any command
--versionShow version information
# Enable debug logging
kafka-backup -v backup --config backup.yaml

# Enable trace logging (very verbose)
kafka-backup -vv backup --config backup.yaml

Command Overview

CommandDescription
backupRun a backup operation
restoreRestore data from a backup
listList available backups
statusShow backup status and statistics
describeShow detailed backup manifest
validateValidate backup integrity
validate-restoreValidate restore configuration (dry-run)
show-offset-mappingDisplay offset mapping for consumer groups
offset-resetGenerate or execute offset reset plans
offset-reset-bulkParallel bulk offset reset
offset-rollbackSnapshot and rollback consumer offsets
three-phase-restoreComplete restore with automatic offset reset

Core Commands

backup

Run a backup operation from a Kafka cluster to storage.

kafka-backup backup --config <path>

Options:

FlagTypeRequiredDescription
-c, --configstringYesPath to backup configuration YAML

Example:

kafka-backup backup --config /etc/kafka-backup/backup.yaml

restore

Restore data from a backup to a Kafka cluster.

kafka-backup restore --config <path>

Options:

FlagTypeRequiredDescription
-c, --configstringYesPath to restore configuration YAML

Example:

kafka-backup restore --config /etc/kafka-backup/restore.yaml

list

List available backups in a storage location.

kafka-backup list --path <path> [--backup-id <id>]

Options:

FlagTypeRequiredDescription
-p, --pathstringYesPath to storage location
-b, --backup-idstringNoShow details for specific backup

Examples:

# List all backups
kafka-backup list --path /var/lib/kafka-backup/data

# List all backups from S3
kafka-backup list --path s3://my-bucket/backups

# Show details for a specific backup
kafka-backup list --path /data --backup-id daily-backup-001

status

Show status and statistics of a backup.

kafka-backup status --path <path> --backup-id <id> [--db-path <path>]

Options:

FlagTypeRequiredDescription
-p, --pathstringYesPath to storage location
-b, --backup-idstringYesBackup ID to show status for
--db-pathstringNoPath to offset database for progress tracking

Example:

kafka-backup status --path /data --backup-id backup-001

Output includes:

  • Manifest information (created date, source cluster)
  • Topic, partition, and segment counts
  • Record and size statistics
  • Compression ratio
  • Offset tracking status per partition

describe

Show detailed backup manifest information.

kafka-backup describe --path <path> --backup-id <id> [--format <format>]

Options:

FlagTypeRequiredDescription
-p, --pathstringYesPath to storage location
-b, --backup-idstringYesBackup ID to describe
-f, --formatstringNoOutput format: text (default), json, yaml

Examples:

# Text output (default)
kafka-backup describe --path /data --backup-id backup-001

# JSON output for scripting
kafka-backup describe --path /data --backup-id backup-001 --format json

# YAML output
kafka-backup describe --path /data --backup-id backup-001 -f yaml

validate

Validate backup integrity.

kafka-backup validate --path <path> --backup-id <id> [--deep]

Options:

FlagTypeRequiredDescription
-p, --pathstringYesPath to storage location
-b, --backup-idstringYesBackup ID to validate
--deepboolNoPerform deep validation (read all segments)

Examples:

# Quick validation (check existence and metadata)
kafka-backup validate --path /data --backup-id backup-001

# Deep validation (read and verify all segments)
kafka-backup validate --path /data --backup-id backup-001 --deep

Validation Report:

  • Segments checked/valid/missing/corrupted
  • Records validated
  • Issues found with details
  • Final result: VALID or INVALID

validate-restore

Validate a restore configuration without executing it.

kafka-backup validate-restore --config <path> [--format <format>]

Options:

FlagTypeRequiredDescription
-c, --configstringYesPath to restore configuration
-f, --formatstringNoOutput format: text, json, yaml

Example:

kafka-backup validate-restore --config restore.yaml --format json

Report includes:

  • Restore status (VALID or INVALID)
  • Topics and segments to process
  • Records and bytes to restore
  • Time range
  • Errors and warnings

Offset Management Commands

show-offset-mapping

Display offset mapping for a backup (useful for consumer group reset).

kafka-backup show-offset-mapping --path <path> --backup-id <id> [--format <format>]

Options:

FlagTypeRequiredDescription
-p, --pathstringYesPath to storage location
-b, --backup-idstringYesBackup ID
-f, --formatstringNoOutput: text, json, yaml, csv

Example:

kafka-backup show-offset-mapping --path /data --backup-id backup-001 --format csv

offset-reset

Generate or execute consumer group offset reset plans.

Subcommands:

# Generate a reset plan
kafka-backup offset-reset plan \
--path <path> \
--backup-id <id> \
--groups <group1,group2> \
--bootstrap-servers <servers>

# Execute a reset plan
kafka-backup offset-reset execute \
--path <path> \
--backup-id <id> \
--groups <group1> \
--bootstrap-servers <servers>

# Generate a shell script for manual execution
kafka-backup offset-reset script \
--path <path> \
--backup-id <id> \
--groups <group1> \
--bootstrap-servers <servers> \
--output reset.sh

offset-reset-bulk

Execute bulk parallel offset reset (50x faster than sequential).

kafka-backup offset-reset-bulk \
--path <path> \
--backup-id <id> \
--groups <groups> \
--bootstrap-servers <servers> \
[--max-concurrent <num>] \
[--max-retries <num>]

Options:

FlagTypeDefaultDescription
--max-concurrentint50Maximum concurrent requests
--max-retriesint3Maximum retry attempts
--security-protocolstringPLAINTEXTSecurity protocol

offset-rollback

Snapshot and rollback consumer group offsets.

Subcommands:

# Create a snapshot before making changes
kafka-backup offset-rollback snapshot \
--path /data/snapshots \
--groups my-group \
--bootstrap-servers localhost:9092 \
--description "Before migration"

# List available snapshots
kafka-backup offset-rollback list --path /data/snapshots

# Show snapshot details
kafka-backup offset-rollback show \
--path /data/snapshots \
--snapshot-id snapshot-20241203-100000

# Rollback to a previous snapshot
kafka-backup offset-rollback rollback \
--path /data/snapshots \
--snapshot-id snapshot-20241203-100000 \
--bootstrap-servers localhost:9092

# Verify offsets match a snapshot
kafka-backup offset-rollback verify \
--path /data/snapshots \
--snapshot-id snapshot-20241203-100000 \
--bootstrap-servers localhost:9092

# Delete a snapshot
kafka-backup offset-rollback delete \
--path /data/snapshots \
--snapshot-id snapshot-20241203-100000

three-phase-restore

Run a complete three-phase restore with automatic offset reset.

kafka-backup three-phase-restore --config <path>

This command performs:

  1. Phase 1: Collect offset headers from source backup
  2. Phase 2: Restore data to target cluster
  3. Phase 3: Reset consumer group offsets

Common Workflows

Daily Backup Verification

#!/bin/bash
# Verify yesterday's backup

BACKUP_PATH="/var/lib/kafka-backup/data"
BACKUP_ID="daily-$(date -d yesterday +%Y%m%d)"

# Quick validation
kafka-backup validate --path "$BACKUP_PATH" --backup-id "$BACKUP_ID"

# Get backup statistics
kafka-backup describe --path "$BACKUP_PATH" --backup-id "$BACKUP_ID" --format json

Pre-Migration Offset Snapshot

#!/bin/bash
# Snapshot offsets before migration

kafka-backup offset-rollback snapshot \
--path /data/snapshots \
--groups "app-consumer,analytics-consumer" \
--bootstrap-servers broker-1:9092,broker-2:9092 \
--description "Pre-migration snapshot"

Disaster Recovery Restore

#!/bin/bash
# Full disaster recovery restore

# 1. Validate the backup
kafka-backup validate --path s3://backups/kafka --backup-id latest --deep

# 2. Validate restore config
kafka-backup validate-restore --config dr-restore.yaml

# 3. Execute three-phase restore
kafka-backup three-phase-restore --config dr-restore.yaml

Next Steps