954,604 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Setting up a Cron Job from cPanel for Database backup with php script

I want a PHP cron script to be set up with cPanel cron jobs that would take backup of MySQL database.

Regards,

tejasluvs
Newbie Poster
18 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 

Is there a specific reason you want to do it with PHP ? If you use a shell script it can be as small as this:

#!/bin/sh
DATE=`/bin/date +"%G%m%d"` ;
mysqldump --host=localhost --user=YOURUSER --password=YOURPASSWORD --all-databases --single-transaction --quick | gzip > ./YOURFILEPATH/backup-$DATE.sql.gz ;
pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

Is there a specific reason you want to do it with PHP ? If you use a shell script it can be as small as this:

#!/bin/sh
DATE=`/bin/date +"%G%m%d"` ;
mysqldump --host=localhost --user=YOURUSER --password=YOURPASSWORD --all-databases --single-transaction --quick | gzip > ./YOURFILEPATH/backup-$DATE.sql.gz ;

Can you please guide me how to get the shell script do the job for me? I have not used shell scripts before.

tejasluvs
Newbie Poster
18 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 

You can save these 3 lines as 'backup.sh' and use it when setting up your cron job. For help on setting up your cronjob, see the cpanel documentation.

pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 
You can save these 3 lines as 'backup.sh' and use it when setting up your cron job. For help on setting up your cronjob, see the cpanel documentation.

Thanks for the hint and guidance.

tejasluvs
Newbie Poster
18 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 
Thanks for the hint and guidance.

Thanks,

The command works for me. Could you please help me little bit more? what will be the parameter for backing up a single or multiple table?

tejasluvs
Newbie Poster
18 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 
pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 
You can find all parameters here: http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html

I have referred to the document above but not able to provide the options correctly. Could you please place the options in your given command?

tejasluvs
Newbie Poster
18 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 

The first example on the page ...

mysqldump --host=localhost --user=YOURUSER --password=YOURPASSWORD YOURDATABASE YOURTABLE
pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

The first example on the page ...

mysqldump --host=localhost --user=YOURUSER --password=YOURPASSWORD YOURDATABASE YOURTABLE

Thanks, I really appreciate your efforts to help me out.

tejasluvs
Newbie Poster
18 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: