login community faq

Hi,

We've been trying to create an automatic database backup with a date attached using Crontab. Using this code (available on the Cron help guide)

0 0 * * 1 mysqldump --defaults-file=$HOME/backups/db/database_name.cnf -u database_name database_name > $HOME/backups/db/database_name-'date +%Y%m%d'.sql 2>> $HOME/backups/db/cron.log

Unfortunately, the output doesnt display the date properly: database_name +%Y%m%d.sql

Does anyone know / see what we're doing wrong here?

Thanks in advance,

Kind regards,

Jochem

asked Sep 17 '12 at 10:06

comheroes's gravatar image

comheroes
12


In your example, you're using single-quote characters around the date command, eg:

1
'date +%Y%m%d'

What you would be using instead is backticks (grave accents), eg:

1
`date +%Y%m%d`

Hope that helps!

answered Sep 17 '12 at 10:29

seanf's gravatar image

seanf ♦♦
59891220

Thanks Sean, I'm pretty sure that will work!

(Sep 18 '12 at 02:44) comheroes comheroes's gravatar image

Just for completeness, in some shells, it's necessary to escape the % symbols as well; like this:

1
`/bin/date +\%Y\%m\%d`

Hope that helps!

(Sep 18 '12 at 03:23) ryans ♦♦ ryans's gravatar image
Your answer
If you have an answer to the above question, then use the form below. Otherwise, use the appropriate 'add new comment' button above to post your feedback.
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×37

Asked: Sep 17 '12 at 10:06

Seen: 346 times

Last updated: Sep 18 '12 at 03:23

Plans & prices    Sign up    Why WebFaction?    Contact us    Affiliate program    Support    Legal    Jobs    Blog    Control panel login
Powered by OSQA
© Copyright 2003-2012 Swarma Limited - WebFaction is a service of Swarma Limited