0

Hello all,

I trust you're well as you read this request for assistance. I am not very experienced in the Linux world, but all the same I'm striving to learn as quickly as possible. So please pardon any obvious ignorance on my part and assist if possible.

I am running a ClearOS v5.2 Enterprise server (based on the Centos linux distro) and I'm using the following command in a shell script to backup my MySQL database.

mysqldump -u root -pMYPASSWORD --all-databases > /mnt/shares/flexshares/backup/MySQL/mysql-backup-`date +%Y-%m-%d-%H-%M`.sql

I use a cron job to call this script @ 1:15 AM daily. Now, I can see in the cron log that the job is executed at that time and the script is called, but the command doesn't execute (log entries below). I say this because I don't see the sql file being created in the /mnt/shares/flexshares/backup/MySQL directory.

Aug 21 01:15:01 server1 crond[27842]: (root) CMD (/root/my_scripts/backup-mysql.sh)
Aug 22 01:15:01 server1 crond[9031]: (root) CMD (/root/my_scripts/backup-mysql.sh)

Strangely enough, if I run the same command from the CLI it executes without any problems and the MySQL database is dumped to the target directory (/mnt/shares/flexshares/backup/MySQL).

What am I missing or what have I included in the script that's causing it not to run? Here's my shell script ("backup-mysql.sh"):

#!/bin/bash
# FULL BACKUP OF MySQL DATABASE
mysqldump -u root -pMYPASSWORD --all-databases > /mnt/shares/flexshares/backup/MySQL/mysql-backup-`date +%Y-%m-%d-%H-%M`.sql

I am very grateful for any help I can get, thanks.

v/r

Kismet

4

3 回答 3

3

I think your commands are not executed properly from script. Can you try the following -

         #!/bin/sh
         DUMPFILE=mysql-backup-`date +%Y-%m-%d-%H-%M`.sql
         `mysqldump -u root -pMYPASSWORD --all-databases > $DUMPFILE`
于 2013-08-22T16:59:25.877 回答
2

I feel there is no problem with the script.

Please check if you are provided with enough execute permission and your cron entry is proper.

Try executing the script on your own and see if the DB file is generating or not.

于 2013-08-22T16:36:07.203 回答
0

I really appreciate the assistance. Based on @Narayan 's comment that the problem may be at the cron job - I did some more testing with the cron job to see where my problem was. Well, it wasn't long before I got an access denied when I tried to run the script directly from the CLI by doing ./backup-mysql.sh.

This prompted me to check the permissions of the script file, and ironically it wasn't executable. I believe this was why the script wasn't running from the cron job. I changed the permissions and tested and all is working fine.

I guess my lesson of the day in the linux world, CHECK PERMISSIONS ALWAYS! Thanks anyway for your assistance, I really appreciate it.

于 2013-08-23T14:09:07.383 回答