Restic Ansible role https://restic.net/
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-11-13 01:16:25 +00:00
.forgejo/workflows fix: moved to forgejo pipeline 2026-10-13 11:59:14 +07:00
defaults feat: added restic database backups 2026-11-13 02:16:14 +01:00
meta feat: initial restic setup 2026-04-27 14:25:12 +02:00
tasks feat: added restic database backups 2026-11-13 02:16:14 +01:00
.gitignore feat: initial restic setup 2026-04-27 14:25:12 +02:00
CHANGELOG.md feat: added restic database backups 2026-11-13 02:16:14 +01:00
LICENSE feat: initial restic setup 2026-04-27 14:25:12 +02:00
README.md Prettified Code! 2026-11-13 01:16:25 +00:00

Restic

Installs restic and configures scheduled backups via cron to local or SFTP repositories.

Requirements

  • Debian/Ubuntu host
  • become: true in the calling playbook (installs packages, writes to /root/ and /etc/)

Variables

Variable Default Description
restic_repos [] List of repository definitions. See Repository structure.
restic_cron 0 3 * * * Cron schedule for backup jobs.
restic_cron_cleanup 0 4 * * 0 Cron schedule for restic forget --prune.
restic_keep_hourly 0 Number of hourly snapshots to keep (0 = not passed).
restic_keep_daily 7 Number of daily snapshots to keep.
restic_keep_weekly 4 Number of weekly snapshots to keep.
restic_keep_monthly 12 Number of monthly snapshots to keep.
restic_shell_env false /etc/profile.d/restic.sh: repo env of the first repo (plain restic snapshots works as root in a login shell) and a restic-<name> alias per repo.
restic_uninstall false Removes all files written by this role.
restic_purge false Also removes packages, logs, and local repo data. Requires restic_uninstall: true. Irreversible.

Repository structure

Each entry in restic_repos supports the following fields:

Field Required Description
name Yes Unique identifier. Used in cron filenames and password file paths.
password Yes Restic encryption password. Generate with openssl rand -hex 32.
target Yes Full restic repository path. Use sftp:<alias>:/path for SFTP or an absolute path for local repos.
sources * List of paths to back up. *At least one of sources/commands.
commands * List of {name, command, only_if?}: stdout of command saved as file name (--stdin-from-command, restic >= 0.17); a failing command leaves no snapshot; only_if = shell test that must pass first.
host No Fixed snapshot host name (--host) for backup and forget.
retry_lock No Wait this long for a locked repo (--retry-lock, restic >= 0.16), for repos shared by hosts.
sftp_config No SFTP connection settings. Omit entirely for local repositories.
sftp_config.alias SFTP SSH config Host alias. Must match the alias used in target.
sftp_config.hostname SFTP Real hostname for the SSH connection.
sftp_config.username SFTP SSH username.
sftp_config.ssh_key No SSH private key content. Omit to use an existing key or agent.
sftp_config.port No SSH port. Default 23.

Usage

SFTP backup:

restic_repos:
  - name: offsite
    password: "{{ vault_restic_password }}"
    target: sftp:myhost:/backups/offsite
    sources:
      - /docker
      - /data
    sftp_config:
      alias: myhost
      hostname: backup.example.com
      username: backupuser
      ssh_key: "{{ vault_restic_ssh_key }}"

Local backup:

restic_repos:
  - name: local
    password: "{{ vault_restic_password }}"
    target: /mnt/backup/restic
    sources:
      - /data

Multiple repos with custom retention:

restic_repos:
  - name: offsite
    password: "{{ vault_restic_offsite_password }}"
    target: sftp:myhost:/backups/offsite
    sources:
      - /docker
    sftp_config:
      alias: myhost
      hostname: backup.example.com
      username: backupuser

  - name: local
    password: "{{ vault_restic_local_password }}"
    target: /mnt/backup/restic
    sources:
      - /docker
      - /data

restic_keep_daily: 14
restic_keep_weekly: 8
restic_keep_monthly: 24

Uninstall

To remove all files written by this role (password files, cron jobs, SSH keys, SSH config entries):

restic_uninstall: true

To also remove the restic and cron packages, the log directory, and local repository data (irreversible):

restic_uninstall: true
restic_purge: true

Notes

  • Password files are written to /root/.restic-password-<name> with mode 0600.
  • Backup logs land at /var/log/restic/<name>_<sanitized_source>.log.
  • SFTP repository data is never removed by this role, even with restic_purge: true.