Torstein-Eide/Borg-Backup-wrapper

This repository contains a small wrapper and templates to run Borg backups with systemd timers, for multiple hosts using per-host environment files.

★ 0Forks 0ShellGitHub ↗Compare

README

Borg Backup wrapper

This repository contains a small wrapper and templates to run Borg backups with systemd timers.

Features

  • Easy environment-based configuration using .env files in env/.
  • systemd unit 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.

Quick overview of important files

  • 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 by borg-run.
  • bin/borg-direct — run an arbitrary borg subcommand 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 latest borg release binary from GitHub, bypassing distro packages.

Requirements

  • BorgBackup (borg) installed and available in PATH.
  • systemd for timer units (if you want scheduled backups).

Setup

  1. 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
  2. If you want the systemd timers enabled, run the installer as root:

    sudo ./install.sh

    install.sh links the templates from systemd/ into /etc/systemd/system, reloads systemd, and enables borg@<name>.timer and borg-check@<name>.timer for any env/*.env files.

    On a laptop or other battery-powered host, set TIMER=daily in env/your-host.env (see template/name.env) before running install.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; leaving TIMER unset (or re-running install.sh after removing/commenting it) removes the override again. [email protected] and [email protected] both have ConditionACPower=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 like OnCalendar= by default, they don't replace them.) [email protected] and [email protected] both have ConditionACPower=true, so a run that fires while on battery is skipped (not queued) and simply waits for the next scheduled trigger.

Usage

  • Manual: run a backup, prune, or integrity check for a specific env:

    bin/borg-run your-host backup bin/borg-run your-host prune bin/borg-run your-host check

  • The wrapper sources env/your-host.env, then invokes the shared logic in bin/borg-common.sh.

  • check (borg check) verifies repository integrity. It's separate from backup/prune — running bin/borg-run your-host with 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.sh enables it automatically alongside borg@<name>.timer.

Configuration notes

  • The env template contains include and exclude lists and references borg-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_DIR can be adjusted in bin/borg-common.sh if desired.
  • For external repositories (e.g., SSH), ensure SSH keys are set up for passwordless access. In .ssh/config, you can specify options like IdentitiesOnly yes to avoid using unwanted keys.
    Host RemoteBorgHost
        IdentityFile ~/.ssh/id_ed25519_borg
        Port 22
        User backup
        hostname 192.0.2.2
        IdentitiesOnly yes

Healthcheck

The common script can send a healthcheck ping to HC_URL if configured in the env file.

Support / Troubleshooting

  • 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.

Contributors

Torstein-Eide

Issues