WebFaction
Community site: login 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 17 Sep '12, 10:06

comheroes
11510
accept rate: 0%


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

'date +%Y%m%d'

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

`date +%Y%m%d`

Hope that helps!

permanent link

answered 17 Sep '12, 10:29

seanf
12.2k41836
accept rate: 37%

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

(18 Sep '12, 02:44) comheroes

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

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

Hope that helps!

(18 Sep '12, 03:23) ryans ♦♦
Your answer
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

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×50

question asked: 17 Sep '12, 10:06

question was seen: 1,885 times

last updated: 18 Sep '12, 03:23

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM