dsnap-sync: handle return status when creating new snapshots

- if creation fails, return negative value for snapper_source_id
- terminate following execution with stating the error

Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
2019-08-07 13:02:09 +02:00
parent 1c117bfbf3
commit 3f9bb23a94

View File

@@ -173,16 +173,25 @@ create_snapshot () {
"$selected_config" "$selected_config"
fi fi
if [ -z $remote ]; then if [ -z $remote ]; then
snapper_source_id=$(snapper --config "$selected_config" create \ ret=$(snapper --config "$selected_config" create \
--print-number \ --print-number \
--description "$snap_description_running" \ --description "$snap_description_running" \
--userdata "host=$HOSTNAME") --userdata "host=$HOSTNAME")
else else
snapper_source_id=$(snapper --config "$selected_config" create \ ret=$(snapper --config "$selected_config" create \
--print-number \ --print-number \
--description "$snap_description_running" \ --description "$snap_description_running" \
--userdata "host=$remote") --userdata "host=$remote")
fi fi
if [ "$ret" ]; then
snapper_source_id=$ret
else
# if snapper call fails, return value will do be a snapshot-id
printf "${RED}Creation of snapper source snapshot failed${NO_COLOR}.\n" "$snapper_source_id"
snapper_source_id=-1
return 1
fi
if [ $SUBVOLUME = "/" ]; then if [ $SUBVOLUME = "/" ]; then
SUBVOLUME="" SUBVOLUME=""
fi fi
@@ -1546,6 +1555,9 @@ run_backup () {
case $snapper_backup_type in case $snapper_backup_type in
btrfs-snapshot) btrfs-snapshot)
create_snapshot create_snapshot
if [ $snapper_source_id -lt 0 ]; then
return 1
fi
# to use snapper on the target to supervise the synced snapshots # to use snapper on the target to supervise the synced snapshots
# the backup_location needs to be in a subvol ".snapshots" inside $selected_config (hardcoded in snapper) # the backup_location needs to be in a subvol ".snapshots" inside $selected_config (hardcoded in snapper)
@@ -1572,6 +1584,9 @@ run_backup () {
btrfs-archive) btrfs-archive)
if [ $snapper_source_sync_id -eq 0 ]; then if [ $snapper_source_sync_id -eq 0 ]; then
create_snapshot create_snapshot
if [ $snapper_source_id -lt 0 ]; then
return 1
fi
else else
# check for last common snapshot # check for last common snapshot
snapper_source_id=$snapper_source_sync_id snapper_source_id=$snapper_source_sync_id