ansible-restic/templates/restic-backup.service.j2
2025-08-12 18:43:17 +01:00

45 lines
1.5 KiB
Django/Jinja

[Unit]
Description=Restic backup
{% if restic_failure_webhook_url is not none %}
OnFailure=restic-failure.service
{% endif %}
[Service]
Type=oneshot
User={{ restic_user }}
CPUQuota={{ 25 * ansible_processor_vcpus }}%
{% if restic_ssh_enabled %}
Environment="RESTIC_REPOSITORY=sftp:{{ restic_ssh_host }}:{{ restic_repository_name }}"
{% else %}
Environment="RESTIC_REPOSITORY={{ restic_repository }}"
{% endif -%}
Environment="RESTIC_PASSWORD={{ restic_password}}"
{% if restic_aws_access_key_id is defined and restic_aws_secret_access_key is defined %}
Environment="AWS_ACCESS_KEY_ID={{ restic_aws_access_key_id}}"
Environment="AWS_SECRET_ACCESS_KEY={{ restic_aws_secret_access_key}}"
{% endif %}
ExecStartPre=/bin/sh -c '{{ restic_path }} snapshots || {{ restic_path }} init'
{% if restic_check %}
ExecStartPre={{ restic_path }} check
{% endif -%}
{% for folder in restic_folders_combined %}
ExecStart={{ restic_path }} backup --verbose {{ folder.path }} {{ folder.exclude if folder.exclude is defined else '' }}
{% endfor -%}
{% for database in restic_databases %}
ExecStart=/bin/sh -c "{{ database.dump_command }} {{ '| pigz |' if restic_dump_compression_enabled else '|' }} {{ restic_path }} backup --verbose --stdin --stdin-filename {{ database.name }}{{ '.dump.gz' if restic_dump_compression_enabled else '.dump' }}"
{% endfor -%}
{% if restic_forget %}
ExecStartPost={{ restic_path }} forget {{ restic_forget_args }}
{% endif -%}
{% if restic_prune %}
ExecStartPost={{ restic_path }} prune
{% endif -%}