slavos1 / restic-backup-wrapper

Use a custom config for many backups
MIT License
0 stars 0 forks source link
backup command-line command-line-tool posix restic tool

restic-backup-wrapper tool

_Generated from source_readme.adoc._

restic-backup-wrapper-cli is a command-line tool that generates restic commands from a TOML config file.

The output is suitable for piping to a (Posix) shell. If you have the RESTIC_REPOSITORY and RESTIC_PASSWORD environment variables set up already, you can run it simply as:

restic-backup-wrapper-cli -l '' -i my-backup.toml | bash -xs
*Please note although this script is provided in the hope it will be [useful](LICENSE), use caution when running it. Always review the generated `restic` commands, as improper use could potentially damage your backup data.*

Example

Given a TOML file min.toml:

# a sample config
relative-to = "/home/user"
group-by = "host,paths,tags"
# global exclude: will be added to all backups
exclude = ['.git', '*.py[cd]', '__pycache__']

[my-folder-one]
dir = "/home/user/my-folder-one"
tags = ['mobile', 'voice', 'audio']
exclude = ['.hg']

[folder-with-one-backup]
dir = "/home/user/readme.txt"
tags = ['doc']
keep-last = 1

[absolute-path]
dir = "/mnt/data"
tags = ['external']

then

restic-backup-wrapper-cli -l '' -i min.toml

generates restic commands:

# Generated by restic-backup-wrapper-cli 0.2.1 on ...
#
# commands for key 'my-folder-one'
#
(cd /home/user && restic backup my-folder-one --group-by host,paths,tags --tag audio,mobile,voice -e '*.py[cd]' -e .git -e .hg -e __pycache__)
#
# commands for key 'folder-with-one-backup'
#
(cd /home/user && restic backup readme.txt --group-by host,paths,tags --tag doc -e '*.py[cd]' -e .git -e __pycache__)
(cd /home/user && restic forget --prune --keep-last 1 --path /home/user/readme.txt)
#
# commands for key 'absolute-path'
#
restic backup /mnt/data --group-by host,paths,tags --tag external -e '*.py[cd]' -e .git -e __pycache__

Syntax

usage: restic-backup-wrapper-cli [-h] [--version] [-q] [-d] [-l PATH] -i PATH
                                 [-o PATH|-] [-n]

options:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  -q, --quiet           Log less (default: False)
  -d, --debug           Log more (default: False)
  -l PATH, --log-root PATH
                        Log root path (specify '' to suppress logging to a
                        file) (default: logs)
  -i PATH, --input-file PATH
                        Input TOML file (default: None)
  -o PATH|-, --output-file PATH|-
                        Output file; if not specified or -, it is stdout
                        (default: None)
  -n, --dry-run         Generate dry run for restic backup (default: False)

Prerequisites

How to use

# run the CLI
hatch run cli
make cli

# run the CLI help
hatch run help
make help

# or append any CLI-defined args, like --help
hatch run cli --help
make cli EXTRA='...'

# run mypy
hatch run types:check
make mypy

# run tests
make
hatch run test

# go to the venv shell
hatch shell

# write documentation
make doc

# increase version
hatch version <new-version>

Local install and run

rm -rf dist/
hatch build
pipx install dist/*.whl
restic-backup-wrapper-cli --version
restic-backup-wrapper-cli --help

# or you can use
make local

Input file format

-i/--input-file is a TOML file of the following format.

Global parameters

Backed up folders

Each key of the form [my-dir] represents a folder to be backed up and for which a restic backup command will be generated.

The key can be an arbitrary string and does not need to match folder/file being backup up.

For each such entry, restic-backup-wrapper-cli recognizes these parameters:

restic and relative paths

According to the restic author, restic keeps relative and absolute paths. It is not obvious from restic snaphots where only absolute paths are shown. Running `restic ls

` for a snapshot backed up from a relative path will show `/` as the "parent" path (and not the full path). *So one should imagine how `tar` does it.* # Writing documentation When writing documentation, edit `source_readme.adoc`, run `make doc-devel` and preview the generated `readme.html`. Once ready to commit, run `make doc` to generate [README.md](README.md) file from [source\_readme.adoc](source_readme.adoc) (and included files).