Jump to content


Backup Script Problem..


2 replies to this topic

#1 Braunson

    Young Padawan

  • Members
  • Pip
  • 237 posts
  • Gender:Male
  • Location:Ontario, Canada

Posted 15 July 2007 - 10:04 AM

Hello all,

I have found this backup script for mysql databases, now I run it, everything is successfull and the file is added to the spicific folder, but nothing is in it, its 0kb's whys that? Any reason? I have tryed many different backup scripts but still none work.

<?php
 //================================================
 // Auto backup your databases
 //================================================
 
 $backup_dir = dirname( __FILE__ ) . '/backups/';

 $u = 'xxx';
 $p = 'xxx';
 $db = 'xxx';//This is just the name of a database just to make the query work. The script will backup all the databases that your use has access to.
 
 $db_link = mysql_connect($h,$u,$p);
 $res = mysql_db_query($db, 'SHOW DATABASES', $db_link) or die('Could not connect: ' . mysql_error());
 echo 'Found '. mysql_num_rows($res) . ' databases' . "\n";
 
 while ( $rec = mysql_fetch_array($res) )
 {
  //Parse time :
  $time = microtime();
  $time = explode(' ', $time);
  $time = $time[1] + $time[0];
  $start = $time;
  
  echo $rec[0] . "\n";
  shell_exec( 'mysqldump --default-character-set=greek --result-file='.$backup_dir.$rec[0].'.'.date('Y-m-d').'.sql --password='.$p.' '.$rec[0] );
  //Parse time :
  $time = microtime();
  $time = explode(' ', $time);
  $time = $time[1] + $time[0];
  $finish = $time;
  $total_time = round(($finish - $start), 6);
  echo 'Parsed in ' . $total_time . ' secs' . "\nStarting with compression\n";
 }
 //Let's tar those backups :
 shell_exec( 'tar cvf '.$backup_dir.date('Y-m-d').'.tar '.$backup_dir.'*.sql' );
?>

Any help is appreciated :P

Edited by Braunson, 15 July 2007 - 11:18 AM.


#2 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 15 July 2007 - 01:13 PM

Does your host enable the use of shell commands? That's about the only thing I would see questionable with that code.

I personally just wrote myself a manual MySQL dump using just a few queries instead of using shell commands, as I find it to be more secure, and a bit cross-compatible.

PM me if you'd like the function (its part of a class, so I may have to re-write part of it for you).


Edit:
Try using mysql_fetch_row() instead of mysql_fetch_array(), as it may be retrieving the result as an associative array. I'm not too familiar with it as I've found instances where it does and doesn't, even without using flags... worth a try, lol.

Edited by Demonslay, 15 July 2007 - 01:15 PM.


#3 Braunson

    Young Padawan

  • Members
  • Pip
  • 237 posts
  • Gender:Male
  • Location:Ontario, Canada

Posted 15 July 2007 - 02:44 PM

Alright thank you. Pm'd.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users