Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

According to this tutorial trying to backup mysql database

I did:

1) created folders in home directory. /home/USERNAME/backup/

2) in folder backup created file, named

3) created content of

backup_filename=$db_name-`date +%F`

mysqldump -h localhost -u $db_user -p$db_password $db_name | gzip > /home/USERNAME/dbbackup/$backup_filename.sql.gz

Made executable (Octal: 0755)

4) created folder dbbackup. path: /home/USERNAME/dbbackup/

5) Using putty.exe logged in and typed crontab –e, then Enter. Latter found that cron configuration file is located in directory /var/spool/cron/ and file name is root

6) opened root file with Notepad++ and pasted following code

45 14 * * *     /bin/sh /home/USERNAME/backup/

As result in /home/USERNAME/dbbackup/ must see some file. But see nothing (empty folder).

Please advice what need to correct, to backup mysql

share|improve this question
You edited the crontab file manually, so cron probably doesn't know you've made any changes. It's always best to use the crontab command, because that sends a signal to cron to re-read the config files. Try using crontab to make a trivial change in the file, then see if your backups run. – MadHatter Oct 21 '13 at 12:24
up vote 0 down vote accepted

Check the below file for the cron log output. /var/log/syslog

You can also filter the log using this command:

grep CRON /var/log/syslog

To configure log in your cron job:

 45 14 * * *     /bin/sh /home/USERNAME/backup/ 2>&1 >> /var/log/myjob.log

share|improve this answer
can not find file syslog in /var/log/ grep: /var/log/syslog: No such file or directory OK. Will configure cron job according to your advice. – user2118559 Oct 21 '13 at 12:22
The is a space after 2>&1, I have edited accordingly! If you don't find syslog then it might be /var/log/messages for CentOS/Redhat. – Zeeshan Oct 21 '13 at 12:29
Yes, see file messages. And see nothing about backup / cron job. Will try to backup manually to see if it works at all. – user2118559 Oct 21 '13 at 14:48

A few thoughts:

  1. Since you're using CentOS, the default location for Cron's logs should be /var/log/cron. There may not be much information in there, but it should at least tell you whether or not the Cron daemon is attempting to run your script.

  2. Zeeshan's output redirection above might work successfully but a simpler notation would be to use the "redirect all output to file"... e.g.

    45 14 * * * /bin/sh /home/USERNAME/backup/ &> /some/file

    A good overview of Bash redirection methods is located here:

  3. Crontab files are finicky in a couple of ways; one way is that they require a blank line as the last line in the file. I'd suggest making sure there's at least one empty line at the end of the file (having several won't hurt, so you could throw a couple in there for good measure.)

  4. Did you run the backup script manually before attempting to automate it with Cron? If there's a problem with the script itself, adding Cron automation on top of it would only make troubleshooting harder.

share|improve this answer
In cron see Oct 21 10:40:01 localhost CROND[16090]: (root) CMD (/usr/bin/php -q /etc/zpanel/panel/bin/daemon.php >> /dev/null 2>&1). Manually did not run backup script. Yes, at first need to try manually. Not sure if it matters, but I use Zpanel ( – user2118559 Oct 21 '13 at 14:43
Tried manually with ./ and no backup at all. So appears that error is in code of backup file – user2118559 Oct 21 '13 at 15:15
I'd start by breaking down the script and confirming proper function of each component. So for instance, at a command line simply run the mysqldump command (with the appropriate username, password, etc.) and see if you get a successful dump. Be aware that if you specify the password on the command line using the -p flag, the password will show up in a process listing; so any other users who are ssh'd into the system might be able to see the password if they ran a process list. Might be safer to run the command without the -p flag first, supplying it interactively when prompted. – jon Oct 21 '13 at 15:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.