LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-14-2008, 04:39 AM   #1
nawuza
Member
 
Registered: Jan 2007
Location: High Castle
Distribution: FC8
Posts: 66

Rep: Reputation: 15
Unhappy mysqldump crontab


i am running a script to back up my mysql database using crontab.
this is how i assign the the cronjob.The script is in the root directory.

01 * * * * /root/test.sh

the script is

Code:
#!/bin/sh

date=`date +%Y-%m-%d_%Hh%M`

mysqldump -u root -ppassword my_database > $date.sql
although the .sql file is generated using the cronjob, the .sql file empty.i have checked everything.if i manually run it,it worked fine & the .sql file filled with information on the database.

can anyone help me with this.ASAP
 
Old 07-14-2008, 04:41 AM   #2
emi_ramo
Member
 
Registered: Apr 2007
Location: Barcelona, Spain
Distribution: Debian, KUbuntu
Posts: 213

Rep: Reputation: 36
Try changing

Code:
#!/bin/sh
to

Code:
#!/bin/bash
 
Old 07-14-2008, 10:48 AM   #3
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 235Reputation: 235Reputation: 235
Quote:
Originally Posted by emi_ramo View Post
Try changing

Code:
#!/bin/sh
to

Code:
#!/bin/bash
/bin/sh is usually linked to /bin/bash and shouldn't make a difference. It's most likely a permissions issue writing to the specified directory. Make sure cron isn't running as a different user or the directory it is writing to has the proper access.
 
Old 07-14-2008, 11:43 AM   #4
emi_ramo
Member
 
Registered: Apr 2007
Location: Barcelona, Spain
Distribution: Debian, KUbuntu
Posts: 213

Rep: Reputation: 36
What about ubuntu?

Code:
$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 2008-06-03 22:38 /bin/sh -> dash
 
Old 07-14-2008, 11:46 AM   #5
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 235Reputation: 235Reputation: 235
Quote:
Originally Posted by emi_ramo View Post
What about ubuntu?

Code:
$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 2008-06-03 22:38 /bin/sh -> dash
Well, unless the OP specified Ubuntu, I wouldn't assume such things. Also they mentioned it worked when run manually, so that tells me it's not the actual issue.
 
Old 07-14-2008, 09:54 PM   #6
nawuza
Member
 
Registered: Jan 2007
Location: High Castle
Distribution: FC8
Posts: 66

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by trickykid View Post
/bin/sh is usually linked to /bin/bash and shouldn't make a difference. It's most likely a permissions issue writing to the specified directory. Make sure cron isn't running as a different user or the directory it is writing to has the proper access.
emm..i think you are right trickykid..thanks..maybe i should try other than mysqldump to backup the mysql.
 
Old 07-14-2008, 11:41 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,406

Rep: Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396
cron has a minimal env, so the path to the mysqldump cmd is not usually present. Always specify the full path to all cmds (unless shell built-in), and also to output files.
Ditto, don't assume where bin/sh points to, always specify the actual shell you want.
 
Old 07-15-2008, 07:05 AM   #8
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 235Reputation: 235Reputation: 235
Quote:
Originally Posted by nawuza View Post
emm..i think you are right trickykid..thanks..maybe i should try other than mysqldump to backup the mysql.
It's either a permissions issue or path to the mysqldump commnand like mentioned before this post. mysqldump is probably the best method to backing up your database. You can take a flat file cold backup of the /var/lib/mysql files but the only way to ensure it's fully intact is if you shutdown mysql, take the backup, turn mysql back on.

You can also look into using MySQL-ZRM from the zmanda.com guys. Good product to manage backups of mysql databases.
 
Old 07-17-2008, 08:55 PM   #9
nawuza
Member
 
Registered: Jan 2007
Location: High Castle
Distribution: FC8
Posts: 66

Original Poster
Rep: Reputation: 15
if its a permission issue, how do i get it running?!does it required the root to login in the script or something else?
 
Old 07-17-2008, 09:49 PM   #10
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 235Reputation: 235Reputation: 235
Well, you don't specify in the script where you are dumping the mysqldump. You might want to actually specify it. cron jobs might run as a cron user or the like, if it's kicking off a script that doesn't specify a location but where the script resides, it's probably trying to write to no location. Specify a location in the script.

Example:

Code:
#!/bin/sh

date=`date +%Y-%m-%d_%Hh%M`

mysqldump -u root -ppassword my_database > /path/to/dump/dir/$date.sql
 
Old 07-17-2008, 10:51 PM   #11
nawuza
Member
 
Registered: Jan 2007
Location: High Castle
Distribution: FC8
Posts: 66

Original Poster
Rep: Reputation: 15
the script is in the root dir.what are things that i need to do so that the script can run in any enviroment.or should i move the script away from the root dir.
 
Old 07-18-2008, 03:18 AM   #12
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,406

Rep: Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396
Either create a dedicated 'backup' user acct, and put it in there, or put it somewhere in the mysql owner's acct dir.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Timestamping/Emailing a mysqldump crontab staypuftman Linux - Server 3 10-27-2007 12:24 PM
MySqlDump Issue?? rajnair0278 Linux - Software 17 06-09-2006 04:46 AM
about mysqldump javier_ccs Programming 3 08-08-2005 06:13 PM
restore using mysqldump sporkit Linux - Networking 2 05-26-2004 05:34 PM
mysqldump - backup *.* bpk Linux - Newbie 1 03-29-2004 04:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:13 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration