Markus Michalski FAQ

restic-backup-suite: Technical details

Technical details of restic-backup-suite: backup.sh sequence, restic calls, retention and check, SSH configuration, cleanup, temp directories, file layout and exit codes.

Deutsche Version

Back to overview


Technical details

Files in the repository

File Purpose
backup.sh Backup, retention, verification
restore.sh Interactive restore
inspect.sh Snapshot browser
install.sh Installer and uninstaller
config.example.sh Configuration template
Makefile Shortcuts for the installer and ShellCheck
.github/workflows/shellcheck.yml CI: syntax check and ShellCheck for all .sh files

All four scripts run with set -o errexit -o nounset -o pipefail. backup.sh, restore.sh and inspect.sh additionally have a cleanup handler on EXIT, ERR, INT and TERM. The cleanup runs when the script exits. On a non-zero exit the handler logs Script exited with code: N. install.sh has no trap.

Sequence of backup.sh

graph TD
    A["Start"] --> B["Read options, load config, check root and restic"]
    B --> C["Create temp directory for dumps"]
    C --> D{"dump-only?"}
    D -->|yes| E["Database dumps only, end"]
    D -->|no| F["Write SSH config and test SFTP, sftp only"]
    F --> G["Check repository, initialise if needed"]
    G --> H["Stop systemd services"]
    H --> I["Stop Docker services"]
    I --> J["Database dumps"]
    J --> K["restic backup"]
    K --> L["restic forget with prune"]
    L --> M["restic check, stats, snapshots"]
    M --> N["Write success marker"]
    N --> O["Cleanup: remove temp, start services"]

restic commands issued

Step Command
Check repository restic snapshots. If it fails for any reason, restic init follows
Backup restic backup --compression max --exclude-caches --exclude-if-present <name> --one-file-system --verbose <excludes> <paths> <dump directory> --tag automated
Retention restic forget --keep-daily <n> --keep-weekly <n> --keep-monthly <n> --prune --cleanup-cache
Verification restic check --read-data-subset=<REPO_CHECK_SUBSET>
Output restic stats --mode restore-size and restic snapshots --last 5

Retention and verification only run if restic backup succeeded. If they fail, the script logs a warning and the exit code stays 0. A failure in restic stats or restic snapshots afterwards, however, ends the script with an error code and the marker is not written.

restic forget runs without filters. It groups by restic's default (host and paths) and applies to all snapshots in the repository, not only those tagged automated.

SSH configuration

For sftp: repositories backup.sh creates the config.d directory next to the SSH_KEY_FILE file (for /root/.ssh/id_ed25519 that is /root/.ssh/config.d) and writes the file restic-backup there with the host block (mode 600). If the config file in the same directory lacks the line Include <directory>/config.d/*, the script prepends it and leaves the rest untouched. If the key is missing, it logs a warning and the matching ssh-keygen command.

Temporary directories

Directory Content Lifetime
/tmp/restic-db-dump-XXXXXX SQL dumps Removed in the cleanup
/tmp/restic-restore-XXXXXX Restored files Stays until you delete it

Because the dump path inside the snapshot is /tmp/restic-db-dump-XXXXXX, restic-inspect (item 6) and the restore find the dumps by that pattern.

Built-in limits

Exit codes

Code Meaning
0 Success
non-zero Error, see Monitoring