snap-sync: introduce cleanup() function

- for trapkill: call cleanup function
- remove temp-dirs
This commit is contained in:
2017-11-21 15:27:28 +01:00
parent eac70fc001
commit c6de0dec80

View File

@@ -527,6 +527,22 @@ run_config () {
done 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 () { run_backup () {
# Actual backing up # Actual backing up
#printf "\nPerforming backups...\n" | tee $PIPE #printf "\nPerforming backups...\n" | tee $PIPE
@@ -883,7 +899,9 @@ traperror () {
} }
trapkill () { trapkill () {
die "Exited due to user intervention." printf "Exited due to user intervention.\n"
run_cleanup 1
exit 0
} }
usage () { usage () {
@@ -978,13 +996,14 @@ verify_snapper_structure () {
fi fi
$ssh mkdir --mode=0700 $backup_root/$snapper_config/$snapper_snapshots/$snapper_id $ssh mkdir --mode=0700 $backup_root/$snapper_config/$snapper_snapshots/$snapper_id
else else
if [ "$verbose" ]; then if [ -z "$remote" ]; then
printf "Snapshot %s already in use on target %s.\n" "$snapper_id" "$backup_root/$snapper_config/$snapper_snapshots" 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 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 # cleanup generated snapper entry
check_snapper_failed_ids check_snapper_failed_ids $noconfirm
die "Can't create new snapshot with given snapshot-id!" die "Can't create new snapshot with given snapshot-id!"
return=1 return=1
fi fi
@@ -1055,6 +1074,9 @@ run_finalize
printf "\nDone!\n" | tee $PIPE printf "\nDone!\n" | tee $PIPE
exec 3>&- exec 3>&-
# cleanup
run_cleanup
if [ "$uuid_cmdline" != "none" ]; then if [ "$uuid_cmdline" != "none" ]; then
notify_info "Finished" "Backups to $uuid_cmdline complete!" notify_info "Finished" "Backups to $uuid_cmdline complete!"
else else