phpMySQLAutoBackup - automate the backup of your MySQL databases and email a copy to yourself

phpMySQLAutoBackup

is FREE to use - its released under GPL License

Please consider making a donation, even a single Dollar (or a Pound) would be great!

This ain't a big organisation - its just me.

phpMySQLAutoBackup
the simple way to backup MySQL databases. Automates the backup of MySQL databases.
The PHP scripts export your database (data and structures), compresses it into gzip format and emails it to you.

Note will now only run once per hour by default; when testing please see "debugging" section
in the run.php file to ensure the backup will run more than just once per hour for testing purposes.

To upgrade an existing installation:

  1. BACKUP your original files. 
  2. Follow the install details below (note: you can use your original run.php file, but need to add the new variables detailed below to benefit from the new features).
    You can use the details within your existing /phpMySQLAutoBackup/run.php file to complete section 2 below.

To install:

  1. Unzip the files and upload to your server.

    You should upload the files and folders retaining the original names 

  2. To configure your installation, add your details to the following variables within file /phpMySQLAutoBackup/run.php:
    1. $db_server
      "localhost" is normally fine - if not then please contract your web host
    2. $db
      set to your MySQL database name
    3. $mysql_username
      set to your MySQL username
    4. $mysql_password
      set to your MySQL password
    5. $to_emailaddress
      set to your email address to send backup files to (leave blank to not send emails)
    6. $from_emailaddress
      set to a different email address than above - else some spam detectors will bin the email
    7. $save_backup_zip_file_to_server
      If you set the variable $save_backup_zip_file_to_server to 1 then the backup files will be saved in the folder: /phpmysqlautobackup/backups/
          (ensure you chmod [777] the backups folder for write access to allow for file creation)
    8. $time_internal - interval between backups - stops malicious attempts at bringing down your server by making multiple requests to run the backup. By default this is set to one hour (3600 seconds), will only allow the backup to run once each hour. You could reduce to 30 seconds when testing so you do not have to wait an hour! Do remember to put this backup to at least 3600 when testing is completed.
    9. $table_select - leave commented out if you need to backup the whole database.
      If you uncomment the variable $table_select then only the specified named tables will be selected for backup.  The table names must be correct else the backup will not select any tables.

      The correct format is:
      $table_select[0]="MyFirstTableName";
      $table_select[1]="MySecondTableName";
      $table_select[2]="MyThirdTableName";
      $table_select[x]="MylastTableName";

      You can add any number of table names.

      If you specify distinct tables names, as above, then ONLY those tables will be included in your backup.

      For a list of table names to backup for popular applications including phpBB and phpAMA see:
      http://www.dwalker.co.uk/forum/viewtopic.php?t=491

    10. $table_exclude - leave commented out if you need to backup the whole database.
      If you uncomment the variable $table_exclude then the specified named tables will be excluded from the backup.

      The correct format is:
      $table_exclude[0]="FirstTableName";
      $table_exclude[1]="SecondTableName";
      $table_exclude[2]="ThirdTableName";
      $table_exclude[x]="lastTableName";

      You can add any number of table names.

      Should not be used in conjunction with $table_select.

    11. $limit_from
      record number to start from, use this if you have a large table to backup.  Should be used with a single table setting like:
                   $table_select[0]="MyFirstTableName";
    12. $limit_to
      total rows to export

      The two variables above are used in the SQL query:
         SELECT * FROM tablename LIMIT $limit_from , $limit_to
      These variables have been added to allow for the backup of just a section of a very large table with millions of records.
    13. $newline
      fix for email attachment issue (backup file included within email body). If your backup emails arrive in your mailbox with no attachment but loads of strange characters within the body of the email try setting $newline to: "\n"

    14. FTP - push the backup file to a remote server. PHP CURL is required and ensure the local and remote backups folders are writeable.

      The correct format is:
      $ftp_username="your-ftp-username";
      $ftp_password="yoursecure-pass";
      $ftp_server="ftp.your--domain.com";
      $ftp_path="/public_html/secure-folder/";

      The remote folder you are uploading to should be secure. Ensure your backups are not uploaded to a folder open for public access.

    15. Debugging - uncomment the lines: 
      error_reporting(E_ALL);
      $time_internal=2;
      This will then display any errors and allow the backup to run with only a 2 second wait limit.  Do remember to comment out these lines once you have the application working.

    TIP:  If you need to backup several different databases or tables at different backup times you can copy the run.php file, and rename it appropriately.

  3. To run the backup:

    Enter in your address bar the url:

    http://www.[Your--domain].com/phpmysqlautobackup/run.php
      (runs silently [no output], unless there are errors, OHhh no.)

    If you have entered the above details correctly this will export your database, compress it into gzip format and email it to you.

    When run correctly for the first time it will create a new table within your database called: phpmysqlautobackup, which contains a single record to monitor the last time it was run (used to stop abuse).

    To schedule it to run hourly/daily/monthly add the above url to a cron job or use the excellent phpJobScheduler

Common errors or issues:

If you experience problems then the most common error is the script timing-out; usually error messages are:

Fatal error: Maximum execution time of 50 seconds exceeded in, or
Fatal error: allowed memory size of bytes exhausted (tried to allocate bytes), or
Internal Server Error, this is an error with your script, or other similar message

Then you need to either:

I do hope you find it useful, and if you use it let me know  ;-)

And if you are feeling generous then you might even consider giving a tiny donation, any small amount helps keep the wheels turning.

 

My other applications:

Create your own members area:
phpAMA - create a members area using PHP MySQL, protect your members only or adult content
phpAutoMembersArea
Run cron jobs with ease schedule PHP scripts to
run: 1-59 minutes, hourly, daily or weekly,
and log the output
phpJobScheduler - scheduling PHP scripts to run at set intervals your replacement for cron jobs. 
phpJobScheduler