• 0

[MYSQL + CRON JOB] Backup MYSQL Database with cron job


Question

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

3 answers to this question

Recommended Posts

  • 0
  On 12/03/2010 at 00:42, Hot said:

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?

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.