Unable to execute Borgmatic when using pipx installation method #757

Closed
opened 2023-09-17 21:56:41 +00:00 by tylerlucas · 8 comments

What I'm trying to do and why

Issue

When installing using pipx, I'm unable to execute Borgmatic unless providing the full directory path

I'm following the instructions on this page.

Ubuntu 22.04LTS

Steps to reproduce

Troubleshooting/Repro

Prior to installing, I update my path with sudo pipx ensurepath:
/root/.local/bin has been been added to PATH, but you need to open a new terminal or re-login for this PATH change to take effect.

I have verified that my PATH does contain /root/.local/bin:
tyler@tl-pub-media:~$ echo $PATH /home/tyler/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/root/.local/bin

While installing, I receive this output:

tyler@tl-pub-media:~$ sudo pipx install borgmatic
[sudo] password for tyler:
  installed package borgmatic 1.8.2, installed using Python 3.10.12
  These apps are now globally available
    - borgmatic
    - generate-borgmatic-config
    - validate-borgmatic-config
⚠️  Note: '/root/.local/bin' is not on your PATH environment variable. These apps will not be globally accessible until your PATH is updated. Run 'pipx
    ensurepath' to automatically add it, or manually modify your PATH in your shell's config file (i.e. ~/.bashrc).
done! ✨ 🌟 ✨

I can execute when providing the full path:

tyler@tl-pub-media:~$ sudo /root/.local/bin/borgmatic --version
1.8.2

I cannot execute when calling 'borgmatic':

tyler@tl-pub-media:~$ sudo borgmatic --version
sudo: borgmatic: command not found

### Actual behavior

_No response_

### Expected behavior

_No response_

### Other notes / implementation ideas

_No response_

### borgmatic version

1.8.2

### borgmatic installation method

pipx

### Borg version

1.2.0

### Python version

Python 3.10.12

### Database version (if applicable)

_No response_

### Operating system and version

Ubuntu 22.04.3

### What I'm trying to do and why # Issue When installing using pipx, I'm unable to execute Borgmatic unless providing the full directory path I'm following the instructions on [this page](https://torsion.org/borgmatic/docs/how-to/set-up-backups/). Ubuntu 22.04LTS ### Steps to reproduce # Troubleshooting/Repro Prior to installing, I update my path with `sudo pipx ensurepath`: `/root/.local/bin has been been added to PATH, but you need to open a new terminal or re-login for this PATH change to take effect.` I have verified that my PATH does contain `/root/.local/bin`: `tyler@tl-pub-media:~$ echo $PATH /home/tyler/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/root/.local/bin` While installing, I receive this output: ``` tyler@tl-pub-media:~$ sudo pipx install borgmatic [sudo] password for tyler: installed package borgmatic 1.8.2, installed using Python 3.10.12 These apps are now globally available - borgmatic - generate-borgmatic-config - validate-borgmatic-config ⚠️ Note: '/root/.local/bin' is not on your PATH environment variable. These apps will not be globally accessible until your PATH is updated. Run 'pipx ensurepath' to automatically add it, or manually modify your PATH in your shell's config file (i.e. ~/.bashrc). done! ✨ 🌟 ✨ ``` I can execute when providing the full path: ``` tyler@tl-pub-media:~$ sudo /root/.local/bin/borgmatic --version 1.8.2 ``` I cannot execute when calling 'borgmatic': ``` tyler@tl-pub-media:~$ sudo borgmatic --version sudo: borgmatic: command not found ### Actual behavior _No response_ ### Expected behavior _No response_ ### Other notes / implementation ideas _No response_ ### borgmatic version 1.8.2 ### borgmatic installation method pipx ### Borg version 1.2.0 ### Python version Python 3.10.12 ### Database version (if applicable) _No response_ ### Operating system and version Ubuntu 22.04.3
tylerlucas changed title from Unable to execute Borgmatic when using pipx installation method to Unable to execute Borgmatic when using pipx installation method 2023-09-17 21:57:59 +00:00
Owner

Thanks for filing this! I think you're running into this problem because pipx ensurepath only applies to the shell for the Unix user account in which that command is run. In other words, when you run sudo pipx ensurepath, that modifies the PATH environment variable for the root user—but not for your non-root user. So I see a couple of options here:

  • You can su or sudo to a root shell before running borgmatic as the root user. That should work because it'll use root's PATH.
  • Or: Manually add /root/.local/bin to your non-root user's PATH (in ~/.bashrc or similar) so sudo borgmatic works as expected.
  • Or: Install borgmatic (and run pipx ensurepath) as a non-root user instead of (or in addition to) a root user. This would only work though if you want to run borgmatic as a non-root user and therefore only have access to that user's files.

I'll try to cover this use case a little better in the documentation.

Thanks for filing this! I think you're running into this problem because `pipx ensurepath` only applies to the shell for the Unix user account in which that command is run. In other words, when you run `sudo pipx ensurepath`, that modifies the `PATH` environment variable for the root user—but not for your non-root user. So I see a couple of options here: * You can `su` or `sudo` to a root shell before running borgmatic as the root user. That should work because it'll use root's `PATH`. * Or: Manually add `/root/.local/bin` to your non-root user's PATH (in `~/.bashrc` or similar) so `sudo borgmatic` works as expected. * Or: Install borgmatic (and run `pipx ensurepath`) as a non-root user instead of (or in addition to) a root user. This would only work though if you want to run borgmatic as a non-root user and therefore only have access to that user's files. I'll try to cover this use case a little better in the documentation.
Owner

Okay, I implemented some documentation updates that should hopefully clarify this situation. Please check it out and let me know what you think and whether this solves your issue at all: https://torsion.org/borgmatic/docs/how-to/set-up-backups/#installation

If not, I'd be happy to reopen this ticket and try something else. ("Happy" in that I'd be cursing the Python packaging ecosystem all the while.)

Okay, I implemented some documentation updates that should hopefully clarify this situation. Please check it out and let me know what you think and whether this solves your issue at all: https://torsion.org/borgmatic/docs/how-to/set-up-backups/#installation If not, I'd be happy to reopen this ticket and try something else. ("Happy" in that I'd be cursing the Python packaging ecosystem all the while.)
Author

Thanks! Is there any risk if installing both root and non-root?

Thanks! Is there any risk if installing both root and non-root?
Owner

The only risk I can think of is that you might upgrade one and forget to upgrade the other—and end up with different versions installed!

The only risk I can think of is that you might upgrade one and forget to upgrade the other—and end up with different versions installed!

After upgrading to bookworm and all my backups failing, I was getting the "module not found" error with borgmatic so I came to reinstall and see it's now via pipx instead of pip.

I tried the root install and the user install and adding the path to .bashrc, but neither option makes sudo borgmatic --version work.

I can do it with my user or as root but not with sudo:

user@pve:~ $ sudo borgmatic --version
sudo: borgmatic: command not found

user@pve:~ $ borgmatic --version
1.8.3

user@pve:~ $ sudo su -
root@pve:~ # borgmatic --version
1.8.3

halp?

After upgrading to bookworm and all my backups failing, I was getting the "module not found" error with borgmatic so I came to reinstall and see it's now via `pipx `instead of `pip`. I tried the root install and the user install and adding the path to `.bashrc`, but neither option makes `sudo borgmatic --version` work. I can do it with my user or as root but not with sudo: ``` user@pve:~ $ sudo borgmatic --version sudo: borgmatic: command not found user@pve:~ $ borgmatic --version 1.8.3 user@pve:~ $ sudo su - root@pve:~ # borgmatic --version 1.8.3 ``` halp?
Owner

Hmm.. Some thoughts:

  • How did you add the path to your .bashrc? Did you use pipx ensurepath to do it? You might give that a shot rather than manual path modifications.
  • Does the sudo command work if you specify sudo -E? That would indicate there's an environment variable (e.g. PATH) not getting set properly upon sudo.
Hmm.. Some thoughts: * How did you add the path to your `.bashrc`? Did you use `pipx ensurepath` to do it? You might give that a shot rather than manual path modifications. * Does the `sudo` command work if you specify `sudo -E`? That would indicate there's an environment variable (e.g. `PATH`) not getting set properly upon `sudo`.

I used pipx ensurepath and it put export PATH="$PATH:/root/.local/bin" in my .bashrc

echo $PATH shows /root/.local/bin

sudo -E does not work.

upon googling, it looks like there's a secure_path that's managed with visudo. I added /root/.local/bin to the end of that list and now sudo borgmatic --version works.

I used `pipx ensurepath` and it put `export PATH="$PATH:/root/.local/bin"` in my `.bashrc` `echo $PATH` shows `/root/.local/bin` `sudo -E` does not work. upon googling, it looks like there's a `secure_path` that's managed with visudo. I added `/root/.local/bin` to the end of that list and now `sudo borgmatic --version` works.
Owner

Nice detective work! I'm glad to hear that worked. I'll make a note in the docs about this solution. Thanks!

Nice detective work! I'm glad to hear that worked. I'll make a note in the docs about this solution. Thanks!
Sign in to join this conversation.
No Milestone
No Assignees
3 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#757
No description provided.