ansible-borgbackup/templates/prune.sh.j2

36 lines
1.3 KiB
Plaintext
Raw Normal View History

#jinja2:lstrip_blocks: True
2017-10-01 17:24:50 +00:00
#!/bin/bash
usage(){
cat << EOL
2017-10-01 17:24:50 +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
EOL
}
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")
{% 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
{% endfor %}
{% endif %}
2017-10-01 17:24:50 +00:00
{% endif %}
{% endfor %}