2018-07-03 05:27:50 +00:00
|
|
|
#jinja2:lstrip_blocks: True
|
2017-10-01 17:24:50 +00:00
|
|
|
#!/bin/bash
|
2019-07-11 20:08:09 +00:00
|
|
|
usage(){
|
|
|
|
cat << EOL
|
2017-10-01 17:24:50 +00:00
|
|
|
|
2019-07-11 20:08:09 +00:00
|
|
|
This script is intended to run on a trusted management station to purge borg repo's in
|
|
|
|
append-only mode.
|
|
|
|
Don't put it on the backup server, it contains all borg secrets!
|
2017-10-01 17:24:50 +00:00
|
|
|
|
2019-07-11 20:08:09 +00:00
|
|
|
EOL
|
|
|
|
}
|
2018-07-03 05:27:50 +00:00
|
|
|
|
2019-07-11 20:08:09 +00:00
|
|
|
DATE=$(date +%y%m%d)
|
|
|
|
LOG_DIR=/var/log/borgbackup
|
|
|
|
[ ! -d $LOG_DIR ] && mkdir $LOG_DIR
|
|
|
|
LOG_FILE=/var/log/borgbackup-prune/${DATE}.log
|
|
|
|
exec &> >(tee "$LOG_FILE")
|
2018-07-03 05:27:50 +00:00
|
|
|
|
2019-07-11 20:08:09 +00:00
|
|
|
{% 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 }}
|
2017-10-01 17:24:50 +00:00
|
|
|
|
2019-07-11 20:08:09 +00:00
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
2017-10-01 17:24:50 +00:00
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|