Cron job config for virtual environments #752
Labels
No Label
bug
data loss
design finalized
good first issue
new feature area
question / support
security
waiting for response
No Milestone
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: borgmatic-collective/borgmatic#752
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What I'm trying to do and why
Hi, I responded in thread #751 on Debian's switch to virtual environments. I'm following up on the cron issue, similar to issue #68: when I install borgmatic using venv (sorry did that before you changed the instructions), I think it installs a user/local copy that is unavailable globally. I'm new to python virtual environments, so forgive my mistakes here.
The error messages borgmatic gave me about being unable to read /etc/ files were therefore super clear, and I simply created .yaml files in my local .config directory to run it manually. When it comes to the cron syntax however, I tried the standard root syntax, and played around with trying my user to initiate the job, but nothing has worked.
Steps to reproduce
I went with venv because I wanted to learn how python virtual environments work "under the hood" (hence the headaches, pipx was probably the right recommendation). I tried the following both with and without sudo:
I have config files already set up from prior to my OS upgrade. Then, either in
cron.d
or incrontab -e
I tried using:Actual behavior
Cron job simply doesn't run, the tmp error log reads:
Expected behavior
No response
Other notes / implementation ideas
No response
borgmatic version
1.8.2
borgmatic installation method
pip install using venv
Borg version
1.2.4
Python version
3.11.4
Database version (if applicable)
No response
Operating system and version
PRETTY_NAME="Ubuntu 23.04" 2 │ NAME="Ubuntu" 3 │ VERSION_ID="23.04" 4 │ VERSION="23.04 (Lunar Lobster)" 5 │ VERSION_CODENAME=lunar 6 │ ID=ubuntu 7 │ ID_LIKE=debian 8 │ HOME_URL="https://www.ubuntu.com/" 9 │ SUPPORT_URL="https://help.ubuntu.com/" 10 │ BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" 11 │ PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" 12 │ UBUNTU_CODENAME=lunar 13 │ LOGO=ubuntu-logo
Fortunately, I think this should be a pretty easy fix! User-specific crontabs don't include the user, because they run as the user they're installed as. So if you're using
crontab -e
to create/edit your crontab, then simply omitroot
from that crontab entry.I certainly don't expect you to have used pipx prior to me having documented it, but if and when you feel sufficiently comfortable with learning about venvs, you may consider uninstalling borgmatic and reinstalling with pipx. It just streamlines a bunch of the process including upgrades!
Also, unrelated, but you may want to do
--verbosity -2
instead of-1
since you're logging to syslog. That'll prevent duplicate errors going to your syslog logs.Does pipx automatically install a symlink to
/root/.local/bin
? There was no symlink to my root user's.local
directory on my machine. That might be where venv diverges? Thus, I couldn't just take out root from the cron job syntax.I got it to work by creating a symlink to my user's
.local/bin
directory, and specifying that path in the user-specific crontabcrontab -e
:Everything works fine for me now. Thanks for the pointer about the logs and the assistance overall!
No, but it will put
~/.local/bin
in your user's systemPATH
if you go through its install steps (specificallypipx ensurepath
). And this accomplishes the same end effect as the symlink: Being able to run borgmatic commands without giving a full path. Note that this only applies to the current user, so if you run it withsudo
, it'll do it for the root user.That totally sounds like it'll work, but you may want to consider the
pipx ensurepath
approach if you want to be a little more "on the rails." Up to you.Glad everything's working for you though! Please file tickets for any other problems you encounter.