From 26214e3f7c5343fa30d2ff1ae71a6cf7197b6f3e Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 19 May 2021 16:52:36 +0200 Subject: initial version of syncoid autosuspender --- roles/storage/zfs/syncoid/tasks/main.yml | 34 +++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'roles/storage/zfs/syncoid/tasks/main.yml') diff --git a/roles/storage/zfs/syncoid/tasks/main.yml b/roles/storage/zfs/syncoid/tasks/main.yml index a01900b1..7c489baa 100644 --- a/roles/storage/zfs/syncoid/tasks/main.yml +++ b/roles/storage/zfs/syncoid/tasks/main.yml @@ -43,8 +43,8 @@ loop_control: label: "{{ item.key }}" template: - src: systemd.service.j2 - dest: "/etc/systemd/system/syncoid-{{ item.key }}.service" + src: run.service.j2 + dest: "/etc/systemd/system/syncoid-run-{{ item.key }}.service" - name: create systemd timer units for periodic backups loop: "{{ zfs_syncoid_sources | dict2items }}" @@ -52,8 +52,8 @@ label: "{{ item.key }}" when: "'periodic' in item.value" template: - src: systemd.timer.j2 - dest: "/etc/systemd/system/syncoid-{{ item.key }}.timer" + src: run.timer.j2 + dest: "/etc/systemd/system/syncoid-run-{{ item.key }}.timer" - name: make sure systemd timer units for periodic backups are enabled and started loop: "{{ zfs_syncoid_sources | dict2items }}" @@ -62,6 +62,30 @@ when: "'periodic' in item.value" systemd: daemon_reload: yes - name: "syncoid-{{ item.key }}.timer" + name: "syncoid-run-{{ item.key }}.timer" state: started enabled: yes + +- name: enable autosuspend + when: zfs_syncoid_autosuspend + block: + - name: install autosuspend script + template: + src: autosuspend.py.j2 + dest: /usr/local/bin/syncoid-autosuspend.py + mode: 0755 + + - name: install autosuspend systemd units + loop: + - service + - timer + template: + src: "autosuspend.{{ item }}.j2" + dest: "/etc/systemd/system/syncoid-autosuspend.{{ item }}" + + - name: make sure autosuspend timer unit is enabled and started + systemd: + daemon_reload: yes + name: syncoid-autosuspend.timer + enabled: yes + state: started -- cgit v1.2.3 From a23e7f8055818a1d95b005998f094a249f71b490 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 19 May 2021 18:55:24 +0200 Subject: syncoid: autosuspend cleanup and cooldown --- roles/storage/zfs/syncoid/tasks/main.yml | 15 +++++++++++++++ roles/storage/zfs/syncoid/templates/run.service.j2 | 3 +++ 2 files changed, 18 insertions(+) (limited to 'roles/storage/zfs/syncoid/tasks/main.yml') diff --git a/roles/storage/zfs/syncoid/tasks/main.yml b/roles/storage/zfs/syncoid/tasks/main.yml index 7c489baa..bab61a89 100644 --- a/roles/storage/zfs/syncoid/tasks/main.yml +++ b/roles/storage/zfs/syncoid/tasks/main.yml @@ -69,6 +69,21 @@ - name: enable autosuspend when: zfs_syncoid_autosuspend block: + - name: generate syncoid post script + copy: + content: | + #!/bin/bash + + echo "running sanoid --prune to cleanup old snapshots" + sleep 5 + systemctl start --wait sanoid-prune.service + + echo "wait 60s (autosuspend cooldown period)" + sleep 60 + echo "done." + dest: /var/lib/syncoid/syncoid_post + mode: 0755 + - name: install autosuspend script template: src: autosuspend.py.j2 diff --git a/roles/storage/zfs/syncoid/templates/run.service.j2 b/roles/storage/zfs/syncoid/templates/run.service.j2 index 0d214595..33283576 100644 --- a/roles/storage/zfs/syncoid/templates/run.service.j2 +++ b/roles/storage/zfs/syncoid/templates/run.service.j2 @@ -6,6 +6,9 @@ Type=oneshot {% for path,config in item.value.paths.items() %} ExecStart=/var/lib/syncoid/syncoid_wrapper --dumpsnaps --quiet {{ config.recursive | default(false) | ternary('-r ', '') }}{{ config.skip_parent | default(false) | ternary('--skip-parent ', '') }}{% for re in config.exclude | default([]) %}--exclude='{{ re }}' {% endfor %}{% if 'ssh_port' in item.value %}--sshport {{ item.value.ssh_port }} {% endif %}root@{{ item.value.ssh_hostname }}:{{ path }} {{ zfs_syncoid_target_pool }}/{{ item.key }}/{{ path }} {% endfor %} +{% if zfs_syncoid_autosuspend %} +ExecStart=/var/lib/syncoid/syncoid_post +{% endif %} {% if 'periodic' in item.value %} TimeoutStartSec={{ item.value.periodic.timeout }} {% endif %} -- cgit v1.2.3 From 389f7be86f07a08a6282e02913a676aeef328db5 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 19 May 2021 23:39:10 +0200 Subject: syncoid: run vs pull and fix autosuspend timer --- roles/storage/zfs/syncoid/tasks/main.yml | 15 ++++++++++----- .../zfs/syncoid/templates/autosuspend.timer.j2 | 2 +- .../storage/zfs/syncoid/templates/pull.service.j2 | 22 ++++++++++++++++++++++ roles/storage/zfs/syncoid/templates/pull.timer.j2 | 9 +++++++++ roles/storage/zfs/syncoid/templates/run.service.j2 | 22 ---------------------- roles/storage/zfs/syncoid/templates/run.timer.j2 | 9 --------- 6 files changed, 42 insertions(+), 37 deletions(-) create mode 100644 roles/storage/zfs/syncoid/templates/pull.service.j2 create mode 100644 roles/storage/zfs/syncoid/templates/pull.timer.j2 delete mode 100644 roles/storage/zfs/syncoid/templates/run.service.j2 delete mode 100644 roles/storage/zfs/syncoid/templates/run.timer.j2 (limited to 'roles/storage/zfs/syncoid/tasks/main.yml') diff --git a/roles/storage/zfs/syncoid/tasks/main.yml b/roles/storage/zfs/syncoid/tasks/main.yml index bab61a89..6232eea7 100644 --- a/roles/storage/zfs/syncoid/tasks/main.yml +++ b/roles/storage/zfs/syncoid/tasks/main.yml @@ -43,8 +43,8 @@ loop_control: label: "{{ item.key }}" template: - src: run.service.j2 - dest: "/etc/systemd/system/syncoid-run-{{ item.key }}.service" + src: pull.service.j2 + dest: "/etc/systemd/system/syncoid-pull-{{ item.key }}.service" - name: create systemd timer units for periodic backups loop: "{{ zfs_syncoid_sources | dict2items }}" @@ -52,8 +52,8 @@ label: "{{ item.key }}" when: "'periodic' in item.value" template: - src: run.timer.j2 - dest: "/etc/systemd/system/syncoid-run-{{ item.key }}.timer" + src: pull.timer.j2 + dest: "/etc/systemd/system/syncoid-pull-{{ item.key }}.timer" - name: make sure systemd timer units for periodic backups are enabled and started loop: "{{ zfs_syncoid_sources | dict2items }}" @@ -62,7 +62,7 @@ when: "'periodic' in item.value" systemd: daemon_reload: yes - name: "syncoid-run-{{ item.key }}.timer" + name: "syncoid-pull-{{ item.key }}.timer" state: started enabled: yes @@ -84,6 +84,11 @@ dest: /var/lib/syncoid/syncoid_post mode: 0755 + - name: install python deps + apt: + name: "{{ python_basename }}-dbus" + state: present + - name: install autosuspend script template: src: autosuspend.py.j2 diff --git a/roles/storage/zfs/syncoid/templates/autosuspend.timer.j2 b/roles/storage/zfs/syncoid/templates/autosuspend.timer.j2 index 5c0b3329..40852739 100644 --- a/roles/storage/zfs/syncoid/templates/autosuspend.timer.j2 +++ b/roles/storage/zfs/syncoid/templates/autosuspend.timer.j2 @@ -2,7 +2,7 @@ Description=automatic system suspender for syncoid-based backups [Timer] -OnCalendar=*-*-* *-03/10-00 +OnCalendar=*-*-* *:03/10:00 [Install] WantedBy=timers.target diff --git a/roles/storage/zfs/syncoid/templates/pull.service.j2 b/roles/storage/zfs/syncoid/templates/pull.service.j2 new file mode 100644 index 00000000..33283576 --- /dev/null +++ b/roles/storage/zfs/syncoid/templates/pull.service.j2 @@ -0,0 +1,22 @@ +[Unit] +Description=syncoid-based backup for {{ item.key }} + +[Service] +Type=oneshot +{% for path,config in item.value.paths.items() %} +ExecStart=/var/lib/syncoid/syncoid_wrapper --dumpsnaps --quiet {{ config.recursive | default(false) | ternary('-r ', '') }}{{ config.skip_parent | default(false) | ternary('--skip-parent ', '') }}{% for re in config.exclude | default([]) %}--exclude='{{ re }}' {% endfor %}{% if 'ssh_port' in item.value %}--sshport {{ item.value.ssh_port }} {% endif %}root@{{ item.value.ssh_hostname }}:{{ path }} {{ zfs_syncoid_target_pool }}/{{ item.key }}/{{ path }} +{% endfor %} +{% if zfs_syncoid_autosuspend %} +ExecStart=/var/lib/syncoid/syncoid_post +{% endif %} +{% if 'periodic' in item.value %} +TimeoutStartSec={{ item.value.periodic.timeout }} +{% endif %} +PrivateTmp=yes +ProtectHome=yes +ProtectKernelTunables=yes +ProtectControlGroups=yes +RestrictRealtime=yes + +[Install] +WantedBy=multi-user.target diff --git a/roles/storage/zfs/syncoid/templates/pull.timer.j2 b/roles/storage/zfs/syncoid/templates/pull.timer.j2 new file mode 100644 index 00000000..cc252854 --- /dev/null +++ b/roles/storage/zfs/syncoid/templates/pull.timer.j2 @@ -0,0 +1,9 @@ +[Unit] +Description=syncoid-based backup for {{ item.key }} + +[Timer] +OnCalendar={{ item.value.periodic.schedule }} +WakeSystem={{ zfs_syncoid_autosuspend | ternary('true', 'false') }} + +[Install] +WantedBy=timers.target diff --git a/roles/storage/zfs/syncoid/templates/run.service.j2 b/roles/storage/zfs/syncoid/templates/run.service.j2 deleted file mode 100644 index 33283576..00000000 --- a/roles/storage/zfs/syncoid/templates/run.service.j2 +++ /dev/null @@ -1,22 +0,0 @@ -[Unit] -Description=syncoid-based backup for {{ item.key }} - -[Service] -Type=oneshot -{% for path,config in item.value.paths.items() %} -ExecStart=/var/lib/syncoid/syncoid_wrapper --dumpsnaps --quiet {{ config.recursive | default(false) | ternary('-r ', '') }}{{ config.skip_parent | default(false) | ternary('--skip-parent ', '') }}{% for re in config.exclude | default([]) %}--exclude='{{ re }}' {% endfor %}{% if 'ssh_port' in item.value %}--sshport {{ item.value.ssh_port }} {% endif %}root@{{ item.value.ssh_hostname }}:{{ path }} {{ zfs_syncoid_target_pool }}/{{ item.key }}/{{ path }} -{% endfor %} -{% if zfs_syncoid_autosuspend %} -ExecStart=/var/lib/syncoid/syncoid_post -{% endif %} -{% if 'periodic' in item.value %} -TimeoutStartSec={{ item.value.periodic.timeout }} -{% endif %} -PrivateTmp=yes -ProtectHome=yes -ProtectKernelTunables=yes -ProtectControlGroups=yes -RestrictRealtime=yes - -[Install] -WantedBy=multi-user.target diff --git a/roles/storage/zfs/syncoid/templates/run.timer.j2 b/roles/storage/zfs/syncoid/templates/run.timer.j2 deleted file mode 100644 index cc252854..00000000 --- a/roles/storage/zfs/syncoid/templates/run.timer.j2 +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -Description=syncoid-based backup for {{ item.key }} - -[Timer] -OnCalendar={{ item.value.periodic.schedule }} -WakeSystem={{ zfs_syncoid_autosuspend | ternary('true', 'false') }} - -[Install] -WantedBy=timers.target -- cgit v1.2.3