adapt transfer_size calculation

- only used when using interactive mode
- consume precise values when using btrfs qgroup functionality
- consume btrfs df values otherwise
- convert 1000 as base values (kB, MB,GB, TB) to be handled via
  via pv (B,M,G,T)
This commit is contained in:
Ralf Zerres
2025-08-03 14:05:24 +02:00
parent 9e7e5b4d28
commit b90e34e596

View File

@@ -168,8 +168,10 @@ check_transfer_size () {
"$source_snapshot" "$source_snapshot"
fi fi
fi fi
# btrfs quotas are expensive and should not be activated if you handle bigger numbers of snapshots
if [ $btrfs_quota -eq 1 ]; then if [ $btrfs_quota -eq 1 ]; then
# qgroup for given path, exclude ancestrals # use qgroup for given path, exclude ancestrals
# qgroup identifiers conform to level/id where level 0 is reserved to the qgroups associated with subvolumes # qgroup identifiers conform to level/id where level 0 is reserved to the qgroups associated with subvolumes
transfer_size=$(btrfs qgroup show -f --raw "$source_snapshot" 2>/dev/null \ transfer_size=$(btrfs qgroup show -f --raw "$source_snapshot" 2>/dev/null \
| awk 'FNR>2 {print $2}') | awk 'FNR>2 {print $2}')
@@ -205,6 +207,8 @@ check_transfer_size () {
# should we disable quota usage again? # should we disable quota usage again?
if [ "$btrfs_quota_tmp" -eq 1 ]; then btrfs quota disable "$source_snapshot"; fi if [ "$btrfs_quota_tmp" -eq 1 ]; then btrfs quota disable "$source_snapshot"; fi
else else
# no quota: get an aproximated value for the transfer_size
# - not accurate, but inexpensive
if [ ${#clone_snapshot} -gt 0 ]; then if [ ${#clone_snapshot} -gt 0 ]; then
# WIP: dry run with btrfs send # WIP: dry run with btrfs send
# need to substitue btrfs 'x.yyGiB' suffix, since pv will need 'xG' # need to substitue btrfs 'x.yyGiB' suffix, since pv will need 'xG'
@@ -212,12 +216,9 @@ check_transfer_size () {
| pv -f 2>&1 >/dev/null \ | pv -f 2>&1 >/dev/null \
| awk -F ' ' '{ gsub(/.[0-9][0-9]MiB/,"M"); gsub(/.[0-9][0-9]GiB/,"G"); print $1 }' ) | awk -F ' ' '{ gsub(/.[0-9][0-9]MiB/,"M"); gsub(/.[0-9][0-9]GiB/,"G"); print $1 }' )
else else
# filesystem size # btrfs calculated filesystem size (--si: use 1000 as a base (kB, MB, GB, TB)
transfer_size=$(du --one-file-system --summarize "$snapper_source_snapshot" 2>/dev/null \ transfer_size=$(btrfs filesystem df --si --gbytes "$snapper_source_snapshot" 2>/dev/null \
| awk -F ' ' '{print $1}') | awk -F '=' 'NR==1 {gsub(/.[0-9][0-9]kB/,"K"); gsub(/.[0-9][0-9]MB/,"M"); gsub(/.[0-9][0-9]GB/,"G"); gsub(/.[0-9][0-9]TB/,"T"); print $3} ')
if [ "$transfer_size" -ge 1048576 ]; then
transfer_size=$(($transfer_size / 1024 / 1024))G
fi
fi fi
if [ "$verbose" -ge 2 ]; then if [ "$verbose" -ge 2 ]; then
printf "${MAGENTA}BTRFS transfer size for ${GREEN}source snapshot${MAGENTA}: size=${GREEN}'%s'${NO_COLOR} ...\n" \ printf "${MAGENTA}BTRFS transfer size for ${GREEN}source snapshot${MAGENTA}: size=${GREEN}'%s'${NO_COLOR} ...\n" \
@@ -231,7 +232,6 @@ check_transfer_size () {
"$snapper_source_id" "$snapper_source_id"
fi fi
fi fi
} }
cleanup_snapper_failed_ids () { cleanup_snapper_failed_ids () {
@@ -1121,8 +1121,8 @@ parse_params () {
backuptype_cmdline="$2" backuptype_cmdline="$2"
shift 2 shift 2
;; ;;
--calculate-btrfs_size) --calculate-btrfs-size)
calulate_size=1 calculate_btrfs_size=1
shift 1 shift 1
;; ;;
-c|--config) -c|--config)
@@ -1896,6 +1896,10 @@ run_backup () {
# prepare send pipe command # prepare send pipe command
create_pv_cmd create_pv_cmd
if [ "$verbose" -ge 3 ]; then
printf "${MAGENTA}Selected Filesystem tye: ${GREEN}'%s'${NO_COLOR}\n" \
"$selected_fstype"
fi
case "$selected_fstype" in case "$selected_fstype" in
btrfs) btrfs)
cmd="btrfs send $btrfs_verbose_flag $snapper_source_snapshot 2>$BTRFS_PIPE \ cmd="btrfs send $btrfs_verbose_flag $snapper_source_snapshot 2>$BTRFS_PIPE \