• 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.
  • Posts

    • The best thing would be to just allow more options to let users pick the layout they like, it doesn't matter at this point really and it's not that hard to do as evidenced but all the 3rd party menus/tools that let you change it in lots of different ways. If you give the users more options they'll be happy, take them away and you have a problem.
    • They could've done that the very next day or from the start but when Win11 came out, the MSN team was still rooted in the OS division and pushing for it's hooks into everything. That's why we have recommended and all the MSN feed stuff in the widget panel which you also couldn't turn off at the start. Now that they've been pushed out, last I checked, all this MSN/web feed junk is finally getting the option to be turned off. tl/dr, it's not about coding ability, it's just dumb business decisions.
    • The headline doesn't fit the article. Sure the headline is more enticing probably, but come on, man. Keep it real, if you can help it.
    • The console sales don't mean much like they used to. Sony tells you this themselves but you seem to miss it. They care more about MAUs and how many people they can milk each month than x number of consoles sold, often to the more casual COD, Madden or FiFA gamers who play little else. Sony can't seem to port their games to the PC fast enough because they're not getting enough out of that 75 million console sales it seems. The traditional home console market has stagnated already, everyone knows it.
    • That is fair, I meant the comment somewhat whimsically and as such was a bit careless with the facts. Had I said either 2 or 4 that would be more defensible. SpaceX's Starship crashed 2 times during hop tests and 2 additional hop-test failures that while not exactly a "crash," still resulted in the total destruction of the test vehicle. Even in that example, it would still be fair for you to point out that Starship is a significantly more complex test vehicle and that SpaceX never crashed a simple rocket hop-test like this one. I already admitted that I could have been clearer, but I also don't think it unreasonable to use the word "it" when referring to the subject of the article I am commenting on. I feel like it is an outlying read of my words to assume "it" meant SpaceX's total success. Like I said, I accept responsibility for the ambiguity.
  • Recent Achievements

    • Week One Done
      slackerzz earned a badge
      Week One Done
    • Week One Done
      vivetool earned a badge
      Week One Done
    • Reacting Well
      pnajbar earned a badge
      Reacting Well
    • Week One Done
      TBithoney earned a badge
      Week One Done
    • First Post
      xuxlix earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      681
    2. 2
      ATLien_0
      285
    3. 3
      Michael Scrip
      225
    4. 4
      +FloatingFatMan
      197
    5. 5
      Steven P.
      136
  • Tell a friend

    Love Neowin? Tell a friend!