feat(restic): add optional hook and optional unlock

This commit is contained in:
transcaffeine 2024-05-05 16:19:10 +02:00
parent 13d40341a0
commit c9bed947f9
Signed by: transcaffeine
GPG Key ID: 03624C433676E465
3 changed files with 8 additions and 3 deletions

View File

@ -8,7 +8,7 @@
when: restic_create_user when: restic_create_user
- name: Ensure either backup_paths or backup_stdin_command is populated - name: Ensure either backup_paths or backup_stdin_command is populated
when: restic_backup_paths|length > 0 and restic_backup_stdin_command when: restic_backup_paths|length > 0 and restic_backup_stdin_command and false
fail: fail:
msg: "Setting both `restic_backup_paths` and `restic_backup_stdin_command` is not supported" msg: "Setting both `restic_backup_paths` and `restic_backup_stdin_command` is not supported"

View File

@ -13,8 +13,14 @@ Environment=RESTIC_PASSWORD={{ restic_repo_password }}
Environment=AWS_ACCESS_KEY_ID={{ restic_s3_key_id }} Environment=AWS_ACCESS_KEY_ID={{ restic_s3_key_id }}
Environment=AWS_SECRET_ACCESS_KEY={{ restic_s3_access_key }} Environment=AWS_SECRET_ACCESS_KEY={{ restic_s3_access_key }}
{% endif %} {% endif %}
{% if restic_unlock_before_backup | default(false) %}
ExecStartPre=-/bin/sh -c '/usr/bin/restic unlock'
{% endif %}
ExecStartPre=-/bin/sh -c '/usr/bin/restic snapshots || /usr/bin/restic init' ExecStartPre=-/bin/sh -c '/usr/bin/restic snapshots || /usr/bin/restic init'
{% if restic_backup_pre_hook %}
ExecStart=-{{ restic_backup_pre_hook }}
{% endif %}
{% if restic_backup_stdin_command %} {% if restic_backup_stdin_command %}
ExecStart=/bin/sh -c '{{ restic_backup_stdin_command }} | /usr/bin/restic backup --verbose --stdin --stdin-filename {{ restic_backup_stdin_command_filename }}' ExecStart=/bin/sh -c '{{ restic_backup_stdin_command }} | /usr/bin/restic backup --verbose --stdin --stdin-filename {{ restic_backup_stdin_command_filename }}'
{% else %} {% else %}

View File

@ -1,9 +1,8 @@
[Unit] [Unit]
Description=Run {{ restic_job_name }} Description=Run {{ restic_timer_description | default(restic_job_name) }}
[Timer] [Timer]
OnCalendar={{ restic_policy.frequency }} OnCalendar={{ restic_policy.frequency }}
Persistent=True
Unit={{ restic_systemd_unit_naming_scheme }}.service Unit={{ restic_systemd_unit_naming_scheme }}.service
[Install] [Install]