4 Commits

Author SHA1 Message Date
Ralf Zerres
85d9216fc1 upgrade to v0.6.10
* update README
2025-08-05 12:00:24 +02:00
Ralf Zerres
6982aafaff shellcheck corrections 2025-08-05 01:14:31 +02:00
Ralf Zerres
e8d5576e02 print out return value of btrfs send-revieve pipe 2025-08-05 01:14:31 +02:00
Ralf Zerres
b90e34e596 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)
2025-08-05 01:14:13 +02:00
2 changed files with 35 additions and 27 deletions

View File

@@ -1,5 +1,5 @@
<!-- dsnap-sync README.md -->
<!-- version: 0.6.9 -->
<!-- version: 0.6.10 -->
# dsnap-sync
@@ -389,4 +389,4 @@ This work is licensed under a [Creative Common License 4.0][License-CC_BY]
![Creative Common Logo][Logo-CC_BY]
© 2016, 2017 James W. Barnett;
© 2017 - 2023 Ralf Zerres
© 2017 - 2025 Ralf Zerres

View File

@@ -39,7 +39,7 @@
# pair of systemd service and timer-units.
progname="${0##*/}"
version="0.6.9"
version="0.6.10"
# global variables
args=
@@ -49,7 +49,7 @@ batch=0
btrfs_quota=0
btrfs_quota_tmp=1
btrfs_verbose_flag=
calculate_btrfs_size=0
calculate_btrfs_size=1
color=0
donotify=0
dryrun=0
@@ -168,8 +168,10 @@ check_transfer_size () {
"$source_snapshot"
fi
fi
# btrfs quotas are expensive and should not be activated if you handle bigger numbers of snapshots
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
transfer_size=$(btrfs qgroup show -f --raw "$source_snapshot" 2>/dev/null \
| awk 'FNR>2 {print $2}')
@@ -188,7 +190,7 @@ check_transfer_size () {
fi
if [ "$verbose" -ge 3 ]; then
printf "${MAGENTA}BTRFS qgroup show result: ${GREEN}'%s'\b${NO_COLOR}'%s'\n" \
printf "${MAGENTA}BTRFS Quoata-Group for snapshot show result: ${GREEN}'%s'\b${NO_COLOR}'%s'\n" \
"$?" "$transfer_size"
fi
@@ -205,6 +207,8 @@ check_transfer_size () {
# should we disable quota usage again?
if [ "$btrfs_quota_tmp" -eq 1 ]; then btrfs quota disable "$source_snapshot"; fi
else
# no quota: get an aproximated value for the transfer_size
# - not accurate, but inexpensive
if [ ${#clone_snapshot} -gt 0 ]; then
# WIP: dry run with btrfs send
# 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 \
| awk -F ' ' '{ gsub(/.[0-9][0-9]MiB/,"M"); gsub(/.[0-9][0-9]GiB/,"G"); print $1 }' )
else
# filesystem size
transfer_size=$(du --one-file-system --summarize "$snapper_source_snapshot" 2>/dev/null \
| awk -F ' ' '{print $1}')
if [ "$transfer_size" -ge 1048576 ]; then
transfer_size=$(($transfer_size / 1024 / 1024))G
fi
# btrfs calculated filesystem size (--si: use 1000 as a base (kB, MB, GB, TB)
transfer_size=$(btrfs filesystem df --si --gbytes "$snapper_source_snapshot" 2>/dev/null \
| 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} ')
fi
if [ "$verbose" -ge 2 ]; then
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"
fi
fi
}
cleanup_snapper_failed_ids () {
@@ -267,9 +267,9 @@ cleanup_snapper_failed_ids () {
| awk ' END {print $1} ')
cmd="snapper --config $selected_config delete"
if [ "$failed_id_first" -lt "$failed_id_last" ]; then
$(eval "$cmd" "$failed_id_first"-"$failed_id_last")
eval "$cmd" "$failed_id_first"-"$failed_id_last"
else
$(eval "$cmd" "$failed_id_first")
eval "$cmd" "$failed_id_first"
fi
fi
fi
@@ -594,7 +594,7 @@ get_disk_infos () {
disk_subvolid_match="$i"
disk_subvolid_match_count=$((disk_subvolid_match_count+1))
fi
$(eval "fs_options_$i='$fs_option'")
eval "fs_options_$i='$fs_option'"
i=$((i+1))
done
}
@@ -789,7 +789,7 @@ get_snapper_last_sync_id () {
cmd="stat --format %n $snapper_config_dir/$snapper_config 2>/dev/null"
#printf "${MAGENTA}Check for given snapper config ${GREEN}'%s'${MAGENTA} (remote host: ${GREEN}'%s'${MAGENTA}).${NO_COLOR}\n" \
# "$cmd" "$remote_host"
if [ ! $(eval "$run_ssh" "$cmd") ]; then
if [ ! "$(eval "$run_ssh" "$cmd")" ]; then
if [ "$verbose" -ge 3 ]; then
if [ "${#remote_host}" -ge 1 ]; then
printf "${MAGENTA}snapper config ${GREEN}'%s'${MAGENTA} on remote ${GREEN}'%s'${MAGENTA} does not exist yet.${NO_COLOR}\n" \
@@ -1121,8 +1121,8 @@ parse_params () {
backuptype_cmdline="$2"
shift 2
;;
--calculate-btrfs_size)
calulate_size=1
--calculate-btrfs-size)
calculate_btrfs_size=1
shift 1
;;
-c|--config)
@@ -1269,7 +1269,7 @@ parse_params () {
snapper_config_postfix="${1#*=}"
shift
;;
--calculate-btrfs_size=*)
--calculate-btrfs-size=*)
case ${1#*=} in
yes | Yes | True | true)
calculate_btrfs_size=1;
@@ -1896,6 +1896,10 @@ run_backup () {
# prepare send pipe command
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
btrfs)
cmd="btrfs send $btrfs_verbose_flag $snapper_source_snapshot 2>$BTRFS_PIPE \
@@ -1936,13 +1940,17 @@ run_backup () {
"$selected_config"
fi
fi
# the actual data sync to the target
# this may take a while, depending on datasize and line-speed
if [ "$verbose" -ge 3 ]; then
printf "cmd: '%s'\n" "$cmd"
fi
$(eval "$cmd")
if [ "$?" -gt 0 ]; then
ret=$(eval "$cmd")
if [ "$verbose" -ge 3 ]; then
printf "cmd returned: '%s' \n" "$ret"
fi
if [ "$ret" -gt 0 ]; then
printf "${RED}BTRFS_PIPE: %s${NO_COLOR}\n" "$(cat <"$BTRFS_PIPE")"
error_count=$((error_count+1))
# go for next configuration
@@ -2064,7 +2072,7 @@ run_backup () {
# printf "${GREEN}btrfs command:${NO_COLOR} '%s'\n" "$cmd"
# fi
$(eval "$cmd")
eval "$cmd"
ret=$?
case "$ret" in
0)
@@ -2125,7 +2133,7 @@ run_backup () {
printf "${MAGENTA}cmd: ${GREEN}'%s'${NO_COLOR}\n" \
"$cmd"
fi
$(eval "$cmd") 1>/dev/null
eval "$cmd" 1>/dev/null
fi
else
printf "${MAGENTA}dryrun${NO_COLOR}: Would copy info metadata '%s' to target.\n" \
@@ -2252,7 +2260,7 @@ run_finalize () {
printf "${MAGENTA}Kill running ${GREEN}snapperd${MAGENTA} on target id: ${GREEN}'%s'${NO_COLOR} ...\n" \
"$snapperd_pid"
fi
$(eval "$ssh" killall -SIGTERM snapperd 2>/dev/null)
eval "$ssh" killall -SIGTERM snapperd 2>/dev/null
if [ "$verbose" -ge 3 ]; then
printf "${MAGENTA}Identify snapper id ${GREEN}'%s'${MAGENTA} on target for configuration ${GREEN}'%s'${NO_COLOR} ...\n" \
@@ -2277,7 +2285,7 @@ run_finalize () {
fi
ret=$(eval "$cmd")
if [ "$verbose" -ge 3 ]; then
printf "return: '%s'\n" "$?"
printf "return: '%s'\n" "$ret"
fi
sync
@@ -2895,7 +2903,7 @@ Options:
--label-running <desc> snapper description tagging active jobs. Default: "dsnap-sync in progress"
--label-synced <desc> snapper description tagging last synced jobs
Default: "dsnap-sync last incremental"
--calculate-btrfs_size Enable calculation of sync-size for given btrfs snapshots
--calculate-btrfs-size Enable calculation of sync-size for given btrfs snapshots
--color Enable colored output messages
-c, --config <config> Specify <multiple> snapper configurations.
Default: Perform snapshots for each available snapper configuration.