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.1.tar.gz (9.4 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.1-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: restic_backup-1.0.1.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for restic_backup-1.0.1.tar.gz
Algorithm Hash digest
SHA256 779dc74cddcd823bb44622b91fd24500774b0c6abef04a4a1579b092a9d28634
MD5 b7e068a5de2943ecbfbe2c08c7fe7f70
BLAKE2b-256 bfcbfa67073a9d5892010bea1d161909835c0a67d3cd4614d0f8088808b5feee

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for restic_backup-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 249140e2b44eb4547a32dc671b4eeb913c93f76c3635376575121e82b38279b6
MD5 bad528582c51323479abc0aade84bc27
BLAKE2b-256 acb199afc2e624975032959b18500e3b499d39dfb94d65e5c577b2768be5d54d

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