resticbackups3 (rbs3)
A command-line tool that turns restic and S3-compatible storage
(Cloudflare R2 first) into "init once, then back up from cron":
rbs3 init <profile>
rbs3 backup <profile> --mail
rbs3 cronjob <profile> "0 4 * * *" --mail --silent
Status: early development. rbs3 init and rbs3 backup work; retention, email reports,
restore and cron come next.
Create a profile
rbs3 init <profile> --env-file creds.env --config settings.toml
Credentials can come from an env file (--env-file), this shell's environment (--env-var),
flags (--restic-password=…) or prompts. They combine, with flags first, then the env file,
then the environment, and anything still missing is asked for. Prefer the env file or the prompts:
secrets given as flags end up in shell history.
| Key |
Required |
RESTIC_REPOSITORY |
yes, s3:https://<account>.r2.cloudflarestorage.com/<bucket>[/<prefix>] |
AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, RESTIC_PASSWORD |
yes |
AWS_DEFAULT_REGION |
no, default auto |
SMTP_SERVER |
no; empty means no email reports |
SMTP_PORT, SMTP_SECURITY (starttls/ssl) |
defaults 587 / starttls |
SMTP_USER, SMTP_PASSWORD, MAIL_TO |
when SMTP_SERVER is set |
MAIL_FROM |
no, default SMTP_USER |
Before saving, init checks everything it can and prints ✔ or ✖ with a reason for each:
- restic is installed and 0.16 or newer (if not, it prints the install command for your distro);
- the S3 keys can list, write and delete in the bucket (an R2 token with an IP allow-list is
named as such, with this machine's public IP);
- the repository exists and the password opens it, or, if there is none yet, it offers to create
one (
--yes creates it without asking);
- the SMTP login works, if email is configured, and it can send a test email.
If a check fails, nothing is saved unless you answer "save anyway" at the prompt.
Without --config, the settings are asked for one by one. The profile is saved as
/etc/resticbackups3/<profile>/.env (root only, 0600) and config.toml (0644). After that you
may delete your own copies, but keep RESTIC_PASSWORD in a password manager: without it no
backup can be restored.
Back up
rbs3 backup <profile> [--silent] [--dry-run]
All sources go into one snapshot, tagged rbs3 and profile:<profile>. Before it starts, rbs3
removes stale repository locks and opens the repository; afterwards it shows the repository
size, the latest snapshot's restore size and the profile's snapshot count. A relative exclude
pattern is rooted at each source (thumbs skips <source>/thumbs, **/*.tmp any .tmp file
in it); an absolute one is used as-is. If [freshness_check] is set, a stale or missing matching
file is reported as a warning.
--silent prints nothing but errors; --dry-run shows what would be uploaded.
- Each run writes
/var/log/resticbackups3/<profile>/backup/<time>.txt, with secrets replaced
by ***. Logs older than report.log_keep_days are removed.
- Only one run per profile at a time: a second one exits at once.
- Exit codes:
0 OK, 3 warning (snapshot made, but some files could not be read), 1 failed,
75 another run of this profile is still going, 130 cancelled.
Install
Needs Linux, Python 3.12 or newer, and restic 0.16 or newer.
| Tool |
Install |
Update |
| pipx |
pipx install resticbackups3 |
pipx upgrade resticbackups3 |
| uv |
uv tool install resticbackups3 |
uv tool upgrade resticbackups3 |
| pip (in a venv) |
pip install resticbackups3 |
pip install --upgrade resticbackups3 |
Run rbs3 as your normal user; it asks for sudo itself when it needs it.
Development
python -m venv .venv && . .venv/bin/activate
pip install -e ".[dev]" ruff mypy
git config core.hooksPath .githooks # blocks commits containing strings from notes/deny-list.txt
ruff check . && ruff format --check . && mypy && pytest -n auto
tests/test_integration.py runs the checks against a real restic and S3 endpoint when
RBS3_IT_ENDPOINT, RBS3_IT_BUCKET, RBS3_IT_KEY and RBS3_IT_SECRET are set. CI starts
Versity Gateway for it.
Pull request titles follow Conventional Commits; a merged
feat: or fix: publishes a release.
License
MIT