2023-07-28 13:33:18 +00:00
|
|
|
[Unit]
|
|
|
|
Description={{ restic_job_description }}
|
|
|
|
|
|
|
|
[Service]
|
2024-04-14 13:14:02 +00:00
|
|
|
Type=simple
|
2023-07-28 13:33:18 +00:00
|
|
|
User={{ restic_user }}
|
|
|
|
WorkingDirectory={{ restic_systemd_working_directory }}
|
|
|
|
SyslogIdentifier={{ restic_systemd_syslog_identifier }}
|
|
|
|
|
|
|
|
Environment=RESTIC_REPOSITORY={{ restic_repo_url }}
|
|
|
|
Environment=RESTIC_PASSWORD={{ restic_repo_password }}
|
2024-09-18 16:20:12 +00:00
|
|
|
{% for kv in restic_complete_environment | dict2items %}
|
|
|
|
Environment={{ kv.key }}={{ kv.value }}
|
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
{% if restic_init | default(true) %}
|
|
|
|
ExecStartPre=-/bin/sh -c '/usr/bin/restic snapshots || /usr/bin/restic init'
|
2023-07-28 13:33:18 +00:00
|
|
|
{% endif %}
|
2024-05-05 14:19:10 +00:00
|
|
|
{% if restic_unlock_before_backup | default(false) %}
|
2024-09-18 16:20:12 +00:00
|
|
|
ExecStartPre=-/bin/sh -c 'sleep 3 && /usr/bin/restic unlock'
|
2024-05-05 14:19:10 +00:00
|
|
|
{% endif %}
|
|
|
|
{% if restic_backup_pre_hook | default(false) %}
|
2024-09-18 16:20:12 +00:00
|
|
|
ExecStartPre=-{{ restic_backup_pre_hook }}
|
2024-05-05 14:19:10 +00:00
|
|
|
{% endif %}
|
2023-07-28 13:33:18 +00:00
|
|
|
{% if restic_backup_stdin_command %}
|
2024-09-18 16:20:12 +00:00
|
|
|
ExecStart=/bin/sh -c '{{ restic_backup_stdin_command }} | /usr/bin/restic backup \
|
|
|
|
--retry-lock {{ restic_retry_lock | default('5m') }} \
|
|
|
|
--verbose --stdin \
|
|
|
|
--stdin-filename {{ restic_backup_stdin_command_filename }}'
|
2023-07-28 13:33:18 +00:00
|
|
|
{% else %}
|
2024-09-18 16:20:12 +00:00
|
|
|
ExecStart=/opt/restic-backup-directories.sh {{ restic_backup_paths | join(' ') }}
|
|
|
|
{% endif %}
|
|
|
|
{% if restic_forget_prune | default(true) %}
|
|
|
|
ExecStartPost=/usr/bin/restic forget --prune \
|
|
|
|
--retry-lock {{ restic_retry_lock | default('5m') }} \
|
|
|
|
--keep-within={{ restic_policy.keep_within }} \
|
|
|
|
--keep-hourly={{ restic_policy.hourly }} \
|
|
|
|
--keep-daily={{ restic_policy.daily }} \
|
|
|
|
--keep-weekly={{ restic_policy.weekly }} \
|
|
|
|
--keep-monthly={{ restic_policy.monthly }} \
|
|
|
|
--keep-yearly={{ restic_policy.yearly }}
|
|
|
|
{% endif %}
|
|
|
|
{% if restic_list_snapshots | default(true) %}
|
|
|
|
ExecStartPost=-/usr/bin/restic snapshots --retry-lock {{ restic_retry_lock | default('5m') }}
|
2023-07-28 13:33:18 +00:00
|
|
|
{% endif %}
|
2024-05-05 14:19:10 +00:00
|
|
|
{% if restic_backup_post_hook | default(false) %}
|
2024-04-14 13:14:02 +00:00
|
|
|
ExecStartPost=-{{ restic_backup_post_hook }}
|
|
|
|
{% endif %}
|
2024-09-18 16:20:12 +00:00
|
|
|
{% if restic_check | default(true) %}
|
|
|
|
ExecStartPost=/usr/bin/restic check --retry-lock {{ restic_retry_lock | default('5m') }}
|
|
|
|
{% endif %}
|