[fix] the management station should work

This commit is contained in:
root 2019-09-26 21:08:04 +00:00
parent 23609395dc
commit 5ac24196dc
4 changed files with 43 additions and 17 deletions

View File

@ -2,7 +2,7 @@
- name: management | get key file - name: management | get key file
fetch: 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 }} dest: /tmp/.borgbackup_key_{{ inventory_hostname }}
flat: yes flat: yes
changed_when: false changed_when: false

View File

@ -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 - name: management | put management station prune script
template: template:
src: prune.sh.j2 src: prune.sh.j2
@ -7,6 +23,19 @@
group: "{{ borgbackup_management_user }}" group: "{{ borgbackup_management_user }}"
mode: 0700 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 - name: management | put management sshpubkey on the normal backupserver
authorized_key: authorized_key:
user: "{{ item.user }}" user: "{{ item.user }}"

View File

@ -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 %}

View File

@ -16,20 +16,5 @@ LOG_DIR=/var/log/borgbackup
LOG_FILE=/var/log/borgbackup-prune/${DATE}.log LOG_FILE=/var/log/borgbackup-prune/${DATE}.log
exec &> >(tee "$LOG_FILE") exec &> >(tee "$LOG_FILE")
{% for h in groups['all'] %} run-parts --lsbsysinit ~{{ borgbackup_management_user }}/prune.d
{% 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 }}
{% endfor %}
{% endif %}
{% endif %}
{% endfor %}