restic-backup.service.j2 2.0 KB

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