Skip to main content

A simple, configuration-driven backup tool powered by Restic

Project description

restic-backup

Python 3.10+ License: MIT

A simple, configuration-driven backup tool powered by Restic. Manage multiple backup projects with a single YAML configuration file.

Features

  • 📝 Simple Configuration - Define all backup jobs in one YAML file
  • 🚀 Snapshot-based Backups - Built on Restic's efficient incremental backup system
  • 🗄️ Automatic Retention - Configurable retention policies (daily/weekly/monthly)
  • 🔒 Encryption - All backups are encrypted at rest
  • 🎯 Selective Exclusions - Flexible exclude patterns per project
  • 🐳 Docker Support - Run as a container or use Docker Compose

Requirements

  • Python 3.10+
  • Restic 0.14+
  • PyYAML

Installation

From PyPI (recommended)

pip install restic-backup

From Source

git clone https://github.com/beyond-infra/restic-backup.git
cd restic-backup
pip install -e .

Using Docker

docker pull ghcr.io/beyond-infra/restic-backup:latest

Quick Start

1. Install Restic

# Ubuntu/Debian
apt-get install restic

# macOS
brew install restic

# Or download from https://github.com/restic/restic/releases

2. Create Configuration

Create /etc/restic-backup/config.yaml:

repository: /var/backups/restic

retention:
  daily: 7
  weekly: 4
  monthly: 3

projects:
  my-data:
    source: /data/my-project
    exclude:
      - cache
      - "*.log"

3. Set Password

Create /etc/restic-backup/restic.env:

export RESTIC_PASSWORD="your-strong-password-here"

4. Run Backup

restic-backup backup

Configuration

Full Configuration Example

repository: /var/backups/restic

retention:
  daily: 7      # Keep 7 daily snapshots
  weekly: 4     # Keep 4 weekly snapshots
  monthly: 3    # Keep 3 monthly snapshots

projects:
  # Project 1: Immich photos
  immich:
    source: /data/immich
    exclude:
      - cache
      - library/thumbs
      - library/upload
      - postgres
      - "**/.DS_Store"

  # Project 2: Nextcloud
  nextcloud:
    source: /data/nextcloud
    exclude:
      - data/*/cache

Configuration Options

Option Required Description
repository Yes Base directory for all backup repositories
retention.daily Yes Number of daily snapshots to keep
retention.weekly Yes Number of weekly snapshots to keep
retention.monthly Yes Number of monthly snapshots to keep
projects.<name>.source Yes Source directory to backup
projects.<name>.exclude No List of exclusion patterns

Usage

# List configured projects
restic-backup list

# Backup all projects
restic-backup backup

# Backup specific project only
restic-backup backup immich

# Check backup status
restic-backup status

# Restore from backup
restic-backup restore immich /tmp/restore

# Restore specific snapshot
restic-backup restore immich /tmp/restore abc123de

Docker Usage

Using Docker Compose

Create docker-compose.yaml:

services:
  backup:
    image: ghcr.io/beyond-infra/restic-backup:latest
    volumes:
      - ./config.yaml:/etc/restic-backup/config.yaml:ro
      - ./restic.env:/etc/restic-backup/restic.env:ro
      - /data:/data:ro
      - /var/backups:/var/backups
    command: backup

Run:

docker compose run --rm backup

Manual Docker Run

docker run --rm \
  -v /etc/restic-backup/config.yaml:/etc/restic-backup/config.yaml:ro \
  -v /etc/restic-backup/restic.env:/etc/restic-backup/restic.env:ro \
  -v /data:/data:ro \
  -v /var/backups:/var/backups \
  ghcr.io/beyond-infra/restic-backup:latest \
  backup

Automation

Cron

# Edit crontab
crontab -e

# Daily at 2 AM
0 2 * * * restic-backup backup >> /var/log/restic-backup.log 2>&1

Systemd Timer

See examples/systemd/ directory for service and timer files.

Remote Storage

restic-backup supports all Restic storage backends. Set in restic.env:

# S3
export AWS_ACCESS_KEY_ID="..."
export AWS_SECRET_ACCESS_KEY="..."
export RESTIC_REPOSITORY="s3:s3.amazonaws.com/bucket-name"

# SFTP
export RESTIC_REPOSITORY="sftp:user@host:/backups"

# B2
export B2_ACCOUNT_ID="..."
export B2_ACCOUNT_KEY="..."
export RESTIC_REPOSITORY="b2:bucket-name"

Development

Setup Development Environment

git clone https://github.com/beyond-infra/restic-backup.git
cd restic-backup
python -m venv venv
source venv/bin/activate
pip install -e ".[dev]"

Run Tests

pytest

Code Style

ruff check .
ruff format .

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Restic - The backup program that powers this tool
  • Inspired by the need for simple, configuration-driven backup management

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

restic_backup-1.0.0.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

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

restic_backup-1.0.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file restic_backup-1.0.0.tar.gz.

File metadata

  • Download URL: restic_backup-1.0.0.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for restic_backup-1.0.0.tar.gz
Algorithm Hash digest
SHA256 99f5b988885ea93f9468cd23d5f73001a6cd9947b2499be134f8da463693e7c8
MD5 cdf5542113a5fdc4123e3a3e5371b6c7
BLAKE2b-256 c5e8252cad8306a887daad472ab11e9e71194a2d366aeac92a2797902ea8e8cb

See more details on using hashes here.

File details

Details for the file restic_backup-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: restic_backup-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for restic_backup-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ca34ddfcbdee971520de8e3c912042e4373a0d34cb5756418850e414f63003b9
MD5 3dea6bfa268e85a57cbfd312bb937a3a
BLAKE2b-256 1319c9f62ffa5f16bfbaf1ce631607bcd19555498ea0dd708c2e3743f1c426ac

See more details on using hashes here.

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