mikeaag Posted March 12, 2010 Share Posted March 12, 2010 Hey all, Wondering if someone can help me. I need to setup a cron job that backs up a mysql database, but im not too familiar with cron jobs. The code i have at the moment is: 0 0 * * 0 home/usr/toystoys.co.uk/htdocs/crons/database_backup.php > home/usr/toystoys.co.uk/dblog/dbbackup.log and the php file is: <?php $host = "localhost"; $username = "root"; $password = ""; $database = "database"; mysql_connect($host, $username, $password); mysql_select_db($database); $query = "SELECT * INTO OUTFILE 'path/to/backup/file.sql' FROM TABLENAME"; $result = mysql_query($query); mysql_close(); ?> Im pretty sure the PHP code will work fine, its more the Cron job im worried about. I need it to run every week, at midnight on sunday, and i want it to output its results to a log file as well. Can anyone tell me if this will work before i test it on the server, as its not my server and i dont want to break it :D Thanks in advance Link to comment Share on other sites More sharing options...
0 Hot Posted March 12, 2010 Share Posted March 12, 2010 At a glance, all I see wrong with the Cron job is that your paths should start with /home, not just home. You could also replace 0 0 * * 0 with @weekly. Link to comment Share on other sites More sharing options...
0 mikeaag Posted March 12, 2010 Author Share Posted March 12, 2010 At a glance, all I see wrong with the Cron job is that your paths should start with /home, not just home. You could also replace 0 0 * * 0 with @weekly. is the default time for @weekly sunday at midnight then? Link to comment Share on other sites More sharing options...
0 Hot Posted March 12, 2010 Share Posted March 12, 2010 is the default time for @weekly sunday at midnight then? Yes mate. Link to comment Share on other sites More sharing options...
Question
mikeaag
Hey all,
Wondering if someone can help me.
I need to setup a cron job that backs up a mysql database, but im not too familiar with cron jobs.
The code i have at the moment is:
and the php file is:
Im pretty sure the PHP code will work fine, its more the Cron job im worried about.
I need it to run every week, at midnight on sunday, and i want it to output its results to a log file as well.
Can anyone tell me if this will work before i test it on the server, as its not my server and i dont want to break it :D
Thanks in advance
Link to comment
Share on other sites
3 answers to this question
Recommended Posts