QUESTION: Add a hook to check if I am running borgmatic manually in a terminal #729

Closed
opened 2023-07-22 11:42:09 +00:00 by lyndhurst · 3 comments

What I'm trying to do and why

Hi, first of all, thanks for this incredible tool.
I have been spending time over the past week configuring my backups, this is such an elegant way to make use of borg !

Thanks to the very complete and hands on documentation, I managed to do everything I needed, and even more, so I am sorry if I missed something.

I would like to use some before hook to check if borgmatic is being run manually in the terminal or as a 'background process' with cron or systemd. I think it is possible since borgmatic does it to write output to the stdout or syslog, but I have no idea how to go about it..

My first thought was to check if we are in an interactive shell, but all my attempts failed. The best I came up with is the following:

  before_actions:
    - "[[ $- == *i* ]] || exit 75"
    # Since I am usually using zsh, I tried that as well
    - "[[ -o interactive ]] || exit 75"

.

The commands are executed since I get an exit code 75, but they do not work in the sense that I get that soft error code even when running borgmatic manually from the terminal.

I also found a lead checking with test -t 0 but had no luck there either.

Any help would be greatly appreciated.

Thank you in advance.

### What I'm trying to do and why Hi, first of all, thanks for this incredible tool. I have been spending time over the past week configuring my backups, this is such an elegant way to make use of borg ! Thanks to the very complete and hands on documentation, I managed to do everything I needed, and even more, so I am sorry if I missed something. I would like to use some `before` hook to check if borgmatic is being run manually in the terminal or as a 'background process' with cron or systemd. I think it is possible since borgmatic does it to write output to the stdout or syslog, but I have no idea how to go about it.. My first thought was to check if we are in an interactive shell, but all my attempts failed. The best I came up with is the following: ```yaml before_actions: - "[[ $- == *i* ]] || exit 75" # Since I am usually using zsh, I tried that as well - "[[ -o interactive ]] || exit 75" ``` . The commands are executed since I get an exit code 75, but they do not work in the sense that I get that soft error code even when running `borgmatic` manually from the terminal. I also found a lead checking with `test -t 0` but had no luck there either. Any help would be greatly appreciated. Thank you in advance.
lyndhurst changed title from QUESTION: Check if I am running config manually to QUESTION: Add a hook to check if I am running config manually in a terminal 2023-07-22 13:35:04 +00:00
lyndhurst changed title from QUESTION: Add a hook to check if I am running config manually in a terminal to QUESTION: Add a hook to check if I am running borgmatic manually in a terminal 2023-07-22 13:35:30 +00:00
Owner

Interesting use case! Have you tried looking at the value of the $TERM environment variable when borgmatic is run interactively vs. non-interactively? That may be one relatively easy way to differentiate within a hook.

Interesting use case! Have you tried looking at the value of the `$TERM` environment variable when borgmatic is run interactively vs. non-interactively? That may be one relatively easy way to differentiate within a hook.
witten added the
question / support
label 2023-07-23 17:09:37 +00:00
Author

Thank you for the pointer, I did not try that approach. I am not fluent at all with bash, so I think I understood that my way of testing was wrong anyway.

I am going to try out in a different setting and post back if I was successful, or understand better why I am not. So , I will close this issue for now and reopen when I will have more time to spend on that one.

Thanks again.

Thank you for the pointer, I did not try that approach. I am not fluent at all with bash, so I think I understood that my way of testing was wrong anyway. I am going to try out in a different setting and post back if I was successful, or understand better why I am not. So , I will close this issue for now and reopen when I will have more time to spend on that one. Thanks again.
Owner

Sounds good! Let me know if you end up needing more formal support from borgmatic for this.

Sounds good! Let me know if you end up needing more formal support from borgmatic for this.
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#729
No description provided.