cron and run-parts system #206

Closed
opened 2019-08-19 15:43:31 +00:00 by Asaln · 3 comments

Can we create a cron job for the system and not for the root user. If I run a task with the root crontab, including using run-parts it goes well. But if I do exactly the same thing in /etc/cron.xxx with run-parts I have as a result:


/etc/cron.hourly/borgmatic:
Traceback (most recent call last):
File "/ root / bin / borgmatic", line 6, in
from borgmatic.commands.borgmatic import main
ModuleNotFoundError: No module named 'borgmatic'
run-parts: /etc/cron.hourly/borgmatic exited with return code 1


Running run-parts in a terminal with root works:


run-parts /etc/cron.hourly/.
/etc/borgmatic/config.yaml: Running command for pre-backup hook
Starting a backup job.
/ mnt / save / TEST: Pruning archives
.....


In two words it works with the root user but not for the system ...

Other notes / implementation ideas

Environment

borgmatic version: [version here]
Version: 1.3.14

borgmatic installation method: [e.g., Debian package, Docker container, etc.]
pip3 as official guide
Borg version: [version here]
borgbackup-1.2.0-0.a4.1.mga7

Python version: [version here]

Use python --version
Python 2.7.16

operating system and version: [OS here]
Mageia release 7 (Official) for x86_64

Can we create a cron job for the system and not for the root user. If I run a task with the root crontab, including using run-parts it goes well. But if I do exactly the same thing in /etc/cron.xxx with run-parts I have as a result: ****** /etc/cron.hourly/borgmatic: Traceback (most recent call last): File "/ root / bin / borgmatic", line 6, in <module> from borgmatic.commands.borgmatic import main ModuleNotFoundError: No module named 'borgmatic' run-parts: /etc/cron.hourly/borgmatic exited with return code 1 ******** Running run-parts in a terminal with root works: ******** run-parts /etc/cron.hourly/. /etc/borgmatic/config.yaml: Running command for pre-backup hook Starting a backup job. / mnt / save / TEST: Pruning archives ..... ********* In two words it works with the root user but not for the system ... #### Other notes / implementation ideas #### Environment **borgmatic version:** [version here] Version: 1.3.14 **borgmatic installation method:** [e.g., Debian package, Docker container, etc.] pip3 as official guide **Borg version:** [version here] borgbackup-1.2.0-0.a4.1.mga7 **Python version:** [version here] Use `python --version` Python 2.7.16 **operating system and version:** [OS here] Mageia release 7 (Official) for x86_64
Owner

Thanks for filing the ticket! This might be a Python path issue. Try adding PYTHONPATH=/root/.local/lib/python3.7/site-packages or similar (your version of Python may vary) to your cron job. See this example for how to insert environment variables like that in your cron job command invocation: https://projects.torsion.org/witten/borgmatic/src/branch/master/sample/cron/borgmatic

Note that Python 2.x is unsupported. So the version of Python that borgmatic is using (if you installed with pip3) can most likely be found by running: python3 --version.

Let me know if that helps!

Thanks for filing the ticket! This might be a Python path issue. Try adding `PYTHONPATH=/root/.local/lib/python3.7/site-packages` or similar (your version of Python may vary) to your cron job. See this example for how to insert environment variables like that in your cron job command invocation: https://projects.torsion.org/witten/borgmatic/src/branch/master/sample/cron/borgmatic Note that Python 2.x is unsupported. So the version of Python that borgmatic is using (if you installed with pip3) can most likely be found by running: `python3 --version`. Let me know if that helps!
Author

Thanks for the solution.
With run-parts and cron.daily etc. folders it is the same.
the PYTHONPATH variable can be added to a script in /etc/cron.daily (or other /etc/cron.xxx) in the same way. For example, for a default configuration:

PYTHONPATH=/root/.local/lib/python3.7/site-packages borgmatic --stats 2>&1

Thanks for the solution. With run-parts and cron.daily etc. folders it is the same. the PYTHONPATH variable can be added to a script in /etc/cron.daily (or other /etc/cron.xxx) in the same way. For example, for a default configuration: PYTHONPATH=/root/.local/lib/python3.7/site-packages borgmatic --stats 2>&1
Asaln closed this issue 2019-08-19 21:32:44 +00:00
witten added the
question / support
label 2019-08-19 22:02:10 +00:00
Owner

Glad that worked out for you!

Glad that worked out for 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#206
No description provided.