You are not logged in.
This might be pretty simple to figure out but no matter what I have tried it doesn't work.
The script is in the /etc/cron.daily folder
if I execute the file from the $prompt evern with sudo I get a permissions error.
If I change to root with the # prompt the script runs perfectly.
I will show you the contents of the directories and let me know what else you need.
I am testing by running this command:
sudo run-parts /etc/cron.daily/demo@mail cron.daily]$ ls -l
total 4
-rwxr-xr-x 1 root root 592 Mar 20 07:59 mailcow-backup.sh[demo@mail cron.d]$ ls -l
total 8
-rw-r--r-- 1 root root 158 Mar 20 08:26 0daily
-rw-r--r-- 1 root root 128 Sep 22 04:05 0hourly# Run the daily jobs
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=danc@dccathome.com
0 1 * * * root run-parts /etc/cron.daily./mailcow-backup.sh#!/bin/bash
# Backup mailcow data
# https://docs.mailcow.email/backup_restore/b_n_r-backup/
set -e
OUT="$(mktemp)"
export MAILCOW_BACKUP_LOCATION="/mnt/mailbackup"
SCRIPT="/opt/mailcow-dockerized/mailcow-dockerized/helper-scripts/backup_and_restore.sh"
PARAMETERS="backup all"
OPTIONS="--delete-days 3"
# run command
set +e
"${SCRIPT}" ${PARAMETERS} ${OPTIONS} 2>&1 > "$OUT"
RESULT=$?
if [ $RESULT -ne 0 ]
then
echo "${SCRIPT} ${PARAMETERS} ${OPTIONS} encounters an error:"
echo "RESULT=$RESULT"
echo "STDOUT / STDERR:"
cat "$OUT"
fiLast edited by MAYBL8 (2026-03-20 15:37:21)
Online
0 1 * * * root run-parts /etc/cron.daily./mailcow-backup.sh
Is there a dot at the end of /etc/cron.daily./ ?
if I execute the file from the $prompt evern with sudo I get a permissions error.
If I change to root with the # prompt the script runs perfectly.
What are "the $prompt" and "the # prompt"?
What are exact commands and error messages?
Add "set -x" to the script to trace execution.
Online
MAYBL8 wrote:0 1 * * * root run-parts /etc/cron.daily./mailcow-backup.shIs there a dot at the end of /etc/cron.daily./ ?
yesMAYBL8 wrote:if I execute the file from the $prompt evern with sudo I get a permissions error.
If I change to root with the # prompt the script runs perfectly.What are "the $prompt" and "the # prompt"?
like $sudo ./mailcow-backup.sh
vs $./mailcow-backup.sh
What are exact commands and error messages?[demo@mail cron.daily]$ ./mailcow-backup.sh /opt/mailcow-dockerized/mailcow-dockerized/helper-scripts/backup_and_restore.sh: line 79: /opt/mailcow-dockerized/mailcow-dockerized/helper-scripts/../mailcow.conf: Permission denied /opt/mailcow-dockerized/mailcow-dockerized/helper-scripts/backup_and_restore.sh backup all --delete-days 3 encounters an error: RESULT=1 STDOUT / STDERR: Using 1 Thread(s) for this run. Notice: You can set the Thread count with the THREADS Variable before you run this script. Using /mnt/mailbackup as backup/restore location. Could not determine compose project nameAdd "set -x" to the script to trace execution.
[demo@mail cron.daily]$ ./mailcow-backup.sh
++ mktemp
+ OUT=/tmp/tmp.iVTeqxS2kn
+ export MAILCOW_BACKUP_LOCATION=/mnt/mailbackup
+ MAILCOW_BACKUP_LOCATION=/mnt/mailbackup
+ SCRIPT=/opt/mailcow-dockerized/mailcow-dockerized/helper-scripts/backup_and_restore.sh
+ PARAMETERS='backup all'
+ OPTIONS='--delete-days 3'
+ set +e
+ /opt/mailcow-dockerized/mailcow-dockerized/helper-scripts/backup_and_restore.sh backup all --delete-days 3
/opt/mailcow-dockerized/mailcow-dockerized/helper-scripts/backup_and_restore.sh: line 79: /opt/mailcow-dockerized/mailcow-dockerized/helper-scripts/../mailcow.conf: Permission denied
+ RESULT=1
+ '[' 1 -ne 0 ']'
+ echo '/opt/mailcow-dockerized/mailcow-dockerized/helper-scripts/backup_and_restore.sh backup all --delete-days 3 encounters an error:'
/opt/mailcow-dockerized/mailcow-dockerized/helper-scripts/backup_and_restore.sh backup all --delete-days 3 encounters an error:
+ echo RESULT=1
RESULT=1
+ echo 'STDOUT / STDERR:'
STDOUT / STDERR:
+ cat /tmp/tmp.iVTeqxS2kn
Using 1 Thread(s) for this run.
Notice: You can set the Thread count with the THREADS Variable before you run this script.
Using /mnt/mailbackup as backup/restore location.
Could not determine compose project name
[demo@mail cron.daily]$Last edited by MAYBL8 (2026-03-20 13:00:47)
Online
dimich wrote:Is there a dot at the end of /etc/cron.daily./ ?
yes
Why? "cron.daily" and "cron.daily." are different paths. The latter is incorrect for cron.
/opt/mailcow-dockerized/mailcow-dockerized/helper-scripts/backup_and_restore.sh: line 79: /opt/mailcow-dockerized/mailcow-dockerized/helper-scripts/../mailcow.conf: Permission denied
What backup_and_restore.sh is trying to do with mailcow.conf at line 79? Read it, write or execute? The problem is accessing mailcow.conf.
Online
I'm sorry I am not understanding any of your questions.
I changed the cron line to this but it still didn't run.
0 1 * * * root run-parts /etc/cron.daily/./mailcow-backup.shThis is what it says at line 79
source ${SCRIPT_DIR}/../mailcow.confJust to be clear if I run the script from the directory /etc/cron.daily
it runs with
sudo ./mailcow-backup.sh
and
if I change to root
it runs by just using ./mailcow-backup.sh
running this command it does not work
sudo run-parts /etc/cron.dailyOnline
0 1 * * * root run-parts /etc/cron.daily/./mailcow-backup.sh
You can write just
0 1 * * * root run-parts /etc/cron.daily/mailcow-backup.shThis is not the reason why the script fails but "cron.daily./" is incorrect and "cron.daily/./" is redundant here.
UPD: Wait, this is also incorrect. run-parts expects directory name, not an executable. It should be
0 1 * * * root /etc/cron.daily/mailcow-backup.shdemo@mail cron.daily]$ ./mailcow-backup.sh ... /opt/mailcow-dockerized/mailcow-dockerized/helper-scripts/backup_and_restore.sh: line 79: /opt/mailcow-dockerized/mailcow-dockerized/helper-scripts/../mailcow.conf: Permission denied
Here you run mailcow-backup.sh as user. Most likely the user has no access permissions to mailcow.conf, so it fails, as expected.
running this command it does not work
sudo run-parts /etc/cron.daily
Does not work how? Show output of
sudo run-parts --debug --verbose /etc/cron.dailyLast edited by dimich (2026-03-20 14:28:01)
Online
ok i removed the ./
here is the result of running the command you asked.
demo@mail cron.daily]$ sudo run-parts --debug --verbose /etc/cron.daily
"mailcow-backup.sh": classicalre failOnline
"mailcow-backup.sh": classicalre fail
If neither the --lsbsysinit option nor the --regex option is given then the names must consist entirely of ASCII upper- and lower-case letters, ASCII digits, ASCII underscores, and ASCII minus-hyphens.
"mailcow-backup.sh" is not valid name for run-parts.
Also take a look to my previous comment update. "run-parts /etc/cron.daily/mailcow-backup.sh" is also incorrect. run-parts expects directory, not an executable.
Online
I changed the filename and I removed the /mailcow-backup.sh from the 0daily entry.
0 1 * * * root run-parts /etc/cron.dailystill get an error:
[demo@mail cron.daily]$ sudo run-parts --debug --verbose /etc/cron.daily
"mailcowbackup.sh": classicalre failOnline
entirely of ASCII upper- and lower-case letters, ASCII digits, ASCII underscores, and ASCII minus-hyphens
In which of those categories falls "."?
Why are you trying to use run-parts itfp?
Offline
entirely of ASCII upper- and lower-case letters, ASCII digits, ASCII underscores, and ASCII minus-hyphens
In which of those categories falls "."?
Why are you trying to use run-parts itfp?
so to run the script doesn't it need to be a .sh file?
How do I run the script without it being a .sh file?
I thought that is how the line was supposed to look and run.
What commands do I use?
Edit:
I took out the .sh and it ran.
I will mark this solved.
Thanks
Last edited by MAYBL8 (2026-03-20 15:36:14)
Online
The script needs to be executable and head w/ a shebang ("#!/bin/sh") and then you can call it whatever you want.
What commands do I use?
0 1 * * * root /etc/cron.daily/mailcow-backup.sh
Offline
Now that I have it working It is working too well.
For some reason it created to backups
One at 1:00am
And one at 3:46 am for some reason.
Last edited by MAYBL8 (2026-03-21 12:47:46)
Online
Does the script actually get called at those times?
#!/bin/bash
# Backup mailcow data
# https://docs.mailcow.email/backup_restore/b_n_r-backup/
date >> /tmp/mailcow.calls
…Does the system sleep or hibernate or so between 01:00 and 03:46 ?
Offline
the actual script looks pretty complicated to me so I don't want to get into that right now.
I don't have anything running that i am aware of that would put the machine to sleep.
Tell you what let me see what happens tomorrow and then I will see if it does the same thing.
Online
It is working too well.
You should EITHER put the script to /etc/cron.daily/
In this case it will run by
0 1 * * * root run-parts /etc/cron.dailyfrom /etc/cron.d/0daily
OR put
0 1 * * * root /path/to/mailcow-backupto /etc/cron.d/0daily or whatever other crontab. In this case the script should be NOT in /etc/cron.daily/ to prevent running by "run-parts /etc/cron.daily".
As alternative, you can use systemd timer.
Online
If I understood this correctly.
I removed /etc/cron.d/0daily
and in the directory /etc/cron.daily is this:
[demo@mail cron.daily]$ ls
mailcowbackupOnline
I removed /etc/cron.d/0daily and in the directory /etc/cron.daily is this: mailcowbackup
No. If you removed /etc/cron.d/0daily, nothing will run scripts from /etc/cron.daily/. (Unless you manually add "0 1 * * * root run-parts /etc/cron.daily" to some crontab).
If there is a line "0 1 * * * root run-parts /etc/cron.daily" in 0daily, it executes "run-parts /etc/cron.daily" daily. "run-parts" executes scripts from /etc/cron.daily.
If there is a line "0 1 * * * root /path/to/mailcowbackup" in 0daily, it executes "/path/to/mailcowbackup" daily.
If there are both lines in 0daily, and mailcowbackup is in /etc/cron.daily/, it executes mailcowbackup twice: via run-parts and as a separate cronjob.
If 0daily doesn't exist or doesn't contain corresponding entries, mailcowbackup is never executed no matter where it is located.
Last edited by dimich (2026-03-21 19:33:07)
Online
Ok I am sorry for being so dense.
I have recreate a 0daily
and put
0 1 * * * root run-parts /etc/cron.daily
in it
The script is in the cron.daily directory
Last edited by MAYBL8 (2026-03-21 21:54:18)
Online
Yep, this should work.
crond looks for files /etc/cron.d/, finds 0daily, reads it and schedules "run-parts /etc/cron.daily" to execute as root every day at 1:00.
When executed, run-parts looks for files in /etc/cron.daily/ directory, finds your script and executes it.
Online
For some reason it made 2 backups again.
one at 1
and one at 3:38 this time.
How can I troubleshoot this?
thanks
OK I looked at journalctl -b and found this at 3:46
Mar 21 03:46:00 mail anacron[766432]: Job `cron.daily' startedThat matches the time from yesterday
Ok I found this in the anacrontab file:
I commented out the line for cron.daily
# See anacron(8) and anacrontab(5) for details.
SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=danc@dccathome.com
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=45
# the jobs will be started during the following hours only
START_HOURS_RANGE=3-22
#period in days delay in minutes job-identifier command
#1 5 cron.daily nice run-parts /etc/cron.daily
7 25 cron.weekly nice run-parts /etc/cron.weekly
@monthly 45 cron.monthly nice run-parts /etc/cron.monthlyShould this be the solution?
Last edited by MAYBL8 (2026-03-22 12:52:28)
Online
Should this be the solution?
It depends on what you want to achieve.
If you want to run a job at specific time periodically, you should use cron.
If you want to run a job at random time but not more frequently than specific period, you should use anacron.
Online
Indeed, there is some confusion because different cron implementations may use different schemas to run asynchronous jobs. Assuming you use cronie.
If exact time of execution doesn't matter, place mailcowbackup script to /etc/cron.daily/. With your /etc/anacrontab it will run between 3:00 and 22:00 with random 5..50 minute delay according to this line:
1 5 cron.daily nice run-parts /etc/cron.dailyIf you comment this line, neither mailcowbackup nor other scripts in /etc/cron.daily will run by anacron. I would not recommend to comment it.
"/etc/cron.d/0daily" can be removed.
If you want to run mailcowbackup at exact time, you should place mailcowbackup somewhere else and configure cron to run it. For example, in /etc/cron.d/0daily:
0 1 * * * root /usr/local/lib/backup-scripts/mailcowbackup(Actualy the name of file in /etc/cron.d/ can be any, not necessary "0daily". E.g. /etc/cron.d/backups).
Online