4f0bfa6d9d
This adds a script that performs a manual pruning of backup directories. Change-Id: I9559bb8aeeef06b95fb9e172a2c5bfb5be5b480e
41 lines
1.1 KiB
Bash
41 lines
1.1 KiB
Bash
#!/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
|