Backing up MySQL Databases made easy with PHP

In this tutorial, we use PHP as a scripting language to backup a number of MySQL databases so the files can either be downloaded over the web, or are automatically sent to a remote server by FTP. We then create a script which automatically restored the files again, with a minimum of manual intervention.

The system is ideal if you host your own clients, and makes it easy to make sure that all the information in your databases is regularly backed up. The system can be extended further by creating a nice web interface to the backup system, and access can be given to your clients so they can backup their own databases allowing you to offer them a better service.

$2.89
- OR -

Overview

Table of Content:

  • Backing up MySQL Databases made easy with PHP
  • PHP as a Scripting Language
    • Where is the CLI PHP Version?
    • How do I know If I'm running the CLI Version of PHP?
      • Windows
      • Linux
    • Do I have to use the CLI Version of PHP?
  • Backing up a MySQL Database
    • Running the mysqldump command through PHP
    • File Permissions
  • Building the Backup System
    • Step 1 – Creating a Database List
      • Creating your Data file
    • Step 2 – Creating the PHP Code to backup the Databases
      • Reading the data from databaselist.txt into an Array
      • Backing up the Databases
    • Step 3 – Making the Backup Files Downloadable
  • Extending the Backup System – Making the Process Automated
    • Creating the FTP Code to upload the Backup Files through PHP
    • Running the Script
  • Restoring the Files
    • Manually Restoring a Database
    • Automatically Restoring a Number of Databases
  • Summary

 

Gareth Downes-Powell

Gareth Downes-PowellGareth has a range of skills, covering many computer and internet related subjects. He is proficient in many different languages including ASP and PHP, and is responsible for the setup and maintenance of both Windows and Linux servers on a daily basis.


In his daily web development work he uses the complete range of Macromedia software, including Dreamweaver MX, Flash MX, Fireworks MX and Director to build a number of websites and applications. Gareth has a close relationship with Macromedia, and as a member of Team Macromedia Dreamweaver, he has worked closely in the development of Dreamweaver, and was a beta tester for Dreamweaver MX.


On a daily basis he provides support for users in the Macromedia forums, answering questions and providing help on a range of different web related subjects. He has also written a number of free and commercial extensions for Dreamweaver MX, to further extend its capabilities using its native JavaScript API’s or C++.


As a web host, Gareth has worked with a range of different servers and operating systems, with the Linux OS as his personal favourite. Most of his development work is done using a combination of Linux, Apache and MySQL and he has written extensively about setting up this type of system, and also running Apache and MySQL under Windows.

See All Postings From Gareth Downes-Powell >>

Reviews

Well written but not practical for hosted sites

October 8, 2003 by Mark Saragossi

I get "Warning: system() has been disabled for security reasons"

So although the script is well explained it was frustrating at the end of it that it failed because it uses the System command which is blocked by many ISP's

Can you include the php code for download

December 9, 2003 by Keith Milner

Hi,

I found this tutorial very useful. I have one complaint which I think is common to all tutorials on this website -

The code is not made available for download. Which means you have to type it all in. A minor irritation I know but it wouldn't be hard to put right.

Keith

RE: Can you include the php code for download

December 10, 2003 by Gareth Downes-Powell

As requested, I`ve made the code available to download from:

http://www.garethdp.com/writing/articles/dmxzone/code/mysqlbackup/

Enjoy!

You must me logged in to write a review.