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:
@@ -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
|
||||||
@@ -1602,7 +1617,7 @@ run_backup () {
|
|||||||
|
|
||||||
if [ $dryrun -eq 0 ]; then
|
if [ $dryrun -eq 0 ]; then
|
||||||
snapper_source_snapshot_size=0
|
snapper_source_snapshot_size=0
|
||||||
if [ "$interactive" -eq 1 ]; then
|
if [ "$interactive" -eq 1 ]; then
|
||||||
if [ $verbose -ge 2 ]; then
|
if [ $verbose -ge 2 ]; then
|
||||||
printf "${MAGENTA}Get size for given source snapshot (id=${GREEN}'%s'${MAGENTA}, path=${GREEN}'%s'${MAGENTA})${NO_COLOR} ...\n" \
|
printf "${MAGENTA}Get size for given source snapshot (id=${GREEN}'%s'${MAGENTA}, path=${GREEN}'%s'${MAGENTA})${NO_COLOR} ...\n" \
|
||||||
"$snapper_source_id" "$snapper_source_snapshot"
|
"$snapper_source_id" "$snapper_source_snapshot"
|
||||||
|
|||||||
Reference in New Issue
Block a user