Have a hook firing when the process exits because of CTRL+C. #434

Closed
opened 2021-07-22 17:05:12 +00:00 by ams_tschoening · 2 comments

What I'm trying to do and why

I'm in the process of setting up various backups using BorgMatic in a setup where there's one server hosting BorgMatic and fetching contents using SSHFS from remote systems. Additionally I'm testing backing up Postgres file based by issuing pg_start_backup and pg_stop_backup. All of my use cases have in common that there's some state handling necessary: E.g. before a backup some snapshots need to be taken using BTRFS/ZFS, some dirs need to be mounted, pg_start_backup called etc. A corresponding hook after_backup or on_error are available already to clean things up properly.

Though, from my understanding those only fire in case everything works and finishes as expected. But during my setup I need to test a lot of things and am simply aborting backups soon after they have started to test further. Waiting for the backup to finish would simply take too long and is wasted time. The problem seems to be that when I simply kill the process using STRG+C, neither after_backup nor on_error fire, so things are not cleaned up.

I try to take that into account when executing the backup again by e.g. first unmounting probably already mounted dirs, deleting prbably already available snapshots etc. But that makes the before_backup-hook more complex than necessary in theory and requires to start a new backup. Without that a snapshots might be kept around far longer as necessary or Postgres would stay in backup mode.

Having CTRL+C catched and mapped to some hook like on_abort|exit|kill|... or alike would allow me to run the same cleanup like after_backup or on_error in theory.

Thanks for considering!

Environment

borgmatic version: 1.5.15
borgmatic installation method: PIP, system wide
Borg version: 1.1.16
Python version: 3.8.10
operating system and version: Ubuntu 20.04

#### What I'm trying to do and why I'm in the process of setting up various backups using BorgMatic in a setup where there's one server hosting BorgMatic and fetching contents using SSHFS from remote systems. Additionally I'm testing backing up Postgres file based by issuing `pg_start_backup` and `pg_stop_backup`. All of my use cases have in common that there's some state handling necessary: E.g. before a backup some snapshots need to be taken using BTRFS/ZFS, some dirs need to be mounted, `pg_start_backup` called etc. A corresponding hook `after_backup` or `on_error` are available already to clean things up properly. Though, from my understanding those only fire in case everything works and finishes as expected. But during my setup I need to test a lot of things and am simply aborting backups soon after they have started to test further. Waiting for the backup to finish would simply take too long and is wasted time. The problem seems to be that when I simply kill the process using STRG+C, neither `after_backup` nor `on_error` fire, so things are not cleaned up. I try to take that into account when executing the backup again by e.g. first unmounting probably already mounted dirs, deleting prbably already available snapshots etc. But that makes the `before_backup`-hook more complex than necessary in theory and requires to start a new backup. Without that a snapshots might be kept around far longer as necessary or Postgres would stay in backup mode. Having CTRL+C catched and mapped to some hook like `on_abort|exit|kill|...` or alike would allow me to run the same cleanup like `after_backup` or `on_error` in theory. **Thanks for considering!** #### Environment **borgmatic version:** 1.5.15 **borgmatic installation method:** PIP, system wide **Borg version:** 1.1.16 **Python version:** 3.8.10 **operating system and version:** Ubuntu 20.04
Owner

What about simply firing on_error when ctrl-C is pressed? Would that work for you use case? Or do you really need a separate hook with different logic?

What about simply firing `on_error` when ctrl-C is pressed? Would that work for you use case? Or do you really need a separate hook with different logic?
witten added the
good first issue
label 2023-03-27 19:10:14 +00:00
Owner

I'm closing this one for now due to inactivity, but I'd be happy to open it up again if you have further thoughts. Thank you!

I'm closing this one for now due to inactivity, but I'd be happy to open it up again if you have further thoughts. Thank you!
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: borgmatic-collective/borgmatic#434
No description provided.