restic-backup.service.j2 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. [Unit]
  2. Description=Restic backup
  3. [Service]
  4. Type=oneshot
  5. User={{ restic_user }}
  6. CPUQuota={{ 25 * ansible_processor_vcpus }}%
  7. Nice=19
  8. IOSchedulingClass=best-effort
  9. IOSchedulingPriority=7
  10. {% if restic_ssh_enabled %}
  11. Environment="RESTIC_REPOSITORY=sftp:{{ restic_ssh_host }}:{{ restic_repository_name }}"
  12. {% else %}
  13. Environment="RESTIC_REPOSITORY={{ restic_repository }}"
  14. {% endif -%}
  15. Environment="RESTIC_PASSWORD={{ restic_password}}"
  16. {% if restic_aws_access_key_id is defined and restic_aws_secret_access_key is defined %}
  17. Environment="AWS_ACCESS_KEY_ID={{ restic_aws_access_key_id}}"
  18. Environment="AWS_SECRET_ACCESS_KEY={{ restic_aws_secret_access_key}}"
  19. {% endif %}
  20. {% if restic_check %}
  21. ExecStartPre={{ restic_path }} check
  22. {% endif -%}
  23. {% for folder in restic_folders_combined %}
  24. ExecStart={{ restic_path }} backup --verbose {{ folder }}
  25. {% endfor -%}
  26. {% for database in restic_databases %}
  27. ExecStart=/bin/sh -c "{{ database.dump_command }} {{ '| pigz --rsyncable |' if restic_dump_compression_enabled else '|' }} {{ restic_path }} backup --verbose --stdin --stdin-filename {{ database.name }}{{ '.sql.gz' if restic_dump_compression_enabled else '.sql' }}"
  28. {% endfor -%}
  29. {% if restic_forget %}
  30. ExecStartPost={{ restic_path }} {% if restic_keep_last is defined and restic_keep_last != false %}--keep-last{{ restic_keep_last }}{% endif %}
  31. {% if restic_keep_hourly is defined and restic_keep_hourly != false %}--keep-hourly {{ restic_keep_hourly }}{% endif %}
  32. {% if restic_keep_daily is defined and restic_keep_daily != false %}--keep-daily {{ restic_keep_daily }}{% endif %}
  33. {% if restic_keep_weekly is defined and restic_keep_weekly != false %}--keep-weekly {{ restic_keep_weekly }}{% endif %}
  34. {% if restic_keep_monthly is defined and restic_keep_monthly != false %}--keep-monthly {{ restic_keep_monthly }}{% endif %}
  35. {% if restic_keep_yearly is defined and restic_keep_yearly != false %}--keep-yearly {{ restic_keep_yearly }}{% endif %}
  36. {% if restic_keep_within is defined and restic_keep_within != false %}--keep-within {{ restic_keep_within }}{% endif %}
  37. {% endif -%} forget
  38. {% if restic_prune %}
  39. ExecStartPost={{ restic_path }} prune
  40. {% endif -%}