1

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

6
  • Where are you looking for your dumped file ? They supposed to save under /mnt/shares/flexshares/backup/MySQL/mysql-backup-date +%Y-%m-%d-%H-%M.sql Commented Aug 22, 2013 at 16:40
  • One possibility(?) Q: Is "/mnt/shares/flexshares/backup" on a local filesystem, are is that on an auto-mounted remote filesystem? If its not local, then maybe that's not available at the time cron runs the script(?). If it were me, I'd verify that and run a test that writes to known filesystem that has write permissions: /tmp Commented Aug 22, 2013 at 16:41
  • @rakib I have edited the question to show the correct target directory. Commented Aug 22, 2013 at 16:50
  • @spencer7593 /mnt/shares/flexshares/backup is on another HDD that I've auto-mounted so it's always available. I have verified that if I change the target to /root it doesn't work from the cron job, but works if I run it manually at the CLI. Also, it works when run manually with /mnt/shares/flexshares/backup/MySQL as the target. Commented Aug 22, 2013 at 16:52
  • @Kismet Agbasi: another suggestion would be to fully qualify the location of the mysqldump executable, in case that directory is not in the path: /opt/mysql/bin/mysqldump -u root ... or wherever your executable is. (which mysqldump). Commented Aug 22, 2013 at 18:29

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

in that case the culprit shd be cron entry for sure
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`

3 Comments

I tried what you suggested, but with no luck. Assuming of course that I didn't copy and paste incorrectly. Was the entire command supposed to be on one line? Cos that's how I ran it.
There's two different line. Firstline is DUMPFILE variable setup. Next line executes the command.
Thanks, it worked. I appreciate it. Unfortunately, it didn't work from the cron, so I decided to check the permissions of the file and lo it wasn't set to executable. So I changed it and the cron works. Thank you so very much.
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.