Question

I am trying to sumbit a MySQL backup script through cpanel cron jobs panel, but I am receiving errors that I don't understand. I have tried the command on my Ubuntu

mysqldump -u(USERNAME) -p(PASSWORD) --all-databases | gzip > /home/MYHOMEDIR/myDBBckups/full_backup$(date "+%Y-%m-%d_%H:%M:%S").sql.gz

The error I am facing is:

---------- Email message ----------

From: Cron Daemon <root@MYSERVER>

Date: Thu, Jul 11, 2013 at 9:37 PM

Subject: Cron <MYUSERNAME@MYSERVER> mysqldump -u(USERNAME) -p(PASSWORD) --all-databases | 
gzip > /home/MYHOMEDIR/myDBBckups/full_backup$(date "+

To: MYEMAIL@gmail.com


/bin/sh: -c: line 0: unexpected EOF while looking for matching `"'

/bin/sh: -c: line 1: syntax error: unexpected end of file 

---------- End of Email message ----------

When I remove the date command everything works fine but I don't want to override my backup every time.

With help of Colleagues, i fixed it like this:

mysqldump -u(USERNAME) -p(PASSWORD) --all-databases | gzip > /home/MYHOMEDIR/myDBBckups/full_backup$(date "+\%Y-\%m-\%d_\%H:\%M:\%S").sql.gz

many thanks.

Was it helpful?

Solution

The % character in the command portion of a cron job is translated to a newline character. Either use \% to denote a % character, or put the date command into an external script that you invoke from cron.

OTHER TIPS

Cron interprets the % character.

Put the line in a file create_backup.sh and put the command bash /path/to/create_backup.sh in your crontab instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top