dsnap-sync: verbosity level update

- v1: Basic messages (main function calls)
- v2: Notice messages (feedback from main functions)
- v3: Informaional messages (feedback from helper functions)

Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
2018-07-27 12:41:10 +02:00
parent 3403ddc235
commit a433ee1a9b

View File

@@ -87,7 +87,6 @@ NO_COLOR=
### ###
check_prerequisites () { check_prerequisites () {
# requested binaries: # requested binaries:
which awk >/dev/null 2>&1 || { printf "'awk' is not installed." && exit 1; } which awk >/dev/null 2>&1 || { printf "'awk' is not installed." && exit 1; }
which sed >/dev/null 2>&1 || { printf "'sed' is not installed." && exit 1; } which sed >/dev/null 2>&1 || { printf "'sed' is not installed." && exit 1; }
@@ -152,14 +151,14 @@ check_snapper_failed_ids () {
} }
create_snapshot () { create_snapshot () {
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "${MAGENTA}create_snapshot()...${NO_COLOR}\n" $snapper_config printf "${MAGENTA}create_snapshot()...${NO_COLOR}\n" $snapper_config
fi fi
# acting on source system # acting on source system
if [ $dryrun -eq 0 ]; then if [ $dryrun -eq 0 ]; then
#printf "Creating new snapshot with snapper config '%s' ...\n" "$selected_config" | tee $PIPE #printf "Creating new snapshot with snapper config '%s' ...\n" "$selected_config" | tee $PIPE
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "${MAGENTA}Create new snapshot using snapper config ${GREEN}'%s'${MAGENTA}...${NO_COLOR}\n" \ printf "${MAGENTA}Create new snapshot using snapper config ${GREEN}'%s'${MAGENTA}...${NO_COLOR}\n" \
"$selected_config" "$selected_config"
fi fi
@@ -180,7 +179,7 @@ create_snapshot () {
snapper_source_snapshot=$SUBVOLUME/.snapshots/$snapper_source_id/snapshot snapper_source_snapshot=$SUBVOLUME/.snapshots/$snapper_source_id/snapshot
snapper_source_info=$SUBVOLUME/.snapshots/$snapper_source_id/info.xml snapper_source_info=$SUBVOLUME/.snapshots/$snapper_source_id/info.xml
sync sync
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "${MAGENTA}Snapper source snapshot ${GREEN}'%s'${MAGENTA} created${NO_COLOR}\n" "$snapper_source_id" printf "${MAGENTA}Snapper source snapshot ${GREEN}'%s'${MAGENTA} created${NO_COLOR}\n" "$snapper_source_id"
fi fi
else else
@@ -231,7 +230,7 @@ get_answer_yes_no () {
get_backupdir () { get_backupdir () {
local backup_dir=$1 local backup_dir=$1
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "${MAGENTA}get_backupdir()...${NO_COLOR}\n" $snapper_config printf "${MAGENTA}get_backupdir()...${NO_COLOR}\n" $snapper_config
fi fi
@@ -248,7 +247,7 @@ get_backupdir () {
fi fi
fi fi
if [ $verbose -ge 1 ] && [ -n "$backupdir" ]; then if [ $verbose -ge 2 ] && [ -n "$backupdir" ]; then
printf "${MAGENTA}Backup-Dir is ${GREEN}'%s'${NO_COLOR}\n" \ printf "${MAGENTA}Backup-Dir is ${GREEN}'%s'${NO_COLOR}\n" \
"$backupdir" "$backupdir"
fi fi
@@ -260,7 +259,7 @@ get_snapper_config_value () {
local config_key=${3##config_key=} local config_key=${3##config_key=}
local run_ssh='' local run_ssh=''
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "${MAGENTA}get_snapper_config_value()...${NO_COLOR}\n" printf "${MAGENTA}get_snapper_config_value()...${NO_COLOR}\n"
fi fi
@@ -269,7 +268,7 @@ get_snapper_config_value () {
value=$(eval $run_ssh cat $config_file \ value=$(eval $run_ssh cat $config_file \
| awk '/'"$config_key"'/' \ | awk '/'"$config_key"'/' \
| awk -F "=" '{ gsub("\"",""); print $2}') | awk -F "=" '{ gsub("\"",""); print $2}')
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "Snapper ${GREEN}config file${NO_COLOR}: '%s'\n" \ printf "Snapper ${GREEN}config file${NO_COLOR}: '%s'\n" \
"$config_file" "$config_file"
printf "Snapper key ${GREEN}'%s'${NO_COLOR}: '%s'\n" \ printf "Snapper key ${GREEN}'%s'${NO_COLOR}: '%s'\n" \
@@ -280,7 +279,7 @@ get_snapper_config_value () {
get_snapper_target_backupdir () { get_snapper_target_backupdir () {
local backupdir_cmdline=$1 local backupdir_cmdline=$1
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "${MAGENTA}get_snapper_target_backupdir()...${NO_COLOR}\n" $snapper_config printf "${MAGENTA}get_snapper_target_backupdir()...${NO_COLOR}\n" $snapper_config
fi fi
@@ -303,7 +302,7 @@ get_snapper_target_backupdir () {
if [ "$backupdir_cmdline" != 'none' ] && [ "$backupdir_cmdline" != "$backupdir" ] \ if [ "$backupdir_cmdline" != 'none' ] && [ "$backupdir_cmdline" != "$backupdir" ] \
&& [ "${#backupdir}" -gt 0 ] ; then && [ "${#backupdir}" -gt 0 ] ; then
if [ $verbose -ge 1 ]; then if [ $verbose -ge 2 ]; then
# WIP: we need to adapt existing target config SUBVOLUME to reflect the new backupdir # WIP: we need to adapt existing target config SUBVOLUME to reflect the new backupdir
printf "${RED}TODO: ${MAGENTA}Reset backupdir ${GREEN}'%s'${MAGENTA} as requested per commandline.${NO_COLOR}\n" \ printf "${RED}TODO: ${MAGENTA}Reset backupdir ${GREEN}'%s'${MAGENTA} as requested per commandline.${NO_COLOR}\n" \
"$backupdir" "$backupdir"
@@ -321,13 +320,13 @@ get_disk_infos () {
local disk_target local disk_target
local fs_option local fs_option
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "${BLUE}Get target_disk_infos()...${NO_COLOR}\n" printf "${BLUE}Get target_disk_infos()...${NO_COLOR}\n"
fi fi
# wakeup automounter units # wakeup automounter units
if [ ${#automount_path} -gt 0 ]; then if [ ${#automount_path} -gt 0 ]; then
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "${MAGENTA}Mount automounter unit ${GREEN}'%s'${MAGENTA}...${NO_COLOR}\n" \ printf "${MAGENTA}Mount automounter unit ${GREEN}'%s'${MAGENTA}...${NO_COLOR}\n" \
"$automount_path" "$automount_path"
fi fi
@@ -425,11 +424,11 @@ get_snapper_config_type () {
# archive: 3nd stage: CHILD_CONFIG="true" PARENT_CONFIG="<child snapper config name>" # archive: 3nd stage: CHILD_CONFIG="true" PARENT_CONFIG="<child snapper config name>"
# parse selected_config and return with $snapper_target_config set appropriately # parse selected_config and return with $snapper_target_config set appropriately
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "${MAGENTA}get_snapper_config_type()...${NO_COLOR}\n" printf "${MAGENTA}get_snapper_config_type()...${NO_COLOR}\n"
fi fi
if [ $verbose -ge 1 ]; then if [ $verbose -ge 2 ]; then
printf "${MAGENTA}Get snapper configuration type for config ${GREEN}'%s'${MAGENTA}...${NO_COLOR}\n" $snapper_config printf "${MAGENTA}Get snapper configuration type for config ${GREEN}'%s'${MAGENTA}...${NO_COLOR}\n" $snapper_config
fi fi
@@ -487,7 +486,7 @@ get_snapper_config_type () {
snapper_target_config=${snapper_target_config}${snapper_config_postfix} snapper_target_config=${snapper_target_config}${snapper_config_postfix}
fi fi
if [ $verbose -ge 1 ]; then if [ $verbose -ge 2 ]; then
printf "Snapper configuration type: '%s'\n" $snapper_config_type printf "Snapper configuration type: '%s'\n" $snapper_config_type
printf "Snapper target configuration: '%s'\n" $snapper_target_config printf "Snapper target configuration: '%s'\n" $snapper_target_config
printf "Snapper parent configuration: '%s'\n" $snapper_parent_config printf "Snapper parent configuration: '%s'\n" $snapper_parent_config
@@ -505,14 +504,14 @@ get_snapper_last_sync_id () {
snapper_sync_id=0 snapper_sync_id=0
[ ${#remote} -gt 0 ] && run_ssh=$ssh [ ${#remote} -gt 0 ] && run_ssh=$ssh
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "${MAGENTA}get_snapper_last_sync_id()...${NO_COLOR}\n" printf "${MAGENTA}get_snapper_last_sync_id()...${NO_COLOR}\n"
fi fi
# only process, if config does exist # only process, if config does exist
cmd="$run_ssh stat --format %i $SNAPPER_CONFIG_DIR/$snapper_config 2>/dev/null" cmd="$run_ssh stat --format %i $SNAPPER_CONFIG_DIR/$snapper_config 2>/dev/null"
if [ -z $(eval $cmd) ]; then if [ -z $(eval $cmd) ]; then
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
if [ $remote ]; then if [ $remote ]; then
printf "${MAGENTA}snapper config ${GREEN}'%s'${MAGENTA} on remote ${GREEN}'%s'${MAGENTA} does not exist yet.${NO_COLOR}\n" \ printf "${MAGENTA}snapper config ${GREEN}'%s'${MAGENTA} on remote ${GREEN}'%s'${MAGENTA} does not exist yet.${NO_COLOR}\n" \
$snapper_config $remote $snapper_config $remote
@@ -524,7 +523,7 @@ get_snapper_last_sync_id () {
return 1 return 1
fi fi
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
if [ $remote ]; then if [ $remote ]; then
printf "${MAGENTA}Get last sync-ID for snapper config ${GREEN}'%s'${MAGENTA} on remote ${GREEN}'%s'${MAGENTA}...${NO_COLOR}\n" \ printf "${MAGENTA}Get last sync-ID for snapper config ${GREEN}'%s'${MAGENTA} on remote ${GREEN}'%s'${MAGENTA}...${NO_COLOR}\n" \
$snapper_config $remote $snapper_config $remote
@@ -575,10 +574,10 @@ get_snapper_sync_id () {
local run_ssh='' local run_ssh=''
local ret= local ret=
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "${MAGENTA}get_snapper_sync_id()...${NO_COLOR}\n" printf "${MAGENTA}get_snapper_sync_id()...${NO_COLOR}\n"
fi fi
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
if [ $remote ]; then if [ $remote ]; then
printf "${MAGENTA}Get sync-ID ${GREEN}'%s'${MAGENTA} for snapper config ${GREEN}'%s'${MAGENTA} on remote ${GREEN}'%s'${MAGENTA}...${NO_COLOR}\n" \ printf "${MAGENTA}Get sync-ID ${GREEN}'%s'${MAGENTA} for snapper config ${GREEN}'%s'${MAGENTA} on remote ${GREEN}'%s'${MAGENTA}...${NO_COLOR}\n" \
$snapper_sync_id $snapper_config $remote $snapper_sync_id $snapper_config $remote
@@ -598,7 +597,7 @@ get_snapper_sync_id () {
if [ ${#ret} -ge 1 ]; then if [ ${#ret} -ge 1 ]; then
# ok, matching snapshot found # ok, matching snapshot found
snapper_sync_id=$ret snapper_sync_id=$ret
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "Got source snapshot: ${GREEN}'%s'${NO_COLOR} (id: ${GREEN}'%s'${NO_COLOR})\n" \ printf "Got source snapshot: ${GREEN}'%s'${NO_COLOR} (id: ${GREEN}'%s'${NO_COLOR})\n" \
$snapper_config $snapper_sync_id $snapper_config $snapper_sync_id
fi fi
@@ -833,6 +832,10 @@ parse_params () {
uuid_cmdline=${1#*=} uuid_cmdline=${1#*=}
shift shift
;; ;;
--v=* | --verbose=*)
verbose=${1#*=}
shift
;;
--) # End of all options --) # End of all options
shift shift
break break
@@ -881,7 +884,7 @@ parse_params () {
NO_COLOR='\033[0m' NO_COLOR='\033[0m'
fi fi
if [ $verbose -ge 1 ]; then if [ $verbose -ge 2 ]; then
printf "${BLUE}$progname (runtime arguments)...${NO_COLOR}\n" printf "${BLUE}$progname (runtime arguments)...${NO_COLOR}\n"
printf "for backup-source:\n" printf "for backup-source:\n"
printf " selected configs: '%s'\n" "$selected_configs" printf " selected configs: '%s'\n" "$selected_configs"
@@ -899,7 +902,7 @@ parse_params () {
printf " backup running: '%s'\n" "$snap_description_running" printf " backup running: '%s'\n" "$snap_description_running"
printf " backup synced: '%s'\n" "$snap_description_synced" printf " backup synced: '%s'\n" "$snap_description_synced"
if [ $verbose -ge 1 ]; then snap_sync_options="verbose_level=$verbose"; fi if [ $verbose -ge 2 ]; then snap_sync_options="verbose_level=$verbose"; fi
if [ $dryrun -eq 1 ]; then snap_sync_options="${snap_sync_options} dry-run=true"; fi if [ $dryrun -eq 1 ]; then snap_sync_options="${snap_sync_options} dry-run=true"; fi
if [ $donotify -eq 1 ]; then snap_sync_options="${snap_sync_options} donotify=true"; fi if [ $donotify -eq 1 ]; then snap_sync_options="${snap_sync_options} donotify=true"; fi
if [ $color -eq 1 ]; then snap_sync_options="${snap_sync_options} color=true"; fi if [ $color -eq 1 ]; then snap_sync_options="${snap_sync_options} color=true"; fi
@@ -932,7 +935,9 @@ quote_args () {
} }
run_config_preparation () { run_config_preparation () {
printf "${BLUE}Prepare configuration structures...${NO_COLOR}\n" if [ $verbose -ge 1 ]; then
printf "${BLUE}Prepare configuration structures...${NO_COLOR}\n"
fi
SNAP_SYNC_EXCLUDE=no SNAP_SYNC_EXCLUDE=no
# loop though selected snapper configurations # loop though selected snapper configurations
@@ -964,22 +969,22 @@ run_config_preparation () {
"snapper_uuid=${selected_uuid}" "snapper_subvolid=${selected_subvol}" "remote=" "snapper_uuid=${selected_uuid}" "snapper_subvolid=${selected_subvol}" "remote="
;; ;;
btrfs-clone) btrfs-clone)
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "{RED}TODO:{NO_COLOR} config_type '%s'?\n" "$snapper_config_type" printf "${RED}TODO:${NO_COLOR} config_type '%s'?\n" "$snapper_config_type"
fi fi
get_snapper_last_sync_id "snapper_config=${selected_config}" "snapper_description=${snap_description_synced}" \ get_snapper_last_sync_id "snapper_config=${selected_config}" "snapper_description=${snap_description_synced}" \
"snapper_uuid=" "snapper_subvolid=" "remote=" "snapper_uuid=" "snapper_subvolid=" "remote="
;; ;;
*) *)
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "{RED}TODO:{NO_COLOR} what is needed for config_type '%s'?\n" "$snapper_config_type" printf "${RED}TODO:${NO_COLOR} what is needed for config_type '%s'?\n" "$snapper_config_type"
fi fi
;; ;;
esac esac
snapper_source_sync_id=$snapper_sync_id snapper_source_sync_id=$snapper_sync_id
if [ $snapper_sync_id -eq 0 ]; then if [ $snapper_sync_id -eq 0 ]; then
if [ $verbose -ge 1 ]; then if [ $verbose -ge 2 ]; then
printf "${MAGENTA}No previous snapshot available for snapper config ${GREEN}'%s'${MAGENTA}...${NO_COLOR}\n" \ printf "${MAGENTA}No previous snapshot available for snapper config ${GREEN}'%s'${MAGENTA}...${NO_COLOR}\n" \
"$selected_config" "$selected_config"
fi fi
@@ -996,7 +1001,7 @@ run_config_preparation () {
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
snapper_source_sync_snapshot=$value/.snapshots/$snapper_source_sync_id/snapshot snapper_source_sync_snapshot=$value/.snapshots/$snapper_source_sync_id/snapshot
fi fi
if [ $verbose -ge 1 ]; then if [ $verbose -ge 2 ]; then
printf "${MAGENTA}Last synced ${GREEN}source snapshot${MAGENTA} for snapper config ${GREEN}'%s'${MAGENTA} is ${GREEN}'%s'${MAGENTA} ...${NO_COLOR}\n" \ printf "${MAGENTA}Last synced ${GREEN}source snapshot${MAGENTA} for snapper config ${GREEN}'%s'${MAGENTA} is ${GREEN}'%s'${MAGENTA} ...${NO_COLOR}\n" \
"$selected_config" "$snapper_sync_id" "$selected_config" "$snapper_sync_id"
fi fi
@@ -1007,7 +1012,7 @@ run_config_preparation () {
"snapper_uuid=" "snapper_subvolid=" "remote=${remote}" "snapper_uuid=" "snapper_subvolid=" "remote=${remote}"
snapper_target_sync_id=$snapper_sync_id snapper_target_sync_id=$snapper_sync_id
if [ $snapper_target_sync_id -eq 0 ]; then if [ $snapper_target_sync_id -eq 0 ]; then
if [ $verbose -ge 1 ]; then if [ $verbose -ge 2 ]; then
if [ $remote ]; then if [ $remote ]; then
printf "${MAGENTA}No target shapshot available for snapper config ${GREEN}'%s'${MAGENTA} on '%s'...${NO_COLOR}\n" \ printf "${MAGENTA}No target shapshot available for snapper config ${GREEN}'%s'${MAGENTA} on '%s'...${NO_COLOR}\n" \
"$selected_config" "$remote" "$selected_config" "$remote"
@@ -1032,7 +1037,7 @@ run_config_preparation () {
backup_root=$value backup_root=$value
fi fi
if [ $verbose -ge 1 ]; then if [ $verbose -ge 2 ]; then
if [ $remote ]; then if [ $remote ]; then
printf "${MAGENTA}Last synced ${GREEN}target snapshot${MAGENTA} for snapper config ${GREEN}'%s'${MAGENTA} on remote '%s' is ${GREEN}'%s'${NO_COLOR}\n" \ printf "${MAGENTA}Last synced ${GREEN}target snapshot${MAGENTA} for snapper config ${GREEN}'%s'${MAGENTA} on remote '%s' is ${GREEN}'%s'${NO_COLOR}\n" \
"$snapper_target_config" "$remote" "$snapper_target_sync_id" "$snapper_target_config" "$remote" "$snapper_target_sync_id"
@@ -1075,7 +1080,9 @@ run_config_preparation () {
} }
run_backup () { run_backup () {
printf "${BLUE}Performing backups...${NO_COLOR}\n" if [ $verbose -ge 1 ]; then
printf "${BLUE}Performing backups...${NO_COLOR}\n"
fi
i=-1 i=-1
for selected_config in $selected_configs; do for selected_config in $selected_configs; do
@@ -1117,16 +1124,17 @@ run_backup () {
create_snapshot create_snapshot
;; ;;
btrfs-clone) btrfs-clone)
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "{RED}TODO:{NO_COLOR} config_type '%s'?\n" "$snapper_config_type" printf "${RED}WIP:${NO_COLOR} config_type '%s'\n" "$snapper_config_type"
fi fi
# check for last common snapshot
snapper_source_id=$snapper_source_sync_id snapper_source_id=$snapper_source_sync_id
snapper_source_snapshot=$SUBVOLUME/.snapshots/$snapper_source_sync_id/snapshot snapper_source_snapshot=$SUBVOLUME/.snapshots/$snapper_source_sync_id/snapshot
snapper_source_info=$SUBVOLUME/.snapshots/$snapper_source_sync_id/info.xml snapper_source_info=$SUBVOLUME/.snapshots/$snapper_source_sync_id/info.xml
;; ;;
*) *)
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "{RED}TODO:{NO_COLOR} what is needed for config_type '%s'?\n" "$snapper_config_type" printf "${RED}WIP:${NO_COLOR} what is needed for config_type '%s'\n" "$snapper_config_type"
fi fi
;; ;;
esac esac
@@ -1165,13 +1173,13 @@ run_backup () {
if [ "$dryrun" -eq 0 ]; then if [ "$dryrun" -eq 0 ]; then
if [ "$snapper_source_sync_id" -eq 0 ] || [ "$snapper_target_sync_id" -eq 0 ]; then if [ "$snapper_source_sync_id" -eq 0 ] || [ "$snapper_target_sync_id" -eq 0 ]; then
# target never received any snapshot before # target never received any snapshot before
if [ $verbose -ge 1 ]; then if [ $verbose -ge 2 ]; then
printf "${MAGENTA}Sending ${GREEN}first snapshot${NO_COLOR} for snapper config ${GREEN}'%s' ${MAGENTA}(id='%s', size='%s')${NO_COLOR} ...\n" \ printf "${MAGENTA}Sending ${GREEN}first snapshot${NO_COLOR} for snapper config ${GREEN}'%s' ${MAGENTA}(id='%s', size='%s')${NO_COLOR} ...\n" \
"$selected_config" "$snapper_source_id" "$snapper_source_snapshot_size" "$selected_config" "$snapper_source_id" "$snapper_source_snapshot_size"
fi fi
# the actual data sync to the target # the actual data sync to the target
# this may take a while, depending on datasize and line-speed # this may take a while, depending on datasize and line-speed
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "cmd: '%s'\n" "$cmd" printf "cmd: '%s'\n" "$cmd"
fi fi
$(eval $cmd) 1>/dev/null $(eval $cmd) 1>/dev/null
@@ -1181,19 +1189,19 @@ run_backup () {
fi fi
else else
# source holds synced snapshots # source holds synced snapshots
if [ $verbose -ge 1 ]; then if [ $verbose -ge 2 ]; then
printf "${MAGENTA}Sending ${GREEN}incremental snapshot${NO_COLOR} (id: ${GREEN}'%s'${NO_COLOR}) for snapper config ${GREEN}'%s'${NO_COLOR} ...\n" \ printf "${MAGENTA}Sending ${GREEN}incremental snapshot${NO_COLOR} (id: ${GREEN}'%s'${NO_COLOR}) for snapper config ${GREEN}'%s'${NO_COLOR} ...\n" \
"$snapper_target_id" "$selected_config" "$snapper_target_id" "$selected_config"
fi fi
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "Last synced ${GREEN}source snapshot${NO_COLOR}: '%s' (id: ${GREEN}'%s'${NO_COLOR})\n" \ printf "Last synced ${GREEN}source${NO_COLOR} snapshot id: ${GREEN}'%s'${NO_COLOR} (path: ${GREEN}'%s'${NO_COLOR})\n" \
"$snapper_source_sync_snapshot" "$snapper_source_sync_id" "$snapper_source_sync_id" "$snapper_source_sync_snapshot"
printf "New source snapshot: ${GREEN}'%s'${NO_COLOR} (id: ${GREEN}'%s'${NO_COLOR})\n" \ printf "New ${GREEN}source${NO_COLOR} snapshot id: ${GREEN}'%s'${NO_COLOR} (path: ${GREEN}'%s'${NO_COLOR})\n" \
"$snapper_source_snapshot" "$snapper_source_id" "$snapper_source_id" "$snapper_source_snapshot"
printf "Last synced target snapshot: ${GREEN}'%s'${NO_COLOR} (id: ${GREEN}'%s'${NO_COLOR})\n" \ printf "Last synced ${GREEN}target${NO_COLOR} snapshot id: ${GREEN}'%s'${NO_COLOR} (path: ${GREEN}'%s'${NO_COLOR})\n" \
"$snapper_target_sync_snapshot" "$snapper_target_sync_id" "$snapper_target_sync_id" "$snapper_target_sync_snapshot"
printf "New target snapshot: ${GREEN}'%s'${NO_COLOR} (id: ${GREEN}'%s'${NO_COLOR})\n" \ printf "New ${GREEN}target${NO_COLOR} snapshot id: ${GREEN}'%s'${NO_COLOR} (path: ${GREEN}'%s'${NO_COLOR})\n" \
"$snapper_target_snapshot/snapshot" "$snapper_target_id" "$snapper_target_id" "$snapper_target_snapshot/snapshot"
fi fi
# verify that source snapshot-id corresponds to a matching target snapshot-id # verify that source snapshot-id corresponds to a matching target snapshot-id
if [ $snapper_target_sync_id -ne $snapper_source_sync_id ]; then if [ $snapper_target_sync_id -ne $snapper_source_sync_id ]; then
@@ -1206,7 +1214,6 @@ run_backup () {
printf "no commen sync id.\n" printf "no commen sync id.\n"
fi fi
fi fi
fi fi
cmd="$ssh stat --format %i $backup_root/$snapper_snapshots/$snapper_source_sync_id 2>/dev/null" cmd="$ssh stat --format %i $backup_root/$snapper_snapshots/$snapper_source_sync_id 2>/dev/null"
@@ -1218,7 +1225,7 @@ run_backup () {
# location where it can get its data. This helps speed up the transfer. # location where it can get its data. This helps speed up the transfer.
cmd="btrfs send $verbose_flag -c $snapper_source_sync_snapshot $snapper_source_snapshot 2>$BTRFS_PIPE \ cmd="btrfs send $verbose_flag -c $snapper_source_sync_snapshot $snapper_source_snapshot 2>$BTRFS_PIPE \
| $cmd_pv $ssh btrfs receive $verbose_flag $snapper_target_snapshot 2>$BTRFS_PIPE" | $cmd_pv $ssh btrfs receive $verbose_flag $snapper_target_snapshot 2>$BTRFS_PIPE"
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "${GREEN}btrfs send${NO_COLOR} is using snapshot ${GREEN}'%s'${NO_COLOR} from ${GREEN}target${NO_COLOR} to sync metadata for new snapshot ${GREEN}'%s'${NO_COLOR} ...\n" \ printf "${GREEN}btrfs send${NO_COLOR} is using snapshot ${GREEN}'%s'${NO_COLOR} from ${GREEN}target${NO_COLOR} to sync metadata for new snapshot ${GREEN}'%s'${NO_COLOR} ...\n" \
"$snapper_source_sync_snapshot" "$snapper_source_snapshot" "$snapper_source_sync_snapshot" "$snapper_source_snapshot"
printf "${GREEN}btrfs command:${NO_COLOR} '%s'\n" "$cmd" printf "${GREEN}btrfs command:${NO_COLOR} '%s'\n" "$cmd"
@@ -1232,7 +1239,7 @@ run_backup () {
# need to use source snapshot to provide metadata for target # need to use source snapshot to provide metadata for target
cmd="btrfs send $verbose_flag -p $snapper_source_sync_snapshot $snapper_source_snapshot 2>$BTRFS_PIPE \ cmd="btrfs send $verbose_flag -p $snapper_source_sync_snapshot $snapper_source_snapshot 2>$BTRFS_PIPE \
| $cmd_pv $ssh btrfs receive $verbose_flag $snapper_target_snapshot 2>BTRFS_PIPE" | $cmd_pv $ssh btrfs receive $verbose_flag $snapper_target_snapshot 2>BTRFS_PIPE"
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "${GREEN}btrfs send${NO_COLOR} is using snapshot ${GREEN}'%s'${NO_COLOR} from ${GREEN}source${NO_COLOR} to sync metadata ...\n" \ printf "${GREEN}btrfs send${NO_COLOR} is using snapshot ${GREEN}'%s'${NO_COLOR} from ${GREEN}source${NO_COLOR} to sync metadata ...\n" \
"$snapper_source_sync_snapshot" "$snapper_source_sync_snapshot"
printf "${GREEN}btrfs command:${NO_COLOR} '%s'\n" "$cmd" printf "${GREEN}btrfs command:${NO_COLOR} '%s'\n" "$cmd"
@@ -1279,7 +1286,9 @@ run_backup () {
run_cleanup () { run_cleanup () {
local batch=${1:-$false} local batch=${1:-$false}
printf "${BLUE}Performing cleanup ...${NO_COLOR}\n" if [ $verbose -ge 1 ]; then
printf "${BLUE}Performing cleanup ...${NO_COLOR}\n"
fi
if [ $dryrun -eq 0 ]; then if [ $dryrun -eq 0 ]; then
# cleanup failed runs # cleanup failed runs
@@ -1300,7 +1309,9 @@ run_cleanup () {
run_finalize () { run_finalize () {
# Actual backing up # Actual backing up
printf "${BLUE}Finalize backups...${NO_COLOR}\n" if [ $verbose -ge 1 ]; then
printf "${BLUE}Finalize backups...${NO_COLOR}\n"
fi
i=-1 i=-1
for selected_config in $selected_configs; do for selected_config in $selected_configs; do
@@ -1350,7 +1361,7 @@ run_finalize () {
src_subvolid=$(eval findmnt --noheadings --output OPTIONS --target $SUBVOLUME | sed -e 's/.*subvolid=\([0-9]*\).*/\1/') src_subvolid=$(eval findmnt --noheadings --output OPTIONS --target $SUBVOLUME | sed -e 's/.*subvolid=\([0-9]*\).*/\1/')
# Tag new snapshots key/value parameter # Tag new snapshots key/value parameter
if [ $verbose -ge 1 ]; then if [ $verbose -ge 2 ]; then
printf "${MAGENTA}Tagging target ...${NO_COLOR}\n" printf "${MAGENTA}Tagging target ...${NO_COLOR}\n"
fi fi
if [ "$dryrun" -eq 0 ]; then if [ "$dryrun" -eq 0 ]; then
@@ -1373,7 +1384,7 @@ run_finalize () {
# -> will restart and sync; any unseen interdependencies? # -> will restart and sync; any unseen interdependencies?
$(eval $ssh killall -SIGTERM snapperd) $(eval $ssh killall -SIGTERM snapperd)
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "${MAGENTA}Identify snapper id ${GREEN}'%s'${MAGENTA} on target for configuration ${GREEN}'%s'${NO_COLOR} ...\n" \ printf "${MAGENTA}Identify snapper id ${GREEN}'%s'${MAGENTA} on target for configuration ${GREEN}'%s'${NO_COLOR} ...\n" \
"$snapper_target_id" "$snapper_target_config" "$snapper_target_id" "$snapper_target_config"
fi fi
@@ -1397,7 +1408,7 @@ run_finalize () {
esac esac
while [ "$ii" -le "$ii_max" ]; do while [ "$ii" -le "$ii_max" ]; do
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "calling: '%s'\n" "$(eval $cmd)" printf "calling: '%s'\n" "$(eval $cmd)"
fi fi
ret=$(eval $cmd) ret=$(eval $cmd)
@@ -1408,12 +1419,12 @@ run_finalize () {
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
if [ $ret -eq $snapper_target_id ]; then if [ $ret -eq $snapper_target_id ]; then
# got snapshot as $snapper_target_id # got snapshot as $snapper_target_id
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "${MAGENTA}Found${NO_COLOR} snapper id ${GREEN}'%s'${NO_COLOR} on target for configuration ${GREEN}'%s'${NO_COLOR}\n" \ printf "${MAGENTA}Found${NO_COLOR} snapper id ${GREEN}'%s'${NO_COLOR} on target for configuration ${GREEN}'%s'${NO_COLOR}\n" \
"$snapper_target_id" "$snapper_target_config" "$snapper_target_id" "$snapper_target_config"
fi fi
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "${MAGENTA}Tagging metadata${NO_COLOR} for snapper id ${GREEN}'%s'${NO_COLOR} on target for configuration ${GREEN}'%s'${NO_COLOR} ...\n" \ printf "${MAGENTA}Tagging metadata${NO_COLOR} for snapper id ${GREEN}'%s'${NO_COLOR} on target for configuration ${GREEN}'%s'${NO_COLOR} ...\n" \
"$snapper_target_id" "$snapper_target_config" "$snapper_target_id" "$snapper_target_config"
#printf "calling: '%s'\n" "$(eval $cmd)" #printf "calling: '%s'\n" "$(eval $cmd)"
@@ -1434,13 +1445,13 @@ run_finalize () {
$snapper_target_id) $snapper_target_id)
fi fi
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "return: '%s'\n" "$ret" printf "return: '%s'\n" "$ret"
fi fi
break break
fi fi
fi fi
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "%s/%s: ${RED}Waiting another '%s' seconds${NO_COLOR} for snappers database update on target ...\n" \ printf "%s/%s: ${RED}Waiting another '%s' seconds${NO_COLOR} for snappers database update on target ...\n" \
"$ii" "$ii_max" "$ii_sleep" "$ii" "$ii_max" "$ii_sleep"
fi fi
@@ -1449,7 +1460,7 @@ run_finalize () {
done done
# source snapshot # source snapshot
if [ $verbose -ge 1 ]; then if [ $verbose -ge 2 ]; then
printf "${MAGENTA}Tagging source ...${NO_COLOR}\n" printf "${MAGENTA}Tagging source ...${NO_COLOR}\n"
fi fi
@@ -1460,13 +1471,13 @@ run_finalize () {
--cleanup-algorithm \"timeline\" \ --cleanup-algorithm \"timeline\" \
$snapper_source_id" $snapper_source_id"
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "${MAGENTA}Tagging snapper metadata${NO_COLOR} for snapper id ${GREEN}'%s'${NO_COLOR} on source for configuration ${GREEN}'%s'${NO_COLOR} ...\n" \ printf "${MAGENTA}Tagging snapper metadata${NO_COLOR} for snapper id ${GREEN}'%s'${NO_COLOR} on source for configuration ${GREEN}'%s'${NO_COLOR} ...\n" \
"$snapper_source_id" "$selected_config" "$snapper_source_id" "$selected_config"
printf "calling: '%s'\n" "$(eval $cmd)" printf "calling: '%s'\n" "$(eval $cmd)"
fi fi
ret=$(eval "$cmd") ret=$(eval "$cmd")
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "return: '%s'\n" "$?" printf "return: '%s'\n" "$?"
fi fi
sync sync
@@ -1476,7 +1487,7 @@ run_finalize () {
--description \"$snap_description_finished\" \ --description \"$snap_description_finished\" \
$snapper_source_sync_id" $snapper_source_sync_id"
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "${MAGENTA}Tagging snapper metadata${NO_COLOR} for snapper sync id ${GREEN}'%s'${NO_COLOR} on source for configuration ${GREEN}'%s'${NO_COLOR} ...\n" \ printf "${MAGENTA}Tagging snapper metadata${NO_COLOR} for snapper sync id ${GREEN}'%s'${NO_COLOR} on source for configuration ${GREEN}'%s'${NO_COLOR} ...\n" \
"$snapper_source_sync_id" "$selected_config" "$snapper_source_sync_id" "$selected_config"
printf "calling: '%s'\n" "$(eval $cmd)" printf "calling: '%s'\n" "$(eval $cmd)"
@@ -1496,8 +1507,9 @@ run_finalize () {
printf "dryrun: %s\n" "$cmd" printf "dryrun: %s\n" "$cmd"
fi fi
printf "Backup complete for snapper configuration '%s'.\n" "$selected_config" > $PIPE if [ $verbose -ge 1 ]; then
printf "Backup complete for snapper configuration '%s'.\n" "$selected_config" > $PIPE
fi
done done
} }
@@ -1510,10 +1522,12 @@ select_target_disk () {
local subvolid='' local subvolid=''
local subvol='' local subvol=''
printf "${BLUE}Select target disk...${NO_COLOR}\n" if [ $verbose -ge 1 ]; then
printf "${BLUE}Select target disk...${NO_COLOR}\n"
fi
# print selection table # print selection table
if [ $verbose -ge 1 ]; then if [ $verbose -ge 2 ]; then
if [ -z "$remote" ]; then if [ -z "$remote" ]; then
printf "Selecting a mounted BTRFS device for backups on your local machine.\n" printf "Selecting a mounted BTRFS device for backups on your local machine.\n"
else else
@@ -1544,7 +1558,7 @@ select_target_disk () {
if [ "$disk_uuid_match_count" -gt 1 ]; then if [ "$disk_uuid_match_count" -gt 1 ]; then
# got UUID selection from commandline # got UUID selection from commandline
disk_count=$disk_uuid_match_count disk_count=$disk_uuid_match_count
if [ $verbose -ge 1 ]; then if [ $verbose -ge 2 ]; then
printf "%s mount points were found with UUID '%s'.\n" "$disk_uuid_match_count" "$uuid_cmdline" printf "%s mount points were found with UUID '%s'.\n" "$disk_uuid_match_count" "$uuid_cmdline"
fi fi
for disk_uuid in $disk_uuid_match; do for disk_uuid in $disk_uuid_match; do
@@ -1597,7 +1611,7 @@ select_target_disk () {
selected_target=$(eval echo \$disk_target_$disk_selected) selected_target=$(eval echo \$disk_target_$disk_selected)
selected_subvol=$(eval echo \$fs_options_$disk_selected | sed -e 's/.*subvolid=\([0-9]*\).*/\1/') selected_subvol=$(eval echo \$fs_options_$disk_selected | sed -e 's/.*subvolid=\([0-9]*\).*/\1/')
if [ $verbose -ge 1 ]; then if [ $verbose -ge 2 ]; then
printf "${MAGENTA}You selected the disk with UUID ${GREEN}'%s'${MAGENTA} (subvolid=${GREEN}'%s'${MAGENTA})${NO_COLOR}.\n" \ printf "${MAGENTA}You selected the disk with UUID ${GREEN}'%s'${MAGENTA} (subvolid=${GREEN}'%s'${MAGENTA})${NO_COLOR}.\n" \
"$selected_uuid" "$selected_subvol" "$selected_uuid" "$selected_subvol"
if [ -z "$remote" ]; then if [ -z "$remote" ]; then
@@ -1693,11 +1707,11 @@ Options:
should specify the remote machine's hostname or ip address. The 'root' user must be should specify the remote machine's hostname or ip address. The 'root' user must be
permitted to login on the remote machine. permitted to login on the remote machine.
--dry-run perform a trial run where no changes are made. --dry-run perform a trial run where no changes are made.
-v, --verbose Be more verbose on what's going on. -v, --verbose Be verbose on what's going on (min: --verbose=1, max: --verbose=3)
--version show program version --version show program version
EOF EOF
exit 1 exit 0
} }
verify_archive_structure () { verify_archive_structure () {
@@ -1706,11 +1720,11 @@ verify_archive_structure () {
local snapper_id=${3##snapper_target_sync_id=} local snapper_id=${3##snapper_target_sync_id=}
local remote_host=${4##remote=} local remote_host=${4##remote=}
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "${MAGENTA}verify-archive_structure()...\n" printf "${MAGENTA}verify-archive_structure()...\n"
fi fi
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "${MAGENTA}Verify archive filesystem structure${NO_COLOR} on target %s...\n" \ printf "${MAGENTA}Verify archive filesystem structure${NO_COLOR} on target %s...\n" \
"$remote" "$remote"
fi fi
@@ -1719,7 +1733,7 @@ verify_archive_structure () {
cmd="$ssh stat --format %i $backup_root 2>/dev/null" cmd="$ssh stat --format %i $backup_root 2>/dev/null"
if [ -z $(eval $cmd) ]; then if [ -z $(eval $cmd) ]; then
if [ "$dryrun" -eq 0 ]; then if [ "$dryrun" -eq 0 ]; then
if [ $verbose -ge 1 ]; then if [ $verbose -ge 2 ]; then
if [ -z $remote_host ]; then if [ -z $remote_host ]; then
printf "Create backup-path %s ...\n" \ printf "Create backup-path %s ...\n" \
"$backup_root" "$backup_root"
@@ -1752,13 +1766,13 @@ verify_archive_structure () {
# verify that target can take the new archive for given snapshot id # verify that target can take the new archive for given snapshot id
if [ "$dryrun" -eq 0 ]; then if [ "$dryrun" -eq 0 ]; then
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "${MAGENTA}Verify existence of path ${GREEN}'%s'${NO_COLOR}\n" \ printf "${MAGENTA}Verify existence of path ${GREEN}'%s'${NO_COLOR}\n" \
"$backup_root/$snapper_config/$snapper_id" "$backup_root/$snapper_config/$snapper_id"
fi fi
cmd="$ssh stat --format %i $backup_root/$snapper_config/$snapper_id 2>/dev/null" cmd="$ssh stat --format %i $backup_root/$snapper_config/$snapper_id 2>/dev/null"
if [ -z "$(eval $cmd)" ]; then if [ -z "$(eval $cmd)" ]; then
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "${MAGENTA}Create path %s${NO_COLOR} to store target snapshot.\n" \ printf "${MAGENTA}Create path %s${NO_COLOR} to store target snapshot.\n" \
"$backup_root/$snapper_config/$snapper_id" "$backup_root/$snapper_config/$snapper_id"
fi fi
@@ -1790,7 +1804,7 @@ verify_archive_structure () {
} }
verify_backupdir () { verify_backupdir () {
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "${MAGENTA}verify_backupdir()...${NO_COLOR}\n" printf "${MAGENTA}verify_backupdir()...${NO_COLOR}\n"
fi fi
@@ -1820,12 +1834,12 @@ verify_backupdir () {
} }
verify_snapper_config () { verify_snapper_config () {
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "${MAGENTA}verify_snapper_config()...${NO_COLOR}\n" printf "${MAGENTA}verify_snapper_config()...${NO_COLOR}\n"
fi fi
if [ ! -f "/etc/snapper/configs/$selected_config" ]; then if [ ! -f "/etc/snapper/configs/$selected_config" ]; then
if [ $verbose -ge 1 ]; then if [ $verbose -ge 2 ]; then
printf "Did you forget to create the snapper configuration for config '%s' on source?\n" \ printf "Did you forget to create the snapper configuration for config '%s' on source?\n" \
"$selected_config" "$selected_config"
printf "You can create it with following command:\n" printf "You can create it with following command:\n"
@@ -1860,11 +1874,11 @@ verify_snapper_structure () {
local snapper_id=${3##snapper_target_id=} local snapper_id=${3##snapper_target_id=}
local remote_host=${4##remote=} local remote_host=${4##remote=}
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "${MAGENTA}verify-snapper_structure()...${NO_COLOR}\n" printf "${MAGENTA}verify-snapper_structure()...${NO_COLOR}\n"
fi fi
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "${MAGENTA}Verify snapper filesystem structure${NO_COLOR} on target ${GREEN}'%s'${NO_COLOR}...\n" \ printf "${MAGENTA}Verify snapper filesystem structure${NO_COLOR} on target ${GREEN}'%s'${NO_COLOR}...\n" \
"$remote" "$remote"
fi fi
@@ -1874,7 +1888,7 @@ verify_snapper_structure () {
ret=$(eval $cmd) ret=$(eval $cmd)
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; then
if [ "$dryrun" -eq 0 ]; then if [ "$dryrun" -eq 0 ]; then
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
if [ -z $remote_host ]; then if [ -z $remote_host ]; then
printf "${MAGENTA}Create${NO_COLOR} new backup-path ${GREEN}'%s'${NO_COLOR}...\n" \ printf "${MAGENTA}Create${NO_COLOR} new backup-path ${GREEN}'%s'${NO_COLOR}...\n" \
"$backup_root" "$backup_root"
@@ -1887,6 +1901,15 @@ verify_snapper_structure () {
base_path=${backup_root%/*}; echo $base_path base_path=${backup_root%/*}; echo $base_path
if [ $dryrun -eq 0 ]; then if [ $dryrun -eq 0 ]; then
$(eval $ssh mkdir --mode=0700 --parents $base_path) $(eval $ssh mkdir --mode=0700 --parents $base_path)
if [ $verbose -ge 3 ]; then
if [ -z $remote_host ]; then
printf "${MAGENTA}Create${NO_COLOR} new backup-path ${GREEN}'%s'${NO_COLOR}...\n" \
"$backup_root"
else
printf "${MAGENTA}Create${NO_COLOR} new backup-path ${GREEN}'%s'${NO_COLOR} on ${MAGENTA}remote host ${GREEN}'%s'${NO_COLOR=} ...\n" \
"$backup_root" "$remote_host"
fi
fi
else else
if [ -z $remote_host ]; then if [ -z $remote_host ]; then
printf "dryrun: Would create backup-path %s ...\n" \ printf "dryrun: Would create backup-path %s ...\n" \
@@ -1903,9 +1926,9 @@ verify_snapper_structure () {
cmd="$ssh stat --format %i $backup_root 2>/dev/null" cmd="$ssh stat --format %i $backup_root 2>/dev/null"
ret=$(eval $cmd) ret=$(eval $cmd)
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; then
# path does not exist # no inode for given backup_root
if [ $dryrun -eq 0 ]; then if [ $dryrun -eq 0 ]; then
if [ $verbose -ge 1 ]; then if [ $verbose -ge 2 ]; then
if [ -z "$remote" ]; then if [ -z "$remote" ]; then
printf "${MAGENTA}Create${NO_COLOR} new snapper capable BTRFS ${MAGENTA}subvolume ${GREEN}'%s'${NO_COLOR} ...\n" \ printf "${MAGENTA}Create${NO_COLOR} new snapper capable BTRFS ${MAGENTA}subvolume ${GREEN}'%s'${NO_COLOR} ...\n" \
"$backup_root" "$backup_root"
@@ -1926,19 +1949,20 @@ verify_snapper_structure () {
fi fi
# create the non existing remote BTRFS subvolume for given config # create the non existing remote BTRFS subvolume for given config
cmd="$ssh btrfs subvolume create $backup_root 1>/dev/null" cmd="$ssh btrfs subvolume create $backup_root 1>/dev/null"
$(eval $cmd) || die "Creation of BTRFS subvolume %s:%s failed.\n" \ $(eval $cmd) || die "Creation of BTRFS subvolume (backup-root) %s:%s failed.\n" \
"$remote_host" "$backup_root" "$remote_host" "$backup_root"
cmd="$ssh chmod 0700 $backup_root" cmd="$ssh chmod 0700 $backup_root"
$(eval $cmd) || die "Changing the directory mode for %s on %s failed.\n" \ $(eval $cmd) || die "Changing the directory mode for %s on %s failed.\n" \
"$backup_root" "$remote_host" "$backup_root" "$remote_host"
# create the non existing remote BTRFS subvolume for given snapshot # create the non existing remote BTRFS subvolume for given snapshot
cmd="$ssh btrfs subvolume create $backup_root/$snapper_snapshot 1>/dev/null" #cmd="$ssh btrfs subvolume create $backup_root/$snapper_snapshot 1>/dev/null"
$(eval $cmd) || \ #$(eval $cmd) || \
die "Creation of BTRFS subvolume $remote_host: $backup_root failed." # die "Creation of BTRFS subvolume (snapshot): %s:%s failed.\n" \
cmd="$ssh chmod 0700 $backup_root 1>/dev/null" # "$remote_host" "$backup_root" "$remote_host"
$(eval $cmd) || \ # cmd="$ssh chmod 0700 $backup_root 1>/dev/null"
die "Changing the directory mode for '$backup_root' on '$remote_host'." # $(eval $cmd) || \
# die "Changing the directory mode for '$backup_root' on '$remote_host'."
else else
printf "dryrun: Would create new snapper configuration from template %s ...\n" "$snapper_subvolume_template" printf "dryrun: Would create new snapper configuration from template %s ...\n" "$snapper_subvolume_template"
printf "dryrun: Would create new snapper subvolume '%s' ...\n" "$backup_root/$snapper_snapshot" printf "dryrun: Would create new snapper subvolume '%s' ...\n" "$backup_root/$snapper_snapshot"
@@ -1948,7 +1972,7 @@ verify_snapper_structure () {
die "%s needs to be a BTRFS subvolume. But given %s is just a directory.\n" \ die "%s needs to be a BTRFS subvolume. But given %s is just a directory.\n" \
"$snapper_config" "$backup_root" "$snapper_config" "$backup_root"
fi fi
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "${RED}TODO:${NO_COLOR} check and adapt SUBVOLUME in given config '%s', since mount path might have changed meanwhile\n" "$snapper_config" printf "${RED}TODO:${NO_COLOR} check and adapt SUBVOLUME in given config '%s', since mount path might have changed meanwhile\n" "$snapper_config"
fi fi
#$ssh $(. $SNAPPER_CONFIG_DIR/$snapper_config) #$ssh $(. $SNAPPER_CONFIG_DIR/$snapper_config)
@@ -1969,7 +1993,7 @@ verify_snapper_structure () {
cmd="$ssh snapper --config $snapper_config create-config \ cmd="$ssh snapper --config $snapper_config create-config \
--template $snapper_subvolume_template \ --template $snapper_subvolume_template \
--fstype btrfs $backup_root" --fstype btrfs $backup_root"
if [ $verbose -ge 1 ]; then if [ $verbose -ge 2 ]; then
printf "${MAGENTA}Create new BTRFS subvolume ${GREEN}'%s'${NO_COLOR} using template ${GREEN}'%s'${NO_COLOR}\n" \ printf "${MAGENTA}Create new BTRFS subvolume ${GREEN}'%s'${NO_COLOR} using template ${GREEN}'%s'${NO_COLOR}\n" \
$snapper_config $snapper_subvolume_template $snapper_config $snapper_subvolume_template
fi fi
@@ -1990,7 +2014,7 @@ verify_snapper_structure () {
#cmd="$ssh snapper list-configs | awk '/'\"^$snapper_config\"'/' | awk -F '|' ' /'\$1 == "$snapper_config"'/ {print \$1}'" #cmd="$ssh snapper list-configs | awk '/'\"^$snapper_config\"'/' | awk -F '|' ' /'\$1 == "$snapper_config"'/ {print \$1}'"
if [ -n $(eval $cmd) ]; then if [ -n $(eval $cmd) ]; then
# if changed, adapt targets SUBVOLUME path # if changed, adapt targets SUBVOLUME path
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "${RED}TODO:${NO_COLOR} Check if value for key 'SUBVOLUME' needs an update in snapper config %s\n" \ printf "${RED}TODO:${NO_COLOR} Check if value for key 'SUBVOLUME' needs an update in snapper config %s\n" \
"$snapper_config" "$snapper_config"
fi fi
@@ -2007,7 +2031,7 @@ verify_snapper_structure () {
cmd="$ssh stat --format %i $backup_root/$snapper_snapshots 2>/dev/null" cmd="$ssh stat --format %i $backup_root/$snapper_snapshots 2>/dev/null"
ret=$(eval $cmd) ret=$(eval $cmd)
if [ -z $ret ]; then if [ -z $ret ]; then
if [ $verbose -ge 1 ]; then if [ $verbose -ge 2 ]; then
printf "${MAGENTA}Create new BTRFS subvolume ${GREEN}'%s'${NO_COLOR}\n" \ printf "${MAGENTA}Create new BTRFS subvolume ${GREEN}'%s'${NO_COLOR}\n" \
$backup_root/$snapper_snapshots $backup_root/$snapper_snapshots
fi fi
@@ -2031,7 +2055,7 @@ verify_snapper_structure () {
# verify that target snapshot can take the new snapshot data id # verify that target snapshot can take the new snapshot data id
if [ $dryrun -eq 0 ]; then if [ $dryrun -eq 0 ]; then
if [ $verbose -ge 1 ]; then if [ $verbose -ge 2 ]; then
printf "${MAGENTA}Verify existence of path ${GREEN}'%s'${NO_COLOR}...\n" \ printf "${MAGENTA}Verify existence of path ${GREEN}'%s'${NO_COLOR}...\n" \
"$backup_root/$snapper_snapshots/$snapper_id" "$backup_root/$snapper_snapshots/$snapper_id"
fi fi
@@ -2039,7 +2063,7 @@ verify_snapper_structure () {
ret=$(eval $cmd) ret=$(eval $cmd)
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; then
# Path does not exist # Path does not exist
if [ $verbose -ge 2 ]; then if [ $verbose -ge 3 ]; then
printf "${MAGENTA}Create${NO_COLOR} path ${GREEN}'%s'${NO_COLOR} to store target snapshot.\n" \ printf "${MAGENTA}Create${NO_COLOR} path ${GREEN}'%s'${NO_COLOR} to store target snapshot.\n" \
"$backup_root/$snapper_snapshots/$snapper_id" "$backup_root/$snapper_snapshots/$snapper_id"
fi fi
@@ -2066,7 +2090,7 @@ verify_snapper_structure () {
# cleanup generated snapper entry # cleanup generated snapper entry
check_snapper_failed_ids $batch check_snapper_failed_ids $batch
die "Can't create new snapshot with given snapshot-id!" die "Can't backup to existing snapshot-id ($snapper_id)!"
fi fi
fi fi
else else
@@ -2109,7 +2133,7 @@ run_finalize
# cleanup # cleanup
run_cleanup run_cleanup
printf "${BLUE}Done!${NO_COLOR}\n" printf "${BLUE}Backups done!${NO_COLOR}\n"
exec 3>&- exec 3>&-
if [ $donotify -gt 0 ]; then if [ $donotify -gt 0 ]; then