Skip to main content

Robust cold backups for Docker environments using Kopia

Project description

Kopi-Docka

Cold Backup Tool for Docker Environments using Kopia

Kopi-Docka is a Python-based backup wrapper for Docker containers and volumes. It uses Kopia for encryption and deduplication, with specific focus on Docker Compose stack awareness.

PyPI Python Version License Downloads


What is Kopi-Docka?

Kopi-Docka = Kopia + Docker + Backup

A wrapper around Kopia, designed for Docker environments:

  • ๐Ÿ“ฆ Stack-Aware - Recognizes Docker Compose stacks and backs them up as logical units
  • ๐Ÿ” Encrypted - End-to-end encryption via Kopia (AES-256-GCM)
  • ๐ŸŒ Multiple Storage Options - Local, S3, B2, Azure, GCS, SFTP, Tailscale, Rclone
  • ๐Ÿ’พ Disaster Recovery - Encrypted bundles with auto-reconnect scripts
  • ๐Ÿ”ง Pre/Post Hooks - Custom scripts (maintenance mode, notifications, etc.)
  • ๐Ÿ“Š Systemd Integration - Daemon with sd_notify and watchdog support
  • ๐Ÿš€ Restore on New Hardware - Recovery without original system
  • ๐Ÿ›ก๏ธ Graceful Shutdown - SafeExitManager ensures containers restart after Ctrl+C
  • ๐Ÿ”” Notifications - Telegram, Discord, Email alerts via Apprise

See detailed features โ†’


Quick Start

Prerequisites

Kopi-Docka expects a prepared system. You need to install dependencies before installing Kopi-Docka:

Required:

Quick check:

docker --version
kopia --version

Need automated setup? Use Server-Baukasten for automated system preparation.

Installation

# Recommended: pipx (isolated environment)
pipx install kopi-docka

# Or: pip (system-wide)
pip install kopi-docka

# Verify all dependencies
kopi-docka doctor

Full installation guide โ†’

Setup

# Interactive setup wizard
sudo kopi-docka setup

The wizard guides you through:

  1. โœ… Dependency verification (Docker, Kopia)
  2. โœ… Repository storage selection (Local, S3, B2, Azure, GCS, SFTP, Tailscale, Rclone)
  3. โœ… Repository initialization
  4. โœ… Connection test

Configuration guide โ†’

First Backup

# System health check
sudo kopi-docka doctor

# List backup units (containers/stacks)
sudo kopi-docka advanced snapshot list

# Test run (no changes)
sudo kopi-docka dry-run

# Full backup
sudo kopi-docka backup

# Create disaster recovery bundle
sudo kopi-docka disaster-recovery
# โ†’ Store bundle off-site: USB/cloud/safe

Usage guide โ†’

Automatic Backups

# Generate systemd units
sudo kopi-docka advanced service write-units

# Enable daily backups (02:00 default)
sudo systemctl enable --now kopi-docka.timer

# Check status
sudo systemctl status kopi-docka.timer

# Or use the interactive management wizard
sudo kopi-docka advanced service manage

Systemd integration โ†’


Key Features

1. Compose-Stack-Awareness

Recognizes Docker Compose stacks and backs them up as atomic units with docker-compose.yml included.

Traditional vs. Kopi-Docka:

Traditional:                    Kopi-Docka:
โ”œโ”€โ”€ wordpress_web_1            Stack: wordpress
โ”œโ”€โ”€ wordpress_db_1             โ”œโ”€โ”€ Containers: web, db, redis
โ””โ”€โ”€ wordpress_redis_1          โ”œโ”€โ”€ Volumes: wordpress_data, mysql_data
                               โ”œโ”€โ”€ docker-compose.yml
โŒ Context lost                โ””โ”€โ”€ Common backup_id
                               โœ… Complete stack restorable

2. Disaster Recovery Bundles

Encrypted packages containing repository connection data and auto-reconnect scripts:

# Create bundle
sudo kopi-docka disaster-recovery

# In emergency (on new server):
1. Decrypt bundle
2. Run ./recover.sh
3. kopi-docka restore
4. docker compose up -d

Note: The legacy TAR/stdin snapshot method is deprecated in favor of direct Kopia directory snapshots (see docs/PROBLEM_1_PLAN.md). Direct snapshots provide file-level deduplication and are the recommended default.

3. Tailscale Integration

Automatic peer discovery for P2P backups over WireGuard mesh network:

sudo kopi-docka advanced config new
# โ†’ Select Tailscale
# โ†’ Shows all devices in your Tailnet
# โ†’ Auto-configures SSH keys
# โ†’ Direct encrypted connection (no cloud costs)

4. Systemd Integration

Daemon implementation with:

  • sd_notify status reporting
  • Watchdog monitoring
  • Security hardening (ProtectSystem, NoNewPrivileges, etc.)
  • PID locking (prevents parallel runs)
  • Structured logging to systemd journal

See detailed features โ†’


Backup Scopes

Kopi-Docka supports three backup scopes to balance speed, size, and restore capabilities:

Scope Comparison

Scope What's Backed Up Restore Capability Use Case
minimal โœ… Volumes only โš ๏ธ Data only - containers must be manually recreated Fastest backups when you always have docker-compose files available
standard โœ… Volumes
โœ… Recipes (docker-compose.yml)
โœ… Networks (IPAM config)
โœ… Full container restore Recommended - Complete restore capability
full โœ… Volumes
โœ… Recipes
โœ… Networks
โœ… Docker daemon config
โœ… Full restore + manual daemon config Disaster recovery with Docker daemon settings

Detailed Restore Matrix

Scope Volumes Container Configs Networks Docker Daemon Config
minimal โœ… Restored โŒ Not backed up* โŒ Not backed up โŒ Not backed up
standard โœ… Restored โœ… Restored โœ… Restored โŒ Not backed up
full โœ… Restored โœ… Restored โœ… Restored โš ๏ธ Manual restore**

Notes:

  • * Minimal scope limitation: Only volume data is backed up. After restore, you must manually recreate containers using your original docker-compose.yml files or docker run commands. Networks must also be manually recreated.
  • ** Docker config safety: Docker daemon configuration (/etc/docker/daemon.json, systemd overrides) is backed up but not automatically restored. This prevents accidental production breakage. Review and manually apply configuration changes.

Usage Examples

Set default scope in config wizard:

sudo kopi-docka advanced config new
# โ†’ Interactive menu will prompt for scope selection
# โ†’ Default: standard (recommended)

Set scope in config file:

{
  "backup": {
    "backup_scope": "standard"
  }
}

Override scope via CLI flag:

# Minimal - Fastest, smallest backups (volumes only)
sudo kopi-docka backup --scope minimal

# Standard - Recommended (volumes + recipes + networks)
sudo kopi-docka backup --scope standard

# Full - Complete DR including Docker daemon config
sudo kopi-docka backup --scope full

โš ๏ธ Minimal Scope Warning

If you restore from a minimal scope backup, Kopi-Docka will show a prominent warning:

โš ๏ธ  MINIMAL Scope Backup Detected

This backup contains ONLY volume data.
Container recipes (docker-compose files) are NOT included.

After restore:
โ€ข Volumes will be restored
โ€ข Containers must be recreated manually
โ€ข Networks must be recreated manually

Consider using --scope standard or --scope full for complete backups.

Recovery steps for minimal scope backups:

  1. sudo kopi-docka restore โ†’ Restores volume data
  2. Manually recreate containers: docker compose up -d (using your original docker-compose.yml)
  3. Manually recreate networks if needed: docker network create ...

๐Ÿ”ง Docker Config Manual Restore

For FULL scope backups, Docker daemon configuration is backed up but requires manual restoration:

Extract docker_config snapshot:

# List docker_config snapshots
sudo kopi-docka list --snapshots | grep docker_config

# Extract configuration to temp directory
sudo kopi-docka show-docker-config <snapshot-id>

What this command does:

  • Extracts docker_config snapshot to /tmp/kopia-docker-config-XXXXX/
  • Displays safety warnings about manual restore
  • Shows extracted files (daemon.json, systemd overrides)
  • Displays daemon.json contents inline (if <10KB)
  • Provides 6-step manual restore instructions

Why manual restore?

  • Docker daemon configuration is extremely sensitive
  • Incorrect config can break Docker entirely
  • Must be reviewed before applying to production
  • Prevents accidental system breakage

Example output:

โœ“ Extracted files:
   โ€ข daemon.json (2.3 KB)
   โ€ข docker.service.d/override.conf (0.5 KB)

๐Ÿ“„ daemon.json contents:
{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  }
}

๐Ÿ”ง Manual Restore Instructions
Step 1: Review extracted files
Step 2: Backup current config
Step 3: Apply configuration (CAREFULLY!)
Step 4: Systemd overrides (if present)
Step 5: Restart Docker daemon
Step 6: Verify Docker is working

Scope Selection Guidance

Choose minimal when:

  • You need fastest possible backups
  • You always have access to original docker-compose files
  • You're comfortable manually recreating containers after restore
  • Storage space is extremely limited

Choose standard when (RECOMMENDED):

  • You want complete restore capability
  • You prefer automated container recreation
  • You want network configurations preserved
  • You need reliable disaster recovery

Choose full when:

  • You need complete disaster recovery capability
  • You have custom Docker daemon configuration
  • You use systemd service overrides for Docker
  • You want to preserve all Docker settings

Default: standard (best balance for most users)


Documentation

๐Ÿ“š Guides:

๐Ÿ“ Examples:


CLI Commands

Kopi-Docka features a simplified CLI with top-level commands and an admin subcommand for advanced operations.

Top-Level Commands

sudo kopi-docka setup              # Complete setup wizard
sudo kopi-docka backup             # Full backup (standard scope)
sudo kopi-docka restore            # Interactive restore wizard
sudo kopi-docka restore --yes      # Non-interactive restore (CI/CD)
sudo kopi-docka show-docker-config <snapshot-id>  # Extract docker_config for manual restore
sudo kopi-docka disaster-recovery  # Create DR bundle
sudo kopi-docka dry-run            # Simulate backup (preview)
sudo kopi-docka doctor             # System health check
kopi-docka version                 # Show version

Admin Commands

# Configuration
sudo kopi-docka advanced config show      # Show config
sudo kopi-docka advanced config new       # Create new config
sudo kopi-docka advanced config edit      # Edit config

# Repository
sudo kopi-docka advanced repo init        # Initialize repository
sudo kopi-docka advanced repo status      # Repository info
sudo kopi-docka advanced repo maintenance # Run maintenance

# Snapshots & Units
sudo kopi-docka advanced snapshot list          # List backup units
sudo kopi-docka advanced snapshot list --snapshots  # List all snapshots
sudo kopi-docka advanced snapshot estimate-size # Estimate backup size

# System & Service
sudo kopi-docka advanced system install-deps    # Install dependencies
sudo kopi-docka advanced service write-units    # Generate systemd units
sudo kopi-docka advanced service daemon         # Run as daemon

Complete CLI reference โ†’


Storage Backend Options

Kopi-Docka supports 8 different storage backends:

  1. Local Filesystem - Local disk or NAS mount
  2. AWS S3 - Amazon S3 or S3-compatible (Wasabi, MinIO)
  3. Backblaze B2 - ~$6/TB/month (includes egress)
  4. Azure Blob - Microsoft Azure storage
  5. Google Cloud Storage - GCS
  6. SFTP - Remote server via SSH
  7. Tailscale - P2P over WireGuard mesh network
  8. Rclone - Universal adapter (OneDrive, Dropbox, Google Drive, 70+ services)

Storage configuration โ†’


System Requirements

  • OS: Linux (Debian, Ubuntu, Arch, Fedora, RHEL/CentOS)
  • Python: 3.10 or newer
  • Docker: Docker Engine 20.10+
  • Kopia: >= 0.13 (recommended; required for sparse-file support) (automatically checked)

Detailed requirements โ†’


Feature Comparison

Feature Kopi-Docka docker-volume-backup Duplicati Restic
Docker-native โœ… โœ… โŒ โŒ
Cold Backups โœ… โœ… โŒ โŒ
Compose-Stack-Aware โœ… โŒ โŒ โŒ
Network Backup* โœ… โŒ โŒ โŒ
DR Bundles โœ… โŒ โŒ โŒ
Tailscale Integration โœ… โŒ โŒ โŒ
Rclone Support โœ… โŒ โŒ โŒ
systemd Integration โœ… โŒ โŒ โŒ
Pre/Post Hooks โœ… โš ๏ธ โŒ โŒ
Storage Options 8 backends Basic Many Many
Deduplication โœ… (Kopia) โŒ โœ… โœ…

*Network Backup = Automatic backup of custom Docker networks with IPAM configuration (subnets, gateways)

Kopi-Docka's focus: Stack-awareness, disaster recovery bundles, Tailscale P2P, and systemd hardening

Full comparison โ†’


Project Status

Status: Feature-Complete, Stabilization Phase
Latest Release: See badges above โ†‘

The current release includes all planned core features:

  • โœ… Backup scope selection (minimal/standard/full)
  • โœ… Docker network backup with IPAM
  • โœ… Pre/Post backup hooks
  • โœ… Disaster recovery bundles
  • โœ… Systemd integration with hardening

Current Focus:

  • Bug fixing and edge-case handling
  • Test coverage expansion
  • Documentation improvements

Known Limitations:

  • Single repository only (no parallel multi-cloud backup)
  • Hooks require careful configuration (Safety Guide)
  • Restore edge-cases still being hardened

New major features: Only after stable foundation

View Changelog | Development Roadmap


Thanks & Acknowledgments

Kopi-Docka = Kopia + Dockar โ€“ the name reflects what this project is: a bridge between two excellent tools.

Kopi-Docka would not exist without these excellent tools:

All of these tools remain under their respective licenses and are not bundled with Kopi-Docka.

This project is built with deep respect for the open-source ecosystem.

Author: Markus F. (TZERO78)
Links: PyPI | GitHub


License

MIT License - see LICENSE for details.

Copyright (c) 2025 Markus F. (TZERO78)


Feedback & Support

If you find Kopi-Docka useful, feel free to leave a โญ on GitHub.

I cannot test all storage backends and edge cases on my own, so feedback from real-world setups is highly appreciated.

If something doesn't work as expected, please open an Issue and include your environment details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kopi_docka-6.0.0.tar.gz (193.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kopi_docka-6.0.0-py3-none-any.whl (224.3 kB view details)

Uploaded Python 3

File details

Details for the file kopi_docka-6.0.0.tar.gz.

File metadata

  • Download URL: kopi_docka-6.0.0.tar.gz
  • Upload date:
  • Size: 193.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kopi_docka-6.0.0.tar.gz
Algorithm Hash digest
SHA256 036cd5d1fc30fa303cf06c7eb9c7382f53552ac74a574d61e8aa4cd01f390c48
MD5 f22d32e3f6d7d820165da28b9b32e8de
BLAKE2b-256 889f35bb5e95186d8009b225cec78f449c970d3cc31f57689e2aa581b9561630

See more details on using hashes here.

Provenance

The following attestation bundles were made for kopi_docka-6.0.0.tar.gz:

Publisher: publish.yml on TZERO78/kopi-docka

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kopi_docka-6.0.0-py3-none-any.whl.

File metadata

  • Download URL: kopi_docka-6.0.0-py3-none-any.whl
  • Upload date:
  • Size: 224.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kopi_docka-6.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d8b415661aab4fb870761a236c08d4824596eaded4ff52bfb1a886c2bf62680a
MD5 504781b3e9a08e1ae5009f32df8d4798
BLAKE2b-256 86a8726ca54d319d2f2619936e02d1ca66d2684d4dd30e891452282fe76181dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for kopi_docka-6.0.0-py3-none-any.whl:

Publisher: publish.yml on TZERO78/kopi-docka

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page