From c6de0dec80b29e4846b0c79db4a5f3e64bf9d797 Mon Sep 17 00:00:00 2001 From: Ralf Zerres Date: Tue, 21 Nov 2017 15:27:28 +0100 Subject: [PATCH] snap-sync: introduce cleanup() function - for trapkill: call cleanup function - remove temp-dirs --- bin/snap-sync | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/bin/snap-sync b/bin/snap-sync index 1c740e6..0954703 100755 --- a/bin/snap-sync +++ b/bin/snap-sync @@ -527,6 +527,22 @@ run_config () { done } +run_cleanup () { + noconfirm="1" + + # cleanup failed runs + check_snapper_failed_ids "$noconfirm" + + # cleanup target + #$ssh btrfs subvolume delete $backup_root/$snapper_target_config/$snapper_snapshots/$snapper_new_id/snapshot + #$ssh rm -rf $backup_root/$snapper_target_config/$snapper_snapshots/$snapper_new_id + + # cleanup TEMPDIR + if [ -d $TMPDIR_PIPE ]; then + rm -rf $TMPDIR_PIPE || die "Failed to cleanup temporary directory '%s'\n" "$TMPDIR_PIPE" + fi +} + run_backup () { # Actual backing up #printf "\nPerforming backups...\n" | tee $PIPE @@ -883,7 +899,9 @@ traperror () { } trapkill () { - die "Exited due to user intervention." + printf "Exited due to user intervention.\n" + run_cleanup 1 + exit 0 } usage () { @@ -978,13 +996,14 @@ verify_snapper_structure () { fi $ssh mkdir --mode=0700 $backup_root/$snapper_config/$snapper_snapshots/$snapper_id else - if [ "$verbose" ]; then - printf "Snapshot %s already in use on target %s.\n" "$snapper_id" "$backup_root/$snapper_config/$snapper_snapshots" + if [ -z "$remote" ]; then + printf "Cancel Snapshot creation: Former snapshot with id '%s' already exist in '%s'\n" "$snapper_id" "$backup_root/$snapper_config/$snapper_snapshots" + else + printf "Cancel Snapshot creation: Former snapshot with id '%s' already exist on %s in '%s'\n" "$snapper_id" "$remote" "$backup_root/$snapper_config/$snapper_snapshots" fi - printf "Cancel Snapshot creation: Former snapshot with id '%s' already exist in '%s'\n" "\ - $snapper_id" "$backup_root/$snapper_config/$snapper_snapshots" + # cleanup generated snapper entry - check_snapper_failed_ids + check_snapper_failed_ids $noconfirm die "Can't create new snapshot with given snapshot-id!" return=1 fi @@ -1055,6 +1074,9 @@ run_finalize printf "\nDone!\n" | tee $PIPE exec 3>&- +# cleanup +run_cleanup + if [ "$uuid_cmdline" != "none" ]; then notify_info "Finished" "Backups to $uuid_cmdline complete!" else