support append_only mode

This commit is contained in:
Luc Stroobant 2017-10-01 19:24:50 +02:00
parent fadd36625d
commit dc72e03bb3
7 changed files with 94 additions and 6 deletions

View file

@ -69,10 +69,11 @@ if [ "$1" = "backup" ]
/usr/local/bin/borg create --compression zlib,6 --stats $REPOSITORY::$date {{ b.options }} {% for dir in borgbackup_include %}{{ dir }} {% endfor %}{% if automysql.stat.isdir is defined and automysql.stat.isdir == True %}/var/lib/automysqlbackup{% endif %}
if [ "$?" -eq "0" ]; then printf "Backup succeeded on $date\n" >> /var/log/borg-backup.log; fi
# Use the `prune` subcommand to maintain 7 daily, 4 weekly
# and 6 monthly archives.
{% if not borgbackup_appendonly %}
# prune old backups
/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 }}
{% endif %}
{% endfor %}
fi

19
templates/prune.sh.j2 Normal file
View file

@ -0,0 +1,19 @@
#!/bin/bash
# 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!
{% for h in groups['all'] %}
{% if hostvars[h].borgbackup_required is defined and hostvars[h].borgbackup_required %}
# Host: {{ h }}
{% for b in hostvars[h].backupservers %}
{% if hostvars[h].borgbackup_managementstation is defined and inventory_hostname == hostvars[h].borgbackup_managementstation %}
export BORG_PASSPHRASE={{ hostvars[h].borgbackup_passphrase }}
REPOSITORY={{ b.user }}@{{ b.fqdn }}:{{ b.home }}{{ b.pool }}/{{ h }}
/usr/local/bin/borg prune -v $REPOSITORY {{ b.options }} -H {{ hostvars[h].borgbackup_retention.hourly }} -d {{ hostvars[h].borgbackup_retention.daily }} -w {{ hostvars[h].borgbackup_retention.weekly }} -m {{ hostvars[h].borgbackup_retention.monthly }} -y {{ hostvars[h].borgbackup_retention.yearly }}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}