Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Kann

macrumors newbie
Original poster
Apr 7, 2009
11
0
Dear all,

I am trying to write a back up scripts for all database at my office; so, I wrote a mysqldump script and trying to use crontab to schedule run the daily backup. However, the backup sql file is generated, but with an empty content. It seems that the cron daemon does run the job, but return an empty file. I tried running the script on command line and it worked just fine (the proper backup script was returned). Why does my backup script work with out problem when I execute it manually from command line but not work from crontab/cron daemon?

All backup scripts and the crontab file were written by root account. Below is my short back up script and the crontab file:

Code:
sh-3.2# crontab -l
55	11	*	*	*	root	/bin/sh /Volumes/Pharmakon/bin/backup/database.sh
sh-3.2#


Code:
sh-3.2# more /Volumes/Pharmakon/bin/backup/database.sh 
/usr/bin/mysqldump -u root --password=xxx --all-databases >/Volumes/Pharmakon/backup/databases/backup.sql
sh-3.2#
 

ChrisA

macrumors G5
Jan 5, 2006
12,919
2,173
Redondo Beach, California
The dump command runs as root. Do you actually run the database as root with all file owned by root? Most people would make a special user just for the databse. If you are setup like that then perhaps you should run the dump as that user.

I don't use mysql but other DBMSes will refuse to run under root as that is to dangerous
 

Kann

macrumors newbie
Original poster
Apr 7, 2009
11
0
The dump command runs as root. Do you actually run the database as root with all file owned by root? Most people would make a special user just for the databse. If you are setup like that then perhaps you should run the dump as that user.

I don't use mysql but other DBMSes will refuse to run under root as that is to dangerous

I don't intend to run the dump command as a root, but was kinda using the root account while I was testing all the backup commands to make sure things don't get the permission issue.

The weird thing is that the script worked just find from command line, but did nothing from the cronjob.
 

belvdr

macrumors 603
Aug 15, 2005
5,945
1,372
I don't intend to run the dump command as a root, but was kinda using the root account while I was testing all the backup commands to make sure things don't get the permission issue.

The weird thing is that the script worked just find from command line, but did nothing from the cronjob.

Add 2>&1 to the end of your command in cron and check the log.

The main difference here is that running from a shell, you have a totally different environment versus what cron runs from.
 

nopster

macrumors member
Jun 10, 2009
72
20
Hi, i have a similar issue.

I have a jar file that launches mysqldump queries on several dbs and servers.

If I launch from the command line the batch mysqldump dumps every db in the list.

I tried Cronnix to make the backups every 24 hours, but the mysqldump reports 0 byte of every single dump of dbs.

Then I tried Lingon to configure the same batch and making a launchd. But even here the dump are 0 byte.

Previously on Mac OS X Server 10.6 everything worked fine, now that this procedure runs on Lion client with Java runtime installed work nomore.

Every type of help is really appreciated.

Thanks in advance.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.