Skip to main content

python version Code style: black Travis (.com) PyPI Stackshare: runrestic PyPI - Downloads

Runrestic

runrestic is a simple Python wrapper script for the Restic backup software that initiates a backup, prunes any old backups according to a retention policy, and validates backups for consistency. The script supports specifying your settings in a declarative configuration file rather than having to put them all on the command-line, and handles common errors.

Example config

repositories = [
    "/tmp/restic-repo",
    "sftp:user@host:/srv/restic-repo",
    "s3:s3.amazonaws.com/bucket_name"
    ]

[environment]
RESTIC_PASSWORD = "CHANGEME"

[backup]
sources = [
    "/home",
    "/var"
    ]

[prune]
keep-last =  3
keep-hourly =  5

Alternatively you can also just use JSON. For a more comprehensive example see the example.toml or check the schema.json

Getting started

Installing runrestic and restic

To install runrestic, run the following command to download and install it:

sudo pip3 install --upgrade runrestic

You can either manually download and install [Restic](https://restic.net/) or you can just run `runrestic` and it'll try to download it for you.

Initializing and running

Once you have restic and runrestic ready, you should put a config file in on of the scanned locations, namely:

  • /etc/runrestic.toml
  • /etc/runrestic/example.toml
  • ~/.config/runrestic/example.toml
  • /etc/runrestic.json
  • /etc/runrestic/example.json
  • ~/.config/runrestic/example.json

Afterwards, run

runrestic init # to initialize all the repos in `repositories`

runrestic  # without actions will do: runrestic backup prune check
# or
runrestic [action]

Certain `restic` flags like `--dry-run/-n` are built into `runrestic` as well and will be passed to restic where applicable.

If, however, you need to pass along arbitrary other flags you can now add them to the end of your runrestic call like so:

runrestic backup -- --one-file-system

Logs for restic and hooks

The output of restic and the configured pre/post-hooks is added to the runrestic logs at the level defined in [execution] proc_log_level (default: DEBUG), which can be overwritten with the CLI option -p/--proc-log-level.

For process log levels greater than INFO the output of file names is suppressed and for log levels greater than WARNING restic is executed with the --quiet option. If the process log level is set to DEBUG, then restic is executed with the --verbose option.

It is also possible to add restic progress messages to the logs by using the CLI option --show-progress INTERVAL where the INTERVAL is the number of seconds between the progress messages.

Restic shell

To use the options defined in runrestic with restic (e.g. for a backup restore), you can use the shell action:

runrestic shell

If you are using multiple repositories or configurations, you can select one now.

Prometheus / Grafana metrics

@d-matt created a nice dashboard for Grafana here: https://grafana.com/grafana/dashboards/11064/revisions

systemd timer or cron

If you want to run runrestic automatically, say once a day, the you can configure a job runner to invoke it periodically.

systemd

If you're using systemd instead of cron to run jobs, download the sample systemd service file and the sample systemd timer file. Then, from the directory where you downloaded them:

sudo mv runrestic.service runrestic.timer /etc/systemd/system/
sudo systemctl enable runrestic.timer
sudo systemctl start runrestic.timer

cron

If you're using cron, download the sample cron file. Then, from the directory where you downloaded it:

sudo mv runrestic /etc/cron.d/runrestic
sudo chmod +x /etc/cron.d/runrestic

Changelog

  • v0.5.31
    • Change for process pool to thread pool
      • Solves issue with runrestic sometimes hanging.
    • Drop support for Python 3.8 (EOL 2024-10-07) and 3.9 (EOL 2025-10)
    • Fix build backend for uv
    • Add and update docstrings
    • Add and update type hints
    • Minor code improvements and test coverage
  • v0.5.30
    • Fix metric setting in restic runner for "check"
    • Support Python 3.13
      • Add Python 3.13 in devcontainer so that it can be used for testing
      • Updated Poetry lock
    • Enhance test coverage
      • Modified restic tools test to use mock file operations and shortened retry times for faster test execution
  • v0.5.29
    • Support Python 3.12
    • Updated devcontainer to Ubuntu 24.04 (noble)
  • v0.5.28
    • Allow jsonschema >= 4.0
  • v0.5.27
    • Fix output parsing for new restic version 0.14.0
    • Introduce failsafe output parser which supports default values
  • v0.5.26
    • Add output messages from restic and pre/post-hook commands to runrestic logs.
    • New CLI argument --show-progress INTERVAL for the restic progress update interval in seconds (default None)
  • v0.5.25
    • Drop support for Python 3.6, add support for Python 3.9 and 3.10, update dependencies
  • v0.5.24
    • Exit the script with returncode = 1 if there was an error in any of the tasks
  • v0.5.23
    • support JSON config files.
  • v0.5.21
    • fix issue where "check" does not count towards overall "errors"-metric
  • v0.5! Expect breaking changes.
    • metrics output is a bit different
    • see new parallel and retry_* options.

Ansible

@tabic wrote an ansible role, you can find it here: https://github.com/outwire/ansible-role-restic . (I have neither checked nor tested it.)

Development

This project is managed with uv.

Installing dependencies

uv sync

Running Tests

uv run pytest

Using VScode devcontainer

The project contains a .devcontainer folder with the settings for VScode to develop inside container. The Python virtual environment created by poetry is stored outside the container in the projects path .virtualenvs so that it survives container rebuilds.

The Ubuntu 24.04 based container uses Python 3.12 as system version and includes minimal Python 3.10 to 3.13 versions for creating virtual environments in any of those versions.

It is possible to switch the Python version used by poetry with the command poetry env use <version>, see poetry managing environments for more details.

Thanks

This project was initially based on borgmatic but has since evolved into something else.

Release files for runrestic 0.5.31

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for runrestic 0.5.31
File Size Uploaded
runrestic-0.5.31.tar.gz 119.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for runrestic 0.5.31
File Interpreter ABI Platform
runrestic-0.5.31-py3-none-any.whl Python 3 none any Details

Total release size: 155.8 kB

Release files / runrestic-0.5.31.tar.gz

Download URL runrestic-0.5.31.tar.gz
Size 119.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9c5a1e49b678b7fed17c246443c46417068fc31eecb54ddadfdb2aabe81bc0bf
BLAKE2b-256 checksum
How to use checksums
db5d6ab603a95000056e827c39733f36da99b6ac5d90593a42d8e70bb2ea8080
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"TUXEDO OS","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / runrestic-0.5.31-py3-none-any.whl

Download URL runrestic-0.5.31-py3-none-any.whl
Size 36.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c3a78a6d47615aac240455abc9e30ee3a25f6117023dc79345413ba533785b23
BLAKE2b-256 checksum
How to use checksums
77cf0f2f6d4470cfe68040d589768b0b715874773a77d7209c757ca071962573
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"TUXEDO OS","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.5.31 This release

2 release files

0.5.29

2 release files

0.5.28

2 release files

0.5.27

2 release files

0.5.26

2 release files

0.5.25

2 release files

0.5.23

2 release files

0.5.22

2 release files

0.5.21

2 release files

0.5.20

2 release files

0.5.9

2 release files

0.5.8

2 release files

0.5.7

2 release files

0.5.6

2 release files

0.5.5

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page