The source of mysql_backup.php (click to demo the file) viewed 503 times.

If I wrote this code, then it is licensed under the GPL. If someone else wrote it, then please ask them if you want to use the code.


<?php
//////////////////////////////////////////////////////
//           Con MySQL Database Backup v1.0         //
//            By sebflipper Copyright 2005          //
//             http://www.sebflipper.com/            //
//                                                  //
//     This script backs up a list of databases     //
//     or all databases can be used as a ConJob     //
//                                                  //
//   WinRAR required for viewing file on Windows    //
//                                                  //
//     You can read the dump file back into the     //
//                 server like this:                //
//      shell> mysql db_name < backup-file.sql      //
//                                                  //
//////////////////////////////////////////////////////

// Config Area
// MySQL connection details
$settings[server] = 'localhost';
$settings[db_user] = '';
$settings[db_pass] = '';

// Remove existing bz2 files in the folder? (Unix/Linux only)
$settings[remove_existing] = true// true or false

// Enter a list of MySQL databases you want to backup
// Usage:
// $settings[dbs] = "all";
// $settings[dbs] = array("database1", "database2");
$settings[dbs] = "all";

// You don't need to edit anything else below this line

// Connect to database
$db mysql_connect($settings[server], $settings[db_user], $settings[db_pass]) or die("Unable to connect to database on '".$settings[server]."' with user '".$settings[db_user]."'<br />"."Please check your settings in this file");

// Get todays date
$date date("dmY_Hi");

// Remove existing backups
if ($settings[remove_existing] == true)
{
    
exec("rm *.bz2");
}

// Backup all or specified databases
if ($settings[dbs] == "all")
{
    
// Backup all databases
    
echo "Backing up: <b>All Databases</b>...<br>";
    
exec("mysqldump --opt --host=\"".$settings[server]."\" --user=\"".$settings[db_user]."\" --password=\"".$settings[db_pass]."\" --all-databases | bzip2 -c > full_backup_".$date.".sql.bz2");    
}
else
{
    
// Start database loop
    
foreach ($settings[dbs] as $database)
    {
        
// Change database
        
mysql_select_db($database,$db) or die("'".$database."' database does not exist"); ;
        echo 
"Backing up: <b>".$database."</b>...<br>";
                
        
// Backup database
        
exec("mysqldump --opt --host=\"".$settings[server]."\" --user=\"".$settings[db_user]."\" --password=\"".$settings[db_pass]."\" $database | bzip2 -c > ".$database."_backup_".$date.".sql.bz2");
    }
}

// Completed
echo "<br>MySQL Database Backup Complete";
?>

If you want to have a look at the source code, chose a file from this list:

ip.txt
(Demo Script)
userdetails.php
(Demo Script)
perl_smtp_email.php
(Demo Script)
server_mon.php
(Demo Script)
floor_time.php
(Demo Script)
url_verify.php
(Demo Script)
birthday.php
(Demo Script)
md5_password.php
(Demo Script)
email.php
(Demo Script)
char_limit.php
(Demo Script)
time.php
(Demo Script)
htpasswd_maker.php
(Demo Script)
title_case.php
(Demo Script)
password.php
(Demo Script)
phpself.php
(Demo Script)
smarty.php
(Demo Script)
phpinfo.php
(Demo Script)
ip_monitor.php
(Demo Script)
html.php
(Demo Script)
pad_test.php
(Demo Script)
mysql_backup.php
(Demo Script)
cookies.php
(Demo Script)
unix_time.php
(Demo Script)
convert_link.php
(Demo Script)

To colour code your own PHP paste it here: