From 5ac24196dc93a3b52fac09061332c1c97255e345 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 26 Sep 2019 21:08:04 +0000 Subject: [PATCH] [fix] the management station should work --- tasks/management-keys.yml | 2 +- tasks/management.yml | 29 +++++++++++++++++++++++++++++ templates/prune.host.sh.j2 | 12 ++++++++++++ templates/prune.sh.j2 | 17 +---------------- 4 files changed, 43 insertions(+), 17 deletions(-) create mode 100644 templates/prune.host.sh.j2 diff --git a/tasks/management-keys.yml b/tasks/management-keys.yml index e06d884..92f352c 100644 --- a/tasks/management-keys.yml +++ b/tasks/management-keys.yml @@ -2,7 +2,7 @@ - name: management | get key file fetch: - src: "~{{ borgbackup_client_user}}/.config/borg/keys/{{ borgbackup_management_key_name }}{{ inventory_hostname }}" + src: ~{{ borgbackup_client_user}}/.config/borg/keys/{{ borgbackup_management_key_name }}{{ inventory_hostname | regex_replace('\.','_')}} dest: /tmp/.borgbackup_key_{{ inventory_hostname }} flat: yes changed_when: false diff --git a/tasks/management.yml b/tasks/management.yml index 74a2e2e..eab10ab 100644 --- a/tasks/management.yml +++ b/tasks/management.yml @@ -1,4 +1,20 @@ --- +- name: management | create scripts dir + file: + path: "~{{ borgbackup_management_user }}/prune.d" + state: "directory" + owner: "{{ borgbackup_management_user }}" + group: "{{ borgbackup_management_user }}" + mode: "0770" + +- name: management | create logs dir + file: + path: "/var/log/borgbackup-prune" + state: "directory" + owner: "{{ borgbackup_management_user }}" + group: "{{ borgbackup_management_user }}" + mode: "0770" + - name: management | put management station prune script template: src: prune.sh.j2 @@ -7,6 +23,19 @@ group: "{{ borgbackup_management_user }}" mode: 0700 +- name: management | put each host prune script + template: + src: prune.host.sh.j2 + dest: "~{{ borgbackup_management_user }}/prune.d/{{item}}" + owner: "{{ borgbackup_management_user }}" + group: "{{ borgbackup_management_user }}" + mode: 0770 + delegate_to: "secure" + when: item != borgbackup_management_station and item not in groups['borgbackup_servers'] + with_items: "{{ play_hosts }}" + + + - name: management | put management sshpubkey on the normal backupserver authorized_key: user: "{{ item.user }}" diff --git a/templates/prune.host.sh.j2 b/templates/prune.host.sh.j2 new file mode 100644 index 0000000..ee7ba0b --- /dev/null +++ b/templates/prune.host.sh.j2 @@ -0,0 +1,12 @@ +#! /bin/bash +echo "Host: {{ item }}" +export BORG_PASSPHRASE={{ hostvars[item].borgbackup_passphrase }} +{% for b in borgbackup_servers %} +{% if b.type == 'hetzner' %} +REPOSITORY=ssh://{{ b.user }}@{{ b.fqdn }}:23/./{{ b.home }}{{ b.pool }}/{{ item }} +{% else %} +REPOSITORY={{ b.user }}@{{ b.fqdn }}:{{ b.home }}{{ b.pool }}/{{ item }} +{% endif %} +/usr/local/bin/borg prune -v $REPOSITORY {{ b.options }} -H {{ borgbackup_retention.hourly }} -d {{ borgbackup_retention.daily }} -w {{ borgbackup_retention.weekly }} -m {{ borgbackup_retention.monthly }} -y {{ borgbackup_retention.yearly }} +dzadza +{% endfor %} diff --git a/templates/prune.sh.j2 b/templates/prune.sh.j2 index 2dcc629..3572168 100644 --- a/templates/prune.sh.j2 +++ b/templates/prune.sh.j2 @@ -16,20 +16,5 @@ LOG_DIR=/var/log/borgbackup LOG_FILE=/var/log/borgbackup-prune/${DATE}.log exec &> >(tee "$LOG_FILE") -{% for h in groups['all'] %} - {% if h != borgbackup_management_station and h not in groups['borgbackup_servers'] -%} -echo "Host: {{ h }}" -export BORG_PASSPHRASE={{ hostvars[h].borgbackup_passphrase }} - {% if borgbackup_management_station is defined and inventory_hostname == borgbackup_management_station %} - {% for b in borgbackup_servers %} - {% if b.type == 'hetzner' %} -REPOSITORY=ssh://{{ b.user }}@{{ b.fqdn }}:23/./{{ b.home }}{{ b.pool }}/{{ h }} - {% else %} -REPOSITORY={{ b.user }}@{{ b.fqdn }}:{{ b.home }}{{ b.pool }}/{{ h }} - {% endif %} -/usr/local/bin/borg prune -v $REPOSITORY {{ b.options }} -H {{ borgbackup_retention.hourly }} -d {{ borgbackup_retention.daily }} -w {{ borgbackup_retention.weekly }} -m {{ borgbackup_retention.monthly }} -y {{ borgbackup_retention.yearly }} +run-parts --lsbsysinit ~{{ borgbackup_management_user }}/prune.d - {% endfor %} - {% endif %} - {% endif %} -{% endfor %}