docker.recipes

Borgmatic Backup System

intermediate

Borgmatic for automated Borg backups with scheduling.

Overview

Borgmatic is a wrapper around BorgBackup that automates the process of creating, maintaining, and monitoring deduplicated backups. Created to simplify Borg's complex command-line interface, borgmatic provides declarative YAML configuration files and built-in scheduling capabilities, making enterprise-grade backup automation accessible to organizations of all sizes. The tool handles backup rotation, health checks, and repository maintenance automatically while preserving Borg's powerful deduplication and encryption features. This Docker stack combines borgmatic with persistent storage volumes and configurable source directories to create a complete backup automation solution. The b3vis/borgmatic image includes cron scheduling and comprehensive logging, while Docker volumes ensure backup configurations and Borg caches survive container updates. The setup supports both local repositories and remote backup destinations including SSH, S3, and other cloud storage providers. System administrators managing multiple servers, DevOps teams requiring automated backup workflows, and organizations needing compliance-ready backup retention policies will find this stack invaluable. The combination of Borg's space-efficient deduplication with borgmatic's automation reduces both storage costs and administrative overhead while maintaining enterprise-level reliability and security standards.

Key Features

  • Automated backup scheduling with configurable retention policies and pruning rules
  • BorgBackup deduplication engine reducing storage requirements by 80-95% for typical datasets
  • Built-in health checks with configurable monitoring hooks for external alerting systems
  • Support for multiple repository types including local, SSH, S3, and other cloud providers
  • Automatic repository maintenance including compact operations and consistency checks
  • Comprehensive logging and error reporting with customizable notification channels
  • YAML-based configuration supporting multiple backup jobs and complex filtering rules
  • Integration with monitoring systems through healthchecks.io, Prometheus, and webhook notifications

Common Use Cases

  • 1Automated server backup workflows for production infrastructure with compliance requirements
  • 2Development team data protection for source code repositories and build artifacts
  • 3Database backup automation with point-in-time recovery capabilities
  • 4Homelab and personal server backup management with minimal maintenance overhead
  • 5Multi-tenant backup solutions for managed service providers
  • 6Disaster recovery systems requiring offsite replication and encrypted storage
  • 7Container volume backup for stateful applications in Docker and Kubernetes environments

Prerequisites

  • Minimum 512MB RAM for small repositories, 2GB+ recommended for large datasets
  • Sufficient disk space for Borg cache (typically 1-2% of total backup size)
  • Network access to backup repositories if using remote storage destinations
  • Understanding of Borg repository initialization and passphrase management
  • Familiarity with YAML configuration syntax for borgmatic setup files
  • SSH key configuration if backing up to remote repositories via SSH protocol

For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms

docker-compose.yml

docker-compose.yml
1services:
2 borgmatic:
3 image: b3vis/borgmatic:latest
4 container_name: borgmatic
5 restart: unless-stopped
6 environment:
7 - TZ=${TZ:-UTC}
8 - BORG_PASSPHRASE=${BORG_PASSPHRASE:-}
9 volumes:
10 - ./borgmatic.d:/etc/borgmatic.d:ro
11 - ${SOURCE_PATH:-./source}:/mnt/source:ro
12 - ${REPO_PATH:-./repo}:/mnt/borg-repository
13 - borgmatic_config:/root/.config/borg
14 - borgmatic_cache:/root/.cache/borg
15 networks:
16 - borgmatic-network
17
18volumes:
19 borgmatic_config:
20 borgmatic_cache:
21
22networks:
23 borgmatic-network:
24 driver: bridge

.env Template

.env
1# Borgmatic
2TZ=UTC
3BORG_PASSPHRASE=your-secure-passphrase
4SOURCE_PATH=./source
5REPO_PATH=./repo

Usage Notes

  1. 1Create borgmatic.d/config.yaml
  2. 2Run borgmatic init first
  3. 3Cron scheduling built-in
  4. 4Supports remote repositories

Quick Start

terminal
1# 1. Create the compose file
2cat > docker-compose.yml << 'EOF'
3services:
4 borgmatic:
5 image: b3vis/borgmatic:latest
6 container_name: borgmatic
7 restart: unless-stopped
8 environment:
9 - TZ=${TZ:-UTC}
10 - BORG_PASSPHRASE=${BORG_PASSPHRASE:-}
11 volumes:
12 - ./borgmatic.d:/etc/borgmatic.d:ro
13 - ${SOURCE_PATH:-./source}:/mnt/source:ro
14 - ${REPO_PATH:-./repo}:/mnt/borg-repository
15 - borgmatic_config:/root/.config/borg
16 - borgmatic_cache:/root/.cache/borg
17 networks:
18 - borgmatic-network
19
20volumes:
21 borgmatic_config:
22 borgmatic_cache:
23
24networks:
25 borgmatic-network:
26 driver: bridge
27EOF
28
29# 2. Create the .env file
30cat > .env << 'EOF'
31# Borgmatic
32TZ=UTC
33BORG_PASSPHRASE=your-secure-passphrase
34SOURCE_PATH=./source
35REPO_PATH=./repo
36EOF
37
38# 3. Start the services
39docker compose up -d
40
41# 4. View logs
42docker compose logs -f

One-Liner

Run this command to download and set up the recipe in one step:

terminal
1curl -fsSL https://docker.recipes/api/recipes/borgmatic-backup/run | bash

Troubleshooting

  • Repository does not exist error: Run 'borgmatic init' to initialize the repository before first backup
  • Permission denied accessing source files: Ensure Docker container has read access to source directories and proper UID mapping
  • Borg cache lock timeout errors: Remove stale lock files from borgmatic_cache volume or increase lock timeout values
  • Out of disk space during backup: Configure appropriate pruning policies and monitor repository growth patterns
  • Failed to create/acquire the lock: Stop any running borgmatic processes and remove lock files from the repository
  • Backup verification failures: Check repository integrity with 'borg check' and verify source data hasn't been corrupted

Community Notes

Loading...
Loading notes...

Download Recipe Kit

Get all files in a ready-to-deploy package

Includes docker-compose.yml, .env template, README, and license

Ad Space