<?php
// +------------------------------------------------------------------+
// | M-Solutions.co.in MySQL Backup Utility,
// | Copyright (c) 2005-2007 M-Solutions
// | You are free to use and edit this code as you wish,
// | This script can be used freely as long as all copyright messages are intact.
// +------------------------------------------------------------------+
// +------------------------------------------------------------------+
// | Usage :
// | 1. Fill in the dbuser, dbname, and dbpwd fields below.
// | 2. set up a cron job to call this file.
// | this will create a backup of the db, in an .sql file, which can be restored via phpmyadmin.
// |
// | you can test it via http://www.domain.com/[folder]/cron_backupdb.php?verbose=1
// |
// | Referrences :http://www.interspire.com/content/articles/5/1/An-Introduction-to-Cron
// +------------------------------------------------------------------+
$dbuser = 'root';
$dbpwd = '';
$dbname = '';
$dbhost = 'localhost';
$dbprefix = '';
if(!$mycon = @mysql_connect($dbhost,$dbuser,$dbpwd)) die('Database Error: '.mysql_error());
elseif(!@mysql_select_db($dbname,$mycon)) die ('Database Error: '.mysql_error());
mysql_query("SET NAMES TIS620");
error_reporting(E_ALL & ~E_NOTICE);
$verbose = !empty($_REQUEST['verbose']) ? 1 : 0;
@set_time_limit(600); // try to give ourselves plenty of time to run
if (!$handle = fopen($filename, 'w+')) {
die("Failed to open stream : ".$filename);
}
if (!fwrite($handle,$filedata)){
die("Fail - Not able to right to file : ".$filename);
}
fclose($handle);
exit();
}
function backup_table($table,$endit=0)
{
global $dbname, $verbose;
$sql = mysql_query("SELECT * FROM $table") or die(mysql_error());