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

Regards,

Recommended Answers

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 ;
Jump to Post

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.

Jump to Post

All 9 Replies

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 ;

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.

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.

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.

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?

The first example on the page ...

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.