Skip to content
Snippets Groups Projects
postgres-backup-s3.service.j2 2.35 KiB
Newer Older
Michael Hollister's avatar
Michael Hollister committed
#jinja2: lstrip_blocks: "True"
[Unit]
Description=Periodically back up a PostgreSQL database to AWS S3, and to restore from the backup as needed.
{% for service in postgres_backup_s3_systemd_required_services_list %}
Requires={{ service }}
After={{ service }}
{% endfor %}
{% for service in postgres_backup_s3_systemd_wanted_services_list %}
Wants={{ service }}
{% endfor %}

DefaultDependencies=no

[Service]
Type=simple
Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}"
ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop --time={{ devture_systemd_docker_base_container_stop_grace_time_seconds }} {{ postgres_backup_s3_identifier }} 2>/dev/null || true'
ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm {{ postgres_backup_s3_identifier }} 2>/dev/null || true'

ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \
			--rm \
			--name={{ postgres_backup_s3_identifier }} \
			--log-driver=none \
			--user={{ matrix_user_uid }}:{{ matrix_user_gid }} \
			--cap-drop=ALL \
			--read-only \
			--network={{ postgres_backup_s3_container_network }} \
			{% for arg in postgres_backup_s3_container_extra_arguments %}
			{{ arg }} \
			{% endfor %}
			{{ postgres_backup_s3_docker_image }}

{% for network in postgres_backup_s3_container_additional_networks %}
ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} network connect {{ network }} {{ postgres_backup_s3_identifier }}
{% endfor %}

ExecStart={{ devture_systemd_docker_base_host_command_docker }} start --attach {{ postgres_backup_s3_identifier }}

ExecStop=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop --time={{ devture_systemd_docker_base_container_stop_grace_time_seconds }} {{ postgres_backup_s3_identifier }} 2>/dev/null || true'
ExecStop=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm {{ postgres_backup_s3_identifier }} 2>/dev/null || true'
ExecReload={{ devture_systemd_docker_base_host_command_docker }} exec {{ postgres_backup_s3_identifier }} /bin/sh -c 'kill -HUP 1'
Restart=always
RestartSec=30
SyslogIdentifier={{ postgres_backup_s3_identifier }}

[Install]
WantedBy=multi-user.target