I run this as a cront job, do a search for crontab to learn about it
This dumps the databases into SQL files into the a sub directory called "sql" You will have to create this directory first. It should be in the same directory as your database backup php file.
This is what my cronjob looks like. It does it once a day.
15 1 * /usr/home/savvi/usr/local/etc/httpd/cgi-bin/php /usr/home/savvi/dbbackup.php SECRETPASSWORD
Also you could modify this script to keep unique backups by appending the date to the filename
<?
/*Make sure we are running this from the command line*/
if ($argv[1]!="SECRETPASSWORD")
{
echo "access denied";
exit(1);
}
function query($sql)
{
global $db;
$result = mysql_query($sql,$db);
return $result;
}
function Query_Count($rs_query)
{
return mysql_num_rows($rs_query);
}
$db = mysql_connect("localhost", "USER","PASSWORD");
$RS=Query("Show databases;");
$x=Query_Count($RS);
for ($i=0;$i<$x;$i++)
{
$str="mysqldump -u USER --password=\"MYPASSWORD\" ".mysql_result($RS,$i,0)." > sql/".mysql_result($RS,$i,0).".sql";
`$str`;
}
?>