phpMySQLAutoBackup  1.6.1
Open source - automates the backup of your MySQL database
 All Data Structures Files Functions Variables
run.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.5 Feb 2011 more options for config added - email reports only and/or backup, save backup file to local and/or remote server.
13  Reporter added: email report of last 6 (or more) backup stats (date, total bytes exported, total lines exported) plus any errors
14  MySQL error reporting added and Automated version checker added
15 1.6.0 Dec 2011 PDO version
16 1.6.1 April 2012 - CURLOPT_TRANSFERTEXT turned off (to stop garbaging zip file on transfer) and bug removed from write_back
17 ********************************************************************************************/
19 // ---------------------------------------------------------
20 // you must add your details below:
21 $db_server = "localhost"; // your MySQL server - localhost will normally suffice
22 $db = ""; // your MySQL database name
23 $mysql_username = ""; // your MySQL username
24 $mysql_password = ""; // your MySQL password
25 
26 $from_emailaddress = "";// your email address to show who the email is from (should be different $to_emailaddress)
27 $report_emailaddress = "";//address to send reports, not the backup just details on last backups (can be same as above)
28 $to_emailaddress = ""; // your email address to send backup files to
29  //best to specify an email address on a different server than the MySQL db ;-)
30 
31 $send_email_backup=1;//set to 1 and will send the backup file attached to the email address above
32 $send_email_report=1;//set to 1 and will send an email report to the email address above
33 
34 define('LOG_REPORTS_MAX', 6);//the total number of reports to retain - set this to any number you wish (better to keep below 50 as all reports are included in the email)
35 
36 //interval between backups - stops malicious attempts at bringing down your server by making multiple requests to run the backup
37 $time_interval=3600;// 3600 = one hour - only allow the backup to run once each hour
38 
39 //DEBUGGING
40 define('DEBUG', 1);//set to 0 when done testing
41 
42 //FTP settings - uses CURL so your webhost where you run this must support PHP CURL
43 //when the 4 lines below are uncommented will attempt to push the compressed backup file to the remote site ($ftp_server)
44 //$ftp_username=""; // your ftp username
45 //$ftp_password=""; // your ftp password
46 //$ftp_server=""; // eg. ftp.yourdomainname.com
47 //$ftp_path="/public_html/"; // can be just "/" or "/public_html/securefoldername/"
48 
49 
50 $save_backup_zip_file_to_server = 1; // if set to 1 then the backup files will be saved in the folder: /phpMySQLAutoBackup/backups/
51  //(you must also chmod this folder for write access to allow for file creation)
52 define('TOTAL_BACKUP_FILES_TO_RETAIN',10);//the total number of backups files to retain, e.g. 10. the 10 most recent files mtime (modified date) are kept, older versions are deleted
53 
54 /****************************************************************************************
55 The settings below are for the more the more advanced user - in the majority of cases no changes will be required below. */
56 
57 $newline="\n"; //email attachment - if backup file is included within email body then change this to "\r\n"
58 
59 // Below you can uncomment the variables to specify separate tables to backup,
60 // leave commented out and ALL tables will be included in the backup.
61 //$table_select[0]="MyFirstTableName";
62 //$table_select[1]="mySecondTableName";
63 //$table_select[2]="myThirdTableName";
64 //note: when you uncomment $table_select only the named tables will be backed up.
65 
66 // Below you can uncomment the variables to specify separate tables to EXCLUDE from the TOTAL backup,
67 // leave commented out and ALL tables will be included in the backup.
68 //$table_exclude[0]="FirstTableName-to-exclude";
69 //$table_exclude[1]="SecondTableName-to-exclude";
70 //$table_exclude[2]="ThirdTableName-to-exclude";
71 //note: when you uncomment $table_exclude these tables will be excluded from your backup.
72 
73 $limit_to=10000000; //total rows to export - IF YOU ARE NOT SURE LEAVE AS IS
74 $limit_from=0; //record number to start from - IF YOU ARE NOT SURE LEAVE AS IS
75 //the above variables are used in this formnat:
76 // SELECT * FROM tablename LIMIT $limit_from , $limit_to
77 
78 
79 define('DBDRIVER', 'mysql');
80 define('DBPORT', '3306');
81 // No more changes required below here
82 // ---------------------------------------------------------
83 define('DBHOST', $db_server);
84 define('DBUSER', $mysql_username);
85 define('DBPASS', $mysql_password);
86 define('DBNAME', $db);
87 
88 // Turn off all error reporting unless debugging
89 if (DEBUG)
90 {
91  error_reporting(E_ALL);
92  $time_interval=1;// seconds - only allow backup to run once each x seconds
93 }
94 else error_reporting(0);
95 
96 define('LOCATION', dirname(__FILE__) ."/files/");
97 include(LOCATION."phpmysqlautobackup.php");
98 ?>