Merge "borg-backup-server: add script for pruning borg backups"
This commit is contained in:
commit
1d79574d82
@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
echo "This script will prune each archive in the backups of all backed up hosts"
|
||||
echo "Enter 'noop' to test, or 'prune' to actually prune"
|
||||
read -p "Operation: " borg_op
|
||||
|
||||
if [[ ${borg_op} == 'noop' ]]; then
|
||||
BORG_OP='--dry-run'
|
||||
elif [[ ${borg_op} == 'prune' ]]; then
|
||||
BORG_OP=''
|
||||
else
|
||||
echo "*** Invalid input"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
pushd /opt/backups
|
||||
|
||||
for u in borg-*; do
|
||||
BORG_REPO=/opt/backups/$u/backup
|
||||
|
||||
sudo BORG_OP=${BORG_OP} BORG_RELOCATED_REPO_ACCESS_IS_OK=y BORG_REPO=${BORG_REPO} -u ${u} -s <<'EOF'
|
||||
|
||||
# Look at all archives and strip the timestamp, leaving just the archive names
|
||||
# We limit the prune by --prefix so each archive is considered separately
|
||||
archives=$(/opt/borg/bin/borg list ${BORG_REPO} | awk '{$1 = substr($1, 0, length($1)-20); print $1}' | sort | uniq)
|
||||
|
||||
for prefix in ${archives};
|
||||
do
|
||||
echo
|
||||
echo
|
||||
echo "+------"
|
||||
echo "| Pruning ${BORG_REPO} archive ${prefix}"
|
||||
echo "+------"
|
||||
/opt/borg/bin/borg prune --prefix ${prefix} ${BORG_OP} --verbose --list --show-rc --keep-daily 7 --keep-weekly 4 --keep-monthly 12
|
||||
done
|
||||
|
||||
EOF
|
||||
done
|
@ -7,6 +7,14 @@
|
||||
include_role:
|
||||
name: install-borg
|
||||
|
||||
- name: Install prune script
|
||||
copy:
|
||||
src: 'prune-borg-backups.sh'
|
||||
dest: '/usr/local/bin/prune-borg-backups'
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0755'
|
||||
|
||||
- name: Build all borg users from backup hosts
|
||||
set_fact:
|
||||
borg_users: '{{ borg_users }} + [ {{ hostvars[item]["borg_user"] }} ]'
|
||||
|
@ -88,3 +88,11 @@ def test_borg_backup(host):
|
||||
# unmount it for sanity
|
||||
cmd = host.run('umount /opt/backups')
|
||||
assert cmd.succeeded
|
||||
|
||||
def test_borg_server_prune(host):
|
||||
hostname = host.backend.get_hostname()
|
||||
if hostname.startswith('borg-backup-test'):
|
||||
pytest.skip()
|
||||
|
||||
cmd = host.run('echo "prune" | /usr/local/bin/prune-borg-backups 2>&1 > /var/log/prune-borg-backups.log')
|
||||
assert cmd.succeeded
|
||||
|
@ -357,6 +357,9 @@
|
||||
- playbooks/zuul/templates/host_vars/borg-backup
|
||||
- testinfra/test_borg_backups.py
|
||||
host-vars:
|
||||
borg-backup01.region.provider.opendev.org:
|
||||
host_copy_output:
|
||||
'/var/log/prune-borg-backups.log': logs
|
||||
borg-backup-test01.opendev.org:
|
||||
host_copy_output:
|
||||
'/var/log/borg-backup-borg-backup01.region.provider.opendev.org.log': logs
|
||||
|
Loading…
x
Reference in New Issue
Block a user