restic-backup.service.j2 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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.path }} {{ folder.exclude if folder.exclude is defined else '' }}
  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 }} forget --keep-within {{ restic_forget_keep_within }}
  28. {% endif -%}
  29. {% if restic_prune %}
  30. ExecStartPost={{ restic_path }} prune
  31. {% endif -%}