minor btrfs backup fixes

Signed-off-by: kitzman <kitzman@disroot.org>
This commit is contained in:
kitzman 2022-02-04 22:16:58 +02:00
parent 32e106d56d
commit 0e47445903
1 changed files with 23 additions and 5 deletions

View File

@ -4,7 +4,10 @@ set -e
backup_filename=".snapshot-$(date -I)"
#
# runtime
#
progname=$(basename $0)
if [[ "$progname" != backup\.* ]]; then
@ -14,7 +17,10 @@ fi
jobname=${progname:7}
#
# configuration
#
. /etc/conf.d/backup.$jobname
logger_ident="${logger_ident:-backups}"
@ -29,7 +35,9 @@ if [ -z "$source_storage_path" ]; then
echo "source_storage_path not set!"
fi
#
# utils & sanity checks
#
function log() { echo $@; logger -t $logger_ident $@; }
@ -55,13 +63,15 @@ fi
log "removing old backups from $target_backups_path"
for backup_vol in $(find $target_backups_path -maxdepth 1 -type d \
for backup_vol_path in $(find $target_backups_path -maxdepth 1 -type d \
-name ".snapshot*" | \
sort | head -n $backup_retency); do
sort | head -n "-$backup_retency"); do
backup_vol=$(basename $backup_vol_path)
log "removing $backup_vol"
backup_volid=$(btrfs sub list $target_backups_path | \
grep $backup_vol | awk '{print $1}')
grep $backup_vol | awk '{print $2}')
btrfs sub del $target_backups_path/$backup_vol
qgroup_id="0/$backup_volid"
@ -100,7 +110,7 @@ fi
if [ ! -z "$backup_qgroupid" ]; then
log "assigning qgroup $backup_qgroupid"
backup_volid=$(btrfs sub list $target_backups_path | \
grep $backup_filename | awk '{print $1}')
grep $backup_filename | awk '{print $2}')
btrfs qgroup assign --rescan "0/$backup_volid" "$backup_qgroupid" $target_backups_path
fi
@ -112,7 +122,15 @@ fi
log "removing old backups from $source_storage_path"
if [ ! -z "$parent_backup" ]; then
log "removing $source_storage_path/$parent_backup"
backup_volid=$(btrfs sub list $target_backups_path | \
grep $backup_vol | awk '{print $2}')
btrfs subvolume delete $source_storage_path/$parent_backup
qgroup_id="0/$backup_volid"
btrfs qgroup destroy $qgroup_id || log "could not find qgroup $qgroup_id"
fi
#