LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 03-02-2011, 04:15 AM   #1
lakridserne
LQ Newbie
 
Registered: Mar 2011
Posts: 2

Rep: Reputation: 0
MySQL backup cron job not executing correctly


Hi,

I own a CentOS 5 VPS. I typed crontab -e, and then I added the following line to automatically have my server backup mysql

0 * * * * mysqldump -u root -p password --all-databases | gzip > /home/dbbackup/database_`date '+%m-%d-%Y_%H'`.sql.gz

When I go in and look, it doesn't place any files in /home/dbbackup. When I run

mysqldump -u root -p password --all-databases | gzip > /home/dbbackup/database_`date '+%m-%d-%Y_%H'`.sql.gz

it'll place the files as it should.

What am I doing wrong?

Thanks a lot in advance.
 
Old 03-02-2011, 04:21 AM   #2
kuyalfinator
Member
 
Registered: Jul 2003
Location: Los Angeles
Distribution: RedHat8 2.4.18-14 RedHat9 2.4.20-8 FreeBSD 5.2.1 Ubuntu 10_4 Mandrake 2.4.21-0.13mdk
Posts: 118

Rep: Reputation: 16
CRON is tricky. Its picky in a the sense on how it uses syntax. First, look at the cron manual.

$man cron

Next, make sure the command your trying to type works. In testing cron, try a simple script for just getting a small mysql query.

$mysql> select name from myTable > TestMysqlCron
 
Old 03-02-2011, 04:38 AM   #3
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Piping ('|') doesn't work in cron because the interpreter sees the first part as the cron command and the part behind the pipe as a parameter, not as a second command to execute.

In order for this (a piped command) to work, create a separate script and call this script from cron.

jlinkels
 
Old 03-02-2011, 09:10 AM   #4
lakridserne
LQ Newbie
 
Registered: Mar 2011
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks

Thanks. This did it.
Quote:
Originally Posted by jlinkels View Post
Piping ('|') doesn't work in cron because the interpreter sees the first part as the cron command and the part behind the pipe as a parameter, not as a second command to execute.

In order for this (a piped command) to work, create a separate script and call this script from cron.

jlinkels
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cron job to backup prudens Linux - Newbie 16 08-10-2009 07:04 AM
Standard output redirection doesn't work correctly with cron job The Pearls Master Linux - Software 1 07-22-2009 08:03 AM
Issues while executing shell scripts through Cron job paragkalra Programming 8 08-02-2008 01:18 PM
How to improve my mysql backup cron job stardotstar Programming 8 05-25-2006 06:11 AM
cron job - backup medamnit Linux - Newbie 4 05-24-2002 03:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 02:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration