/    Sign up×
Community /Pin to ProfileBookmark

MySQL backup script suddenly stopped working?

This script has been working fine and last time it was run was 29/12/2008

I came to run it today and nothing, no errors says it ran fine but the database wasnt being updated and file wasnt being created.

I have a feeling it is something to do with the year change over but not totally sure

Any help would be great

[code=php]<?php

$server = “localhost”;
$user = “root”;
$pass = “root”;
$db = “test”;

mysql_connect($server, $user, $pass)
or die(mysql_error());

mysql_select_db($db)
or die(mysql_error());

$result = mysql_query(“SELECT * FROM backup WHERE backup_id = 1”)
or die(mysql_error());

$row = mysql_fetch_array($result);

$atoms = explode(‘-‘,$row[‘backup_last’]);
$year = $atoms[0];
$month = $atoms[1];
$atoms2 = explode(‘ ‘,$atoms[2]);
$day = $atoms2[0];
$db_amount = $row[‘times_backedup’];

$today = date(“m-d-Y”, mktime(date(“m”), date(“d”), date(“Y”)));
$date_to_compar = date(“m-d-Y”, mktime(0, 0, 0, $month, $day, $year));

if($today > $date_to_compar)
{

$day = (date(“dmY”));
$filename=”backup/data/$day.sql”;

if (file_exists($filename))
{

unlink(“$filename”);

}

system(“C:wampbinmysqlmysql5.1.30binmysqldump –opt –no-create-db –user=$user –password=$pass –host=$server $db > $filename”);

$db_amountupdated = $db_amount + 1;

mysql_query(“UPDATE backup SET times_backedup = $db_amountupdated WHERE backup_id = 1”)
or die(mysql_error());

echo $filename;

}

?>[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@ratcatemeJan 11.2009 — shouldn't this line
[code=php]$today = date("m-d-Y", mktime(date("m"), date("d"), date("Y"))); [/code]
look more like
[code=php]$today = date("m-d-Y", mktime(0, 0, 0, date("m"), date("d"), date("Y")));[/code]
and should properly just look like this
[code=php]$today = date("m-d-Y");[/code]

Scott.
Copy linkTweet thisAlerts:
@Chris_CrewauthorJan 12.2009 — Thanks for that worked a treat

Weird how it worked for 2 months then just stopped, well at least it works again
×

Success!

Help @Chris_Crew spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...