phpMySQLAutoBackup  1.6.1
Open source - automates the backup of your MySQL database
 All Data Structures Files Functions Variables
phpmysqlautobackup.php
Go to the documentation of this file.
1 <?php
2 /*******************************************************************************************
3  phpMySQLAutoBackup - Author: http://www.DWalker.co.uk - released under GPL License
4  For support and help please try the forum at: http://www.dwalker.co.uk/forum/
5 ********************************************************************************************
6 Version Date Comment
7 0.2.0 7th July 2005 GPL release
8 0.3.0 June 2006 Upgrade - added ability to backup separate tables
9 0.4.0 Dec 2006 removed bugs/improved code
10 1.4.0 Dec 2007 improved faster version
11 1.5.0 Dec 2008 improved and added FTP backup to remote site
12 1.5.4 Nov 2009 version added to xmail
13 1.5.5 Feb 2011 more options for config added - email reports only and/or backup, save backup file to local and/or remote server.
14  Reporter added: email report of last 6 (or more) backup stats (date, total bytes exported, total lines exported) plus any errors
15  MySQL error reporting added and Automated version checker added
16 1.6.0 Dec 2011 PDO version
17 ********************************************************************************************/
19 // ---------------------------------------------------------
20 if(($db=="")OR($mysql_username=="")OR($mysql_password==""))
21 {
22  echo "Configure your installation BEFORE running, add your details to the file /phpmysqlautobackup/run.php";
23  exit;
24 }
25 
26 $backup_type="\n\n BACKUP Type: Full database backup (all tables included)\n\n";
27 if (isset($table_select))
28 {
29  $backup_type="\n\n BACKUP Type: partial, includes tables:\n";
30  foreach ($table_select as $key => $value) $backup_type.= " $value;\n";
31 }
32 if (isset($table_exclude))
33 {
34  $backup_type="\n\n BACKUP Type: partial, EXCLUDES tables:\n";
35  foreach ($table_exclude as $key => $value) $backup_type.= " $value;\n";
36 }
39 include(LOCATION."phpmysqlautobackup_extras.php");
40 include(LOCATION."schema_for_export.php");
43 $backup_info.="\n".$version_info."\n\n";
44 
46 
47 // zip the backup and email it
48 $backup_file_name = 'mysql_'.$db.strftime("_%d_%b_%Y_time_%H_%M_%S.sql",time()).'.gz';
49 $dump_buffer = gzencode($buffer);
50 
52 
53 //FTP backup file to remote server
54 if (isset($ftp_username))
55 {
56  //write the backup file to local server ready for transfer if not already done so
58  $transfer_backup = new transfer_backup();
59  $errors.= $transfer_backup->transfer_data($ftp_username,$ftp_password,$ftp_server,$ftp_path,$backup_file_name);
61 }
62 
63 if(!session_id()) session_start();
64 if(isset($_SESSION['pmab_mysql_errors'])) $errors.=$_SESSION['pmab_mysql_errors'];
65 
68 {
69  $msg_email_backup="";
70  $msg_ftp_backup="";
71  $msg_local_backup="";
72  if ($send_email_backup) $msg_email_backup="\nthe email with the backup attached has been sent to: $to_emailaddress \n";
73  if (isset($ftp_username)) $msg_ftp_backup="\nthe backup zip file has been transferred via ftp to: $ftp_server (user: $ftp_username) - folder: $ftp_path \n";
74  if ($save_backup_zip_file_to_server) $msg_local_backup="\nthe backup zip file has been saved to the same server: ".dirname(__FILE__)."/backups/ \n";
75  if ($errors=="") $errors="None logged!";
77  "REPORT on recent backup using phpMySQLAutoBackup ($backup_file_name)",
78  "SAVE or DELETE THIS MESSAGE - no backup is attached $msg_email_backup $msg_ftp_backup $msg_local_backup \nERRORS: $errors \n$backup_info \n phpMySQLAutoBackup (version $phpMySQLAutoBackup_version) is developed by http://www.dwalker.co.uk/ \nPlease consider making a donation at:\n http://www.dwalker.co.uk/make_a_donation.php \n(every penny or cent helps)",
79  "From: $from_emailaddress\nReply-To:$from_emailaddress");
80 }
81 
82 if (DEBUG) echo '<textarea cols=150 rows=50>'.$backup_info."\n\nERRORS: ".$errors.'</textarea>';
83 ?>