From 64f4773c01930f2f1a5b62572a737427ec0a1285 Mon Sep 17 00:00:00 2001 From: erebion Date: Fri, 16 Aug 2024 20:26:27 +0200 Subject: [PATCH] add restic prune job --- group_vars/all/all.yml | 1 + roles/unhb_backup_scripts/tasks/main.yml | 24 +++++++++++++++++++ .../templates/restic-prune.service.j2 | 11 +++++++++ .../templates/restic-prune.timer.j2 | 9 +++++++ 4 files changed, 45 insertions(+) create mode 100644 roles/unhb_backup_scripts/templates/restic-prune.service.j2 create mode 100644 roles/unhb_backup_scripts/templates/restic-prune.timer.j2 diff --git a/group_vars/all/all.yml b/group_vars/all/all.yml index f522bdf..7803e3d 100644 --- a/group_vars/all/all.yml +++ b/group_vars/all/all.yml @@ -7,3 +7,4 @@ APT_Periodic_Unattended_Upgrade: "1" restic_repository_location: "sftp:restic_{{ inventory_hostname }}@proxmox.unhb.space:/storage/restic-backup/" restic_start_time: "*-*-* 1:00:00" +restic_prune_start_time: "*-*-* 11:00:00" diff --git a/roles/unhb_backup_scripts/tasks/main.yml b/roles/unhb_backup_scripts/tasks/main.yml index 8802942..d5696da 100644 --- a/roles/unhb_backup_scripts/tasks/main.yml +++ b/roles/unhb_backup_scripts/tasks/main.yml @@ -86,6 +86,17 @@ register: unit when: "ansible_os_family == 'Debian'" +- name: "Template systemd units for restic" + ansible.builtin.template: + src: "restic-prune.service.j2" + dest: "/etc/systemd/system/restic-prune.service" + owner: root + group: root + mode: 'u+rw' + force: true + register: unit + when: "ansible_os_family == 'Debian'" + - name: "Template systemd timers for restic" ansible.builtin.template: src: "restic.timer.j2" @@ -97,6 +108,17 @@ register: unit when: "ansible_os_family == 'Debian'" +- name: "Template systemd timers for restic" + ansible.builtin.template: + src: "restic-prune.timer.j2" + dest: "/etc/systemd/system/restic-prune.timer" + owner: root + group: root + mode: 'u+rw' + force: true + register: unit + when: "ansible_os_family == 'Debian'" + - name: "Reload systemd units" ansible.builtin.systemd: daemon_reload: true @@ -109,6 +131,8 @@ with_items: - "restic@{{ inventory_hostname }}.service" - "restic@{{ inventory_hostname }}.timer" + - "restic-prune.service" + - "restic-prune.timer" when: unit.changed #- name: "Enable systemd units for restic-wasabi" diff --git a/roles/unhb_backup_scripts/templates/restic-prune.service.j2 b/roles/unhb_backup_scripts/templates/restic-prune.service.j2 new file mode 100644 index 0000000..dad1f88 --- /dev/null +++ b/roles/unhb_backup_scripts/templates/restic-prune.service.j2 @@ -0,0 +1,11 @@ +[Unit] +Description=This unit will start pruning restic snapshots +After= +Wants= + +[Service] +Restart=no +Type=simple +ExecStart=/opt/scripts/restic/restic-prune.sh + +[Install] diff --git a/roles/unhb_backup_scripts/templates/restic-prune.timer.j2 b/roles/unhb_backup_scripts/templates/restic-prune.timer.j2 new file mode 100644 index 0000000..9b4bf5d --- /dev/null +++ b/roles/unhb_backup_scripts/templates/restic-prune.timer.j2 @@ -0,0 +1,9 @@ +[Unit] +Description=Timer starting restic-prune.service + +[Timer] +OnCalendar={{ restic_prune_start_time }} +Unit=restic-prune.service + +[Install] +WantedBy=multi-user.target