sephiroth1395 / restic-PyBM

A Python 3 wrapper to manage and monitor backups with restic
MIT License
10 stars 1 forks source link
python3 restic

restic-PyBM

A Python 3 wrapper to manage restic repositories and monitor them with Nagios-compliant outputs.

Why?

When looking for a tool to backup my homelab and personal documents, restic came out as the strongest contender for FOSS solutions.

Implementation proved to be easy and simple.

restic-PyBM started out as a Bash script to automate stuff. Then the need to monitor the backups appeared, then the script started to look horrendous, then I wanted to prepare for integration with one-time repository keys generated via HashiCorp Vault.

So I decided to rewrite things in a somewhat cleaner manner in Python, with a YAML configuration file.

Assumptions

In its current form, this wrapper makes a series of assumptions over the use of restic:

Over time, depending on my needs and eventual feature requests if this project drags any attention, some of these assumptions might get lifted.

Features

Roadmap

Usage

Configuration file

The script uses a YAML configuration file:

restic_binary_location: /opt/restic
repos:
  repo1:
    location: /root/test
    key: aaaa
    min_age: 1
    max_age: 7
    includes:
      - /tmp
  repo2:
    location: rest:https://rest-server.local:8000/server_babel
    key: bbb
    min_age: 3
    max_age: 15
    includes:
      - /etc
      - /usr/local/lib

The script itself

usage: restic-PyBM.py [-h] [-c CONFIGFILE] [--full] [--perfdata] [-v] [-q]
                      {run,create,list,prune,check} repo

A restic wrapper and Nagios-compliant status checker using a YAML
configuration file. Version 0.1.

positional arguments:
  {run,create,list,prune,check}
                        Action to execute.
  repo                  Repository name, as declared in the configuration
                        file.

optional arguments:
  -h, --help            show this help message and exit
  -c CONFIGFILE, --config-file CONFIGFILE
                        Configuration file location. Default [backup.yml]
  --full                check action: Verifies the actual snapshots content on
                        top of repository metadata.
  --perfdata            check action: Outputs Nagios-compliant perfdata
                        metrics
  -v, --verbose         Provide restic output even for successful execution of
                        actions.
  -q, --quiet           Output only error messages.