runrestic


Namerunrestic JSON
Version 0.5.28 PyPI version JSON
download
home_pagehttps://github.com/sinnwerkstatt/runrestic
SummaryA wrapper script for Restic backup software that inits, creates, prunes and checks backups
upload_time2023-01-17 21:15:20
maintainer
docs_urlNone
authorAndreas Nüßlein
requires_python>=3.7,<4.0
licenseGPL-3.0+
keywords backup
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            ![python version](https://img.shields.io/badge/python-3.7+-blue.svg)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
![Travis (.com)](https://api.travis-ci.com/sinnwerkstatt/runrestic.svg?branch=main)
![PyPI](https://img.shields.io/pypi/v/runrestic)
[![Stackshare: runrestic](https://img.shields.io/badge/stackshare-runrestic-068DFE.svg)](https://stackshare.io/runrestic)
![PyPI - Downloads](https://img.shields.io/pypi/dm/runrestic)

# Runrestic

runrestic is a simple Python wrapper script for the
[Restic](https://restic.net/) 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

```toml
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](https://github.com/sinnwerkstatt/runrestic/blob/main/sample/example.toml)
or check the [schema.json](https://github.com/sinnwerkstatt/runrestic/blob/main/runrestic/runrestic/schema.json)

## Getting started

### Installing runrestic and restic

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

```bash
sudo pip3 install --upgrade runrestic
```

<br>
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

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

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

<br>
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:

```bash
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:

```bash
runrestic shell
```

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

### Prometheus / Grafana metrics

[@d-matt](https://github.com/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](https://raw.githubusercontent.com/sinnwerkstatt/runrestic/main/sample/systemd/runrestic.service)
and the [sample systemd timer file](https://raw.githubusercontent.com/sinnwerkstatt/runrestic/main/sample/systemd/runrestic.timer).
Then, from the directory where you downloaded them:

```bash
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](https://raw.githubusercontent.com/sinnwerkstatt/runrestic/main/sample/cron/runrestic).
Then, from the directory where you downloaded it:

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

## Changelog

- 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

- v**0.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 [poetry](https://python-poetry.org/)

[Install it](https://github.com/python-poetry/poetry#installation) if not already present:

```bash
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python
# or
pip install --user poetry
```

### Installing dependencies

```bash
poetry install
```

### Running Tests

```bash
poetry run pytest
```

### Using VScode devcontainer

The project contains a `.devcontainer` folder with the settings for VScode to [develop inside container](https://code.visualstudio.com/docs/remote/containers). 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 22.04 based container uses Python 3.10 as system version and includes minimal Python 3.7, 3.8 and 3.9 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 use <version>`,
see [poetry managing environments](https://python-poetry.org/docs/managing-environments/) for more details.

# Thanks

This project was initially based on [borgmatic](https://github.com/witten/borgmatic/) but has since evolved into something else.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/sinnwerkstatt/runrestic",
    "name": "runrestic",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7,<4.0",
    "maintainer_email": "",
    "keywords": "backup",
    "author": "Andreas N\u00fc\u00dflein",
    "author_email": "andreas@nuessle.in",
    "download_url": "https://files.pythonhosted.org/packages/8d/13/3c8a7458a45d8ef0df916149bb627b2233c5e9b20a4f7564d88ce3b0fb32/runrestic-0.5.28.tar.gz",
    "platform": null,
    "description": "![python version](https://img.shields.io/badge/python-3.7+-blue.svg)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n![Travis (.com)](https://api.travis-ci.com/sinnwerkstatt/runrestic.svg?branch=main)\n![PyPI](https://img.shields.io/pypi/v/runrestic)\n[![Stackshare: runrestic](https://img.shields.io/badge/stackshare-runrestic-068DFE.svg)](https://stackshare.io/runrestic)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/runrestic)\n\n# Runrestic\n\nrunrestic is a simple Python wrapper script for the\n[Restic](https://restic.net/) backup software that initiates a backup,\nprunes any old backups according to a retention policy, and validates backups\nfor consistency. The script supports specifying your settings in a declarative\nconfiguration file rather than having to put them all on the command-line, and\nhandles common errors.\n\n## Example config\n\n```toml\nrepositories = [\n    \"/tmp/restic-repo\",\n    \"sftp:user@host:/srv/restic-repo\",\n    \"s3:s3.amazonaws.com/bucket_name\"\n    ]\n\n[environment]\nRESTIC_PASSWORD = \"CHANGEME\"\n\n[backup]\nsources = [\n    \"/home\",\n    \"/var\"\n    ]\n\n[prune]\nkeep-last =  3\nkeep-hourly =  5\n```\n\nAlternatively you can also just use JSON. For a more comprehensive example see the [example.toml](https://github.com/sinnwerkstatt/runrestic/blob/main/sample/example.toml)\nor check the [schema.json](https://github.com/sinnwerkstatt/runrestic/blob/main/runrestic/runrestic/schema.json)\n\n## Getting started\n\n### Installing runrestic and restic\n\nTo install **runrestic**, run the following command to download and install it:\n\n```bash\nsudo pip3 install --upgrade runrestic\n```\n\n<br>\nYou 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.\n\n### Initializing and running\n\nOnce you have `restic` and `runrestic` ready, you should put a config file in on of the scanned locations, namely:\n\n- /etc/runrestic.toml\n- /etc/runrestic/_example_.toml\n- ~/.config/runrestic/_example_.toml\n- /etc/runrestic.json\n- /etc/runrestic/_example_.json\n- ~/.config/runrestic/_example_.json\n\nAfterwards, run\n\n```bash\nrunrestic init # to initialize all the repos in `repositories`\n\nrunrestic  # without actions will do: runrestic backup prune check\n# or\nrunrestic [action]\n```\n\n<br>\nCertain `restic` flags like `--dry-run/-n` are built into `runrestic` as well and will be passed to restic where applicable.\n\nIf, however, you need to pass along arbitrary other flags you can now add them to the end of your `runrestic` call like so:\n\n```bash\nrunrestic backup -- --one-file-system\n```\n\n#### Logs for restic and hooks\n\nThe output of `restic` and the configured pre/post-hooks is added to the `runrestic` logs at the level defined in\n`[execution] proc_log_level` (default: DEBUG), which can be overwritten with the CLI option `-p/--proc-log-level`.\n\nFor process log levels greater than `INFO` the output of file names is suppressed and for log levels greater than WARNING\n`restic` is executed with the `--quiet` option. If the process log level is set to `DEBUG`, then restic is executed\nwith the `--verbose` option.\n\nIt is also possible to add `restic` progress messages to the logs by using the CLI option `--show-progress INTERVAL`\nwhere the `INTERVAL` is the number of seconds between the progress messages.\n\n### Restic shell\n\nTo use the options defined in `runrestic` with `restic` (e.g. for a backup restore), you can use the `shell` action:\n\n```bash\nrunrestic shell\n```\n\nIf you are using multiple repositories or configurations, you can select one now.\n\n### Prometheus / Grafana metrics\n\n[@d-matt](https://github.com/d-matt) created a nice dashboard for Grafana here: https://grafana.com/grafana/dashboards/11064/revisions\n\n### systemd timer or cron\n\nIf you want to run runrestic automatically, say once a day, the you can\nconfigure a job runner to invoke it periodically.\n\n#### systemd\n\nIf you're using systemd instead of cron to run jobs, download the [sample systemd service file](https://raw.githubusercontent.com/sinnwerkstatt/runrestic/main/sample/systemd/runrestic.service)\nand the [sample systemd timer file](https://raw.githubusercontent.com/sinnwerkstatt/runrestic/main/sample/systemd/runrestic.timer).\nThen, from the directory where you downloaded them:\n\n```bash\nsudo mv runrestic.service runrestic.timer /etc/systemd/system/\nsudo systemctl enable runrestic.timer\nsudo systemctl start runrestic.timer\n```\n\n#### cron\n\nIf you're using cron, download the [sample cron file](https://raw.githubusercontent.com/sinnwerkstatt/runrestic/main/sample/cron/runrestic).\nThen, from the directory where you downloaded it:\n\n```bash\nsudo mv runrestic /etc/cron.d/runrestic\nsudo chmod +x /etc/cron.d/runrestic\n```\n\n## Changelog\n\n- v0.5.28\n  - Allow jsonschema >= 4.0\n- v0.5.27\n  - Fix output parsing for new restic version 0.14.0\n  - Introduce failsafe output parser which supports default values\n- v0.5.26\n  - Add output messages from `restic` and pre/post-hook commands to runrestic logs.\n  - New CLI argument `--show-progress INTERVAL` for the restic progress update interval in seconds (default None)\n- v0.5.25\n  - Drop support for Python 3.6, add support for Python 3.9 and 3.10, update dependencies\n- v0.5.24\n  - Exit the script with returncode = 1 if there was an error in any of the tasks\n- v0.5.23\n  - support JSON config files.\n- v0.5.21\n\n  - fix issue where \"check\" does not count towards overall \"errors\"-metric\n\n- v**0.5**! Expect breaking changes.\n  - metrics output is a bit different\n  - see new `parallel` and `retry_*` options.\n\n## Ansible\n\n@tabic wrote an ansible role, you can find it here: https://github.com/outwire/ansible-role-restic . (I have neither checked nor tested it.)\n\n## Development\n\nThis project is managed with [poetry](https://python-poetry.org/)\n\n[Install it](https://github.com/python-poetry/poetry#installation) if not already present:\n\n```bash\ncurl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python\n# or\npip install --user poetry\n```\n\n### Installing dependencies\n\n```bash\npoetry install\n```\n\n### Running Tests\n\n```bash\npoetry run pytest\n```\n\n### Using VScode devcontainer\n\nThe project contains a `.devcontainer` folder with the settings for VScode to [develop inside container](https://code.visualstudio.com/docs/remote/containers). The Python virtual environment\ncreated by poetry is stored outside the container in the projects path `.virtualenvs` so that it survives container rebuilds.\n\nThe Ubuntu 22.04 based container uses Python 3.10 as system version and includes minimal Python 3.7, 3.8 and 3.9 versions\nfor creating virtual environments in any of those versions.\n\nIt is possible to switch the Python version used by `poetry` with the command `poetry use <version>`,\nsee [poetry managing environments](https://python-poetry.org/docs/managing-environments/) for more details.\n\n# Thanks\n\nThis project was initially based on [borgmatic](https://github.com/witten/borgmatic/) but has since evolved into something else.\n",
    "bugtrack_url": null,
    "license": "GPL-3.0+",
    "summary": "A wrapper script for Restic backup software that inits, creates, prunes and checks backups",
    "version": "0.5.28",
    "split_keywords": [
        "backup"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "aca78b935c945f923b723d5782e79b106761a89064ee8d764644ff13131a8ce8",
                "md5": "5416c5a3a3e433ae411065af4b7ac299",
                "sha256": "6d5943e9e2264f42ee507046a1b7cf8cc48b45e1373c9b6ddd6d91cb8868517c"
            },
            "downloads": -1,
            "filename": "runrestic-0.5.28-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5416c5a3a3e433ae411065af4b7ac299",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4.0",
            "size": 32363,
            "upload_time": "2023-01-17T21:15:19",
            "upload_time_iso_8601": "2023-01-17T21:15:19.014960Z",
            "url": "https://files.pythonhosted.org/packages/ac/a7/8b935c945f923b723d5782e79b106761a89064ee8d764644ff13131a8ce8/runrestic-0.5.28-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8d133c8a7458a45d8ef0df916149bb627b2233c5e9b20a4f7564d88ce3b0fb32",
                "md5": "31e5b3ed4f471a872474ad2969bc772f",
                "sha256": "62cd131161379607d3fba1a43e71e57a24e1d747af064bd1b8bab207ec102542"
            },
            "downloads": -1,
            "filename": "runrestic-0.5.28.tar.gz",
            "has_sig": false,
            "md5_digest": "31e5b3ed4f471a872474ad2969bc772f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<4.0",
            "size": 32125,
            "upload_time": "2023-01-17T21:15:20",
            "upload_time_iso_8601": "2023-01-17T21:15:20.667524Z",
            "url": "https://files.pythonhosted.org/packages/8d/13/3c8a7458a45d8ef0df916149bb627b2233c5e9b20a4f7564d88ce3b0fb32/runrestic-0.5.28.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-17 21:15:20",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "sinnwerkstatt",
    "github_project": "runrestic",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "lcname": "runrestic"
}
        
Elapsed time: 0.02919s