b9d98cca21
We may see an archive with ".checkpoint" on the end, as described in [1]; the short version is this that borg stamps this every 30 minutes and may appear if a long backup is interrupted. Skip this when making the list of archives to prune. We noticed this on wiki-test; for clarity the list of archives looks like ... wiki-upgrade-test-filesystem-2021-02-16T02:56:09.checkpoint Tue, 2021-02-16 02:56:11 [c444a0765e5791f3f68f08624d1efd80bf8a3ebc96bb225f08e4013befa2b460] wiki-upgrade-test-filesystem-2021-02-16T17:45:04 Tue, 2021-02-16 17:45:06 [b901b55ac3bf9abecba024caebad5ba7cd1a966e3f00b366f6cff45feba7bdff] wiki-upgrade-test-mysql-2021-02-16T18:35:09 Tue, 2021-02-16 18:35:11 [1d38cd3b4b1b3927b543e4ccc6c794cd3a513a70979ff025bbf303e1fe5e490f] wiki-upgrade-test-filesystem-2021-02-17T17:45:05 Wed, 2021-02-17 17:45:07 [f665e275c0014a21b82efaece5d36525a4ce6cb423253d5bd0b1323b230fa53a] ... [1] https://borgbackup.readthedocs.io/en/stable/faq.html#if-a-backup-stops-mid-way-does-the-already-backed-up-data-stay-there Change-Id: Ia33f46305ef8f541efb7c7150d4bb2e977b01d46
47 lines
1.4 KiB
Bash
47 lines
1.4 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=''
|
|
LOG_FILE="/opt/backups/prune-$(date '+%Y-%m-%d-%H-%M-%S').log"
|
|
echo "*** Logging output to ${LOG_FILE}"
|
|
exec 1>${LOG_FILE}
|
|
exec 2>&1
|
|
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
|
|
# Long-running aborted backups might leave a ".checkpoint" archive around; ignore
|
|
# these as prune will remove them automatically
|
|
archives=$(/opt/borg/bin/borg list ${BORG_REPO} | awk '$1 !~ /\.checkpoint$/ { print substr($1, 0, length($1)-20) }' | sort | uniq)
|
|
|
|
for prefix in ${archives};
|
|
do
|
|
echo
|
|
echo
|
|
echo "+------"
|
|
echo "| $(date) 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
|