This repository contains a small wrapper and templates to run Borg backups with systemd timers.
- Easy environment-based configuration using
.envfiles inenv/. systemdunit templates to run backups on a schedule ([email protected],[email protected]).- A wrapper script that sources an environment file and runs common backup/prune logic.
template/name.env— example environment file (copy and edit per host).bin/borg-run— CLI wrapper to run a named env:borg-run <env-name> [backup|prune|check].bin/borg-common.sh— shared backup and prune implementation used byborg-run.bin/borg-direct— run an arbitraryborgsubcommand against a named env's repo, e.g.borg-direct <env-name> info.install.sh— helper that links systemd templates and enables timers for env files.uninstall.sh— helper that disables timers and removes the linked systemd templates (env files are left untouched).borg-exclude.txt— common exclude patterns used by backups.borg-download.sh— fetch and install the latestborgrelease binary from GitHub, bypassing distro packages.
- BorgBackup (borg) installed and available in PATH.
- systemd for timer units (if you want scheduled backups).
-
Copy the template environment and edit it for your repository and options:
cp template/name.env env/your-host.env # Edit env/your-host.env: set BORG_REPO, HC_URL, and optional BORG_PASSPHRASE -
If you want the systemd timers enabled, run the installer as root:
sudo ./install.sh
install.shlinks the templates fromsystemd/into/etc/systemd/system, reloads systemd, and enablesborg@<name>.timerandborg-check@<name>.timerfor anyenv/*.envfiles.On a laptop or other battery-powered host, set
TIMER=dailyinenv/your-host.env(seetemplate/name.env) before runninginstall.sh. It will install a systemd drop-in (/etc/systemd/system/[email protected]/override.conf) that switches that instance from the default hourly cadence to once a day; leavingTIMERunset (or re-runninginstall.shafter removing/commenting it) removes the override again.[email protected]and[email protected]both haveConditionACPower=true, so a run that fires while on battery is skipped (not queued) and simply waits for the next scheduled trigger.(The empty
OnCalendar=first clears the hourly setting from the template — drop-ins append to list directives likeOnCalendar=by default, they don't replace them.)[email protected]and[email protected]both haveConditionACPower=true, so a run that fires while on battery is skipped (not queued) and simply waits for the next scheduled trigger.
-
Manual: run a backup, prune, or integrity check for a specific env:
bin/borg-run your-host backupbin/borg-run your-host prunebin/borg-run your-host check -
The wrapper sources
env/your-host.env, then invokes the shared logic inbin/borg-common.sh. -
check(borg check) verifies repository integrity. It's separate from backup/prune — runningbin/borg-run your-hostwith no mode, or via the hourly[email protected], never runs it. A separate[email protected]runs it twice a year (Jan 25 and Jul 25);install.shenables it automatically alongsideborg@<name>.timer.
- The env template contains
includeandexcludelists and referencesborg-exclude.txt. - Passphrase: the template shows how to set
BORG_PASSPHRASE(optional). For better security, use a keyfile or an agent rather than embedding a passphrase in plaintext. BORG_CACHE_DIRcan be adjusted inbin/borg-common.shif desired.- For external repositories (e.g., SSH), ensure SSH keys are set up for passwordless access. In
.ssh/config, you can specify options likeIdentitiesOnly yesto avoid using unwanted keys.Host RemoteBorgHost IdentityFile ~/.ssh/id_ed25519_borg Port 22 User backup hostname 192.0.2.2 IdentitiesOnly yes
The common script can send a healthcheck ping to HC_URL if configured in the env file.
- Check the systemd unit status and logs for a timer:
systemctl status [email protected](or[email protected]for the integrity-check timer). - Journal logs from the service are collected by the script and sent with the healthcheck if enabled.
Thanks This small toolset is intended to simplify running Borg with systemd and per-host env files.