Skip to content
BotServBotServ
DockerBackupStrategy3-2-1Offsite

Docker Backup Strategies

Backup strategies for Docker environments. 3-2-1 rule, volume backups, configuration, images, and offsite storage.

S

schutzgeist

2 min read
Docker Backup Strategies

Docker Backup Strategies

What This Article Covers

  • What makes a good backup strategy.
  • The 3-2-1 rule for Docker.
  • What needs to be backed up.
  • Rotation, retention, and testing.
  • Tools and practical examples.

Introduction: Docker Backup Strategies

Containers are stateless, but the data behind them isn’t. Anyone running Docker containers needs to ensure that persistent data, configurations, and images can be restored if something fails. A good backup strategy should run regularly, store multiple copies, and actually be tested. Without a plan, critical data disappears fast.

This article walks you through building a robust backup strategy for Docker environments.

Key Terms

  • 3-2-1 rule: Three copies, two media types, one offsite.
  • Retention: How long to keep backups.
  • RTO: Recovery Time Objective.
  • RPO: Recovery Point Objective.
  • Snapshot: Point-in-time copy.
  • Offsite: External storage location.
  • Catalog: List of all backups.
  • DR plan: Disaster recovery plan.

What to Back Up

  • Volumes: Application data.
  • Bind mounts: Host directories.
  • Compose files: Infrastructure as code.
  • Environment variables and .env files: Configuration.
  • Images: Custom images and their tags.
  • Secrets: Certificates, keys, passwords.
  • Database dumps: Consistent database backups.

The 3-2-1 Rule

  • At least three copies of your data.
  • On at least two different storage media.
  • One copy stored offsite.

Example:

  1. Local copy on NAS.
  2. External copy in cloud storage.
  3. Additional archived version on another medium.

Backup Schedule

FrequencyContent
HourlyDatabase transaction logs
DailyVolumes, database dumps
WeeklyFull image backup
MonthlyArchive backup

Automation

#!/bin/bash
DATE=$(date +%Y%m%d_%H%M%S)
for vol in $(docker volume ls -q); do
  docker run --rm -v ${vol}:/data -v /backup:/backup alpine \
    tar -czf /backup/${vol}_${DATE}.tar.gz -C /data .
done

Database Dumps

docker exec datenbank pg_dump -U postgres meine_db > /backup/db.sql

Or:

docker exec datenbank mysqldump -u root -pgeheim db > /backup/db.sql

Back Up Configuration

cp -r /opt/docker/* /backup/configs/

Export Images

docker save -o /backup/images/mein-image.tar mein-image:latest

Offsite Storage

  • S3, Backblaze B2.
  • rsync.net.
  • External hard drive.
  • FTP/SFTP server.

Retention Policy

  • How long should backups be kept?
  • Daily backups: 14 days.
  • Weekly backups: 8 weeks.
  • Monthly backups: 12 months.

Testing

  • Run a restore test quarterly.
  • Start test containers.
  • Verify the application works.
  • Check data integrity.

Tools

  • Restic: Incremental, encrypted, deduplicated.
  • Borg: Compression, deduplication.
  • Duplicati: Web interface, cloud storage.
  • rsnapshot: Snapshot-based.

Tips

  • Automate your backups.
  • Document retention periods.
  • Test regularly.
  • Never skip offsite backups.
  • Use encryption.
  • Store passwords separately from backups.
  • Maintain a catalog.

Common Pitfalls

  • Backing up only container images: You lose the actual data.
  • No database dumps: Backups become inconsistent.
  • No testing: Restore fails when you need it most.
  • No offsite copy: Fire or theft destroys everything.
  • Wrong retention settings: Disk fills up or backups become too old.
  • Storing secrets unencrypted: Serious security risk.

Further Reading

FAQ: Docker Backup Strategies

What do I need to back up in Docker? Volumes, bind mounts, Compose files, environment files, database dumps, and custom images.

How often should I back up? Databases daily, volumes depending on how frequently they change.

What’s RTO/RPO? RTO is the maximum time to restore. RPO is the maximum acceptable data loss.

Should I back up images? Yes, if you can’t easily rebuild them.

Is one backup enough? No. Follow 3-2-1: three copies on two media types, one offsite.

Sources and Further Reading

Summary: Docker Backup Strategies

A well-designed Docker backup strategy regularly and redundantly backs up volumes, configuration, database dumps, and images, and tests them. The 3-2-1 rule provides a proven framework. Automation, offsite storage, encryption, and regular restore tests are non-negotiable. Build a plan you’ll actually use when disaster strikes, and your data stays safe.

Back to Blog
Share:

Related Posts