4

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.

Mohsen
  • 65
  • 1
  • 6
  • The double quotes (`"`) in the title are correct, but they're rendered as opening (`“`) and closing (`”`) quotes, at least in my browser (and the opening and closing quotes look identical in the font used for comments). – Keith Thompson Jul 11 '13 at 21:09

2 Answers2

7

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.

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
1

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.

Otto Allmendinger
  • 27,448
  • 7
  • 68
  • 79
  • Of the special characters mentioned on the linked web page, only `%` is relevant; the others are not treated specially in a command. – Keith Thompson Jul 11 '13 at 21:10