Cronjob

Hi,

I have a problem with a cronjob.
My Joomla-Site creates a backup everyday and I want this backupfile to be in another directory (as the joomla-backup-script has just access to the webfolders) Therefore I wrote this small script but unfortunately the script is not executed daily.
When executing it manually via the console everything is working fine. Has anyone an idea whats wrong with it?

So here is the script:

joomla-movebackup

#!/bin/sh

JOOMLA_BACKUP_DIRECTORY="/srv/www/htdocs/backup"
OUTPUT_DIRECTORY="/data/backup/joomla"

cd $JOOMLA_BACKUP_DIRECTORY
/usr/bin/find -iname "*.jpa" -mtime -1 -exec cp {} $OUTPUT_DIRECTORY \;

cd $OUTPUT_DIRECTORY
/usr/bin/find -iname "*.jpa" -mtime +0 -delete

The script is located in /data/scripts and has the following rights:

thunderstorm:/data/scripts # dir
insgesamt 16
-rwxr-xr-x 1 root root 746  6. Apr 10:59 backup.php
-rwxr-xr-x 1 root root 199  6. Apr 13:40 joomla-backup
-rwxrwxrwx 1 root root 268 10. Mai 17:45 joomla-movebackup
-rwxr-xr-x 1 root root 153 25. Mär 10:04 openldap-backup

The crontab file looks like this:

SHELL=/bin/sh
PATH=/usr/bin:/usr/sbin:/sbin:/bin:/usr/lib/news/bin
MAILTO=root
#
# check scripts in cron.hourly, cron.daily, cron.weekly, and cron.monthly
#
-*/15 * * * *   root  test -x /usr/lib/cron/run-crons && /usr/lib/cron/run-crons >/dev/null 2>&1
45 23 * * *     root /data/scripts/openldap-backup
46 23 * * *     root /data/scripts/joomla-backup
50 23 * * *     root /data/scripts/joomla-movebackup

Is your /data partition mounted with no exec permission? Try changing that command to for example:

sh /data/scripts/joomla-movebackup

Hi,

are you sure that the backup skript terminates within 4 minutes? Perhaps there is no data to perform when running the move-skript cause the backup skript isn’t ready.

Just an idea.

Bye

Erik

And I suppose that you mean with the “crontab file” the system crontab file /etc/crontab, and not the crontab of root (or another user)?

And yes, my first idea was also the 4 minutes. You say it is not executed daily, how you know? How do you detect the difference between “the script is not executed” and “the file is not copied”?

Also you could build in some traces like:

/usr/bin/find -iname "*.jpa" -mtime -1 >>/tmp/joomtrace

to check what happens.

And a simple

date >>/tmp/joomtest

in the begin, to see if it executes.

Thanks for your ideas.
So how do I know that there are backup files to be copied? Joomla has always 2 backup files stored, so there always have to be files that could be copied. (And they truly are, as I checked it)
Besides that the joomla-backup-script is finished after about 30 seconds

the /data directory is no partition

With “the script is not executed daily” I wanted to say that no files are copied and no old files are deleted.

I’ve added those traces. Lets see what happens.

Thanks for your help :slight_smile:

But that is not the same. It may not matter at all in this case, but report exactly what you see that happens and not what you think that happens (wisecrack of old trouble shooting programmer). :wink:

BTW any reason to write a POSIX shell script instead of a bash script? Again, I do not think it matters, but I am just curious.

Okay I’ve modified the script to check whether it’s executed or not.

#!/bin/sh
date >>/tmp/joomtest1

JOOMLA_BACKUP_DIRECTORY="/srv/www/htdocs/backup"
OUTPUT_DIRECTORY="/data/backup/joomla"

cd $JOOMLA_BACKUP_DIRECTORY
/usr/bin/find -iname "*.jpa" -mtime -1 -exec cp {} $OUTPUT_DIRECTORY \;

date >>/tmp/joomtest2

cd $OUTPUT_DIRECTORY
/usr/bin/find -iname "*.jpa" -mtime +0 -delete

date >>/tmp/joomtest3

But none of the joomtest files were created.

I’m more or less new to linux so there is no reason why I used posix instead of bash.

I really don’t know what to do next… :frowning: Has anyone an idea?

Grep /var/log/messages to see it the job was started.

Again, try changing the command to sh /data/blah/blah/shellscript.

Also, is this your crontab (edited with crontab -e) or /etc/crontab? The user field is only used in the latter.

Did you edit the file with a Linux editor? Windows editors add a carriage return which can upset things.

Finally, cron daemon is installed and running, right?

I asked this earlier (post #4) and there was no answer. Please flekschas.

How can I use a Windowseditor to edit files on linux? :smiley: No I used kwrite.
The cron deamon is running as the other two cronjobs run perfectly.
I edited the crontab file directly. (I did the same with the other cronjobs and they’re working)
/var/log/messages shows me that the other two jobs were started but the one I’m trying to get running

Okay I changed the command to sh /data…

Hopefully this works

That is no answer to my question. There are many crontab files on the system. Is it* /etc/crontab* or not?