Renaming borgmatic backups
I backed up a component using borgmatic, but I forgot to specify the hostname for the borgmatic container in the docker compose config. This freaked me out because backups disappeared all of a sudden.
I was looking for backups with:
1docker compose exec backup borgmatic list
And there was nothing.
The cause of the problem was the default backup naming convention used by borgmatic, which uses the hostname, and which changes on each container restart.
I was able to see all backups with:
1docker compose exec backup borg list $REPOSITORY
To fix this, I specified the missing hostname on the borgmatic container,
and then ran this script to rename pre-existing backups:
1#!/usr/bin/env bash
2
3set -ex
4
5REPOSITORY=$1
6EXPECTED_PREFIX=$2
7
8for line in $(docker compose exec backup borg list --format '{archive}{NL}' $REPOSITORY); do
9 if [[ $line == "$EXPECTED_PREFIX"-* ]]; then
10 continue
11 fi
12 new_line=$(echo $line | sed -e "s/^[a-z0-9]\+/$EXPECTED_PREFIX/g")
13 docker compose exec backup borg rename $REPOSITORY::$line $new_line
14done