infrastructure/roles/lvm_self_backup/templates/backup-lvm.service
saibotk 43535443c2
fix(backup-lvm): ExecStopPost command using bash syntax
This cannot be used in a systemd exec command. Ooopsie
2024-02-21 22:12:19 +01:00

33 lines
1 KiB
Desktop File

[Unit]
Description=Start lvm backup using duplicity.
[Service]
Type=oneshot
TimeoutSec=20h
# Creating snapshots
{% for item in lvm_self_backup_vols %}
ExecStartPre=/usr/sbin/lvcreate -L 1G -n {{ item.lv_name }}_snap -s {{ item.vg_name }}/{{ item.lv_name }}
{% endfor %}
# Mounting snapshots
{% for item in lvm_self_backup_vols %}
ExecStartPre=/usr/bin/mount -o ro,nosuid,noexec{% if item.fstype is defined and item.fstype == "xfs" %},nouuid{% endif %} -t {{ item.fstype | default("ext4") }} /dev/{{ item.vg_name }}/{{ item.lv_name }}_snap /lvm_self_backup_snapshots/{{ item.vg_name }}-{{ item.lv_name }}
{% endfor %}
ExecStart=/usr/local/bin/backup-lvm
# Make sure duplicity container is gone
ExecStopPost=/usr/bin/docker rm --force duplicity-backup-lvm
# Unmount snapshots
{% for item in lvm_self_backup_vols %}
ExecStopPost=/usr/bin/umount /dev/{{ item.vg_name }}/{{ item.lv_name }}_snap
{% endfor %}
# Remove snapshots
{% for item in lvm_self_backup_vols %}
ExecStopPost=/usr/sbin/lvremove -f {{ item.vg_name }}/{{ item.lv_name }}_snap
{% endfor %}