Create database backup & email using php

It is generally difficult to backup our database regularly and store them. With more and more storage space being provided by our email providers, we can write a script that can be called when required and it will automatically create database backup and mail it to the specified email.

The following zip contains two files:
1. ajDbBackup.class
2. backup.php

ajDbBackup.class file contains the ajDbBackup class which can be used to backup the database. An example of usage is given in file backup.php .
To email backup create a php file in the same directory where ajDbBackup.class is kept with the following data:
<?php
include ‘./ajDbBackup.class’;
$backup = new ajDbBackup;
$backup->emailTo = “email@domain.tld”;
$backup->emailFrom = “emailTwo@domain.tld”;
$backup->host = “mysqlHost”;
$backup->user = “mysqlUser”;
$backup->password = “mysqlUserPassword”;
$backup->dbName = “mysqlDbNameToBeBacked”;
$backup->ajMail();
?>

Give execution and read/write permissions to the files. Just call the file you have created through any web browser.

One Response to “Create database backup & email using php”

Tech @ InkAPoint (May 11th, 2009 at 10:53 am)

This is so cool

Leave your response!

Be nice. Keep it clean. Stay on topic. No spam.