WebFaction
Community site: login faq
0
1

I've tried modifying the cron command outlined in the docs for backing up databases to the server so that they can be emailed instead.

0 0 22 * * mysqldump --defaults-file=$HOME/db_backups/db_name.cnf -u db_user db_name | gzip | uuencode db_name-`date +\%Y\%m\%d`.sql.gz | mail email@example.com

but when the email comes through it has no content. What am I missing?

asked 05 Dec '13, 15:33

tyssen
13
accept rate: 0%


Try modifying the mail command to specify the subject and the file file attachment

$ man mail
  -a file
          Attach the given file to the message.
  -s subject
          Specify subject on command line (only the first argument after the -s flag is used as a subject; be careful
          to quote subjects containing spaces).

Than verify it works in shell before setting it in cron.

permanent link

answered 05 Dec '13, 23:28

johns
5.3k312
accept rate: 23%

Seems like it's not the mail part that's failing, but rather the gzipping because I get: gzip: db_name-20131207.sql.gz: No such file or directory / mysqldump: Got errno 32 on write when I run: $ mysqldump --defaults-file=$HOME/db_backups/db_name.cnf -u db_user db_name | gzip db_name-date +%Y%m%d.sql.gz

(07 Dec '13, 04:13) tyssen

In cron you need to use the full path to executables, for mysqldump the path is

/usr/bin/mysqldump

You can get the full paths using

which <executable>
(07 Dec '13, 07:43) timg ♦♦

But the documentation I linked to in my opening post doesn't include the full path to mysqldump and when I follow their example exactly, before trying to gzip the output, it saves a file successfully.

(07 Dec '13, 15:37) tyssen

You might want to make a shell script which runs one command at a time, as opposed to feeding the output of one command into the other, than invoke the script in cron. This should allow gzip to function correctly, after the database dump happens and the file can be verified as created. The example will be different since gzip and mailing add complexity.

(07 Dec '13, 18:04) johns

Thanks, I've done that, and all good now. :)

(07 Dec '13, 20:54) tyssen

how about sharing the cron commands for us noobs?

(09 Dec '13, 13:45) baba
showing 5 of 6 show 1 more comments
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:

×260
×81

question asked: 05 Dec '13, 15:33

question was seen: 1,967 times

last updated: 09 Dec '13, 13:49

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