Giter Site home page Giter Site logo

mysql-php-backup-class's Introduction

MySQL Backup Class

This project provides a useful tool (PHP Class) to backup any MySQL database automatically with Optional Amazon S3 Support.

Requirements

- PHP 5+
- MySQL 4.1+
- A writable (CHMOD 0777) backup directory on the server
- Amazon S3 Account (Optional)

Features

- Backup the whole database (All Tables) in one single file
- Backup each DB table in a seperate SQL Dump File
- Exclude specific tables from your Backup
- Backup data on Amazon S3 (Optional)
- Allows custom dump options
- Restore the whole database on the fly (Runs Once)
- Reads the backup file from Amazon S3 Storage if the local copy isn't available (in restore)

Currently Working On:

1. Add a Code Generation File   
2. Validate user provided settings (DB Login and Amazon S3 Keys)   
3. Validating user added dump options  (within the 'addDumpOption' Method)   
4. Creating the automatic scheduling of the backup process (CronJobs Creator)

Code Examples

Basic Backup Usage

<?php
	require_once('lib/BackupClass.php');
	$dbConfig = array('host' => 'localhost',
					  'login' => '{DBUsername}',
					  'password' => '{DBPassword}',
					  'database_name' => '{DBName}');
	
	$dbBackupObj = new DbBackup($dbConfig);
	$dbBackupObj->executeBackup();
?>

Extended Backup Usage (All Options, commented code)

<?php
	require_once('lib/BackupClass.php');
	
	//Database address, credentials and name
	$dbConfig = array('host' => 'localhost',
					  'login' => '{DBUsername}',
					  'password' => '{DBPassword}',
					  'database_name' => '{DBName}');
	
	
	//Amazon S3 Configurations Array (Optional)
	$amazonConfig = array('accessKey' => '{YOUR S3 ACCESS KEY}',
				 	  'secretKey' =>  '{Your S3 Secret Key}',
				  	  'bucketName' => '{Your Bucket}');
	
	
	$dbBackupObj = new DbBackup($dbConfig);
	
	//Put backup files in the 'extendedExample' directory. NOTE: 'backups' DIR should be writable
	$dbBackupObj->setBackupDirectory('backups/extendedExample');
	
	//To disable the single table files dumping (1 Dump file for the whole database)
	$dbBackupObj->setDumpType(0); 
	
	//Exclude few tables from your backup execution
	$dbBackupObj->excludeTable('table1Name','tabel2Name','table3Name');
	
	//Add few custom options to your backup execution
	$dbBackupObj->addDumpOption('--xml','--force'); //Get XML output and Continue on error
	
	//Transfer your backup files to Amazon S3 Storage
	$dbBackupObj->enableS3Support($amazonConfig);
	
	//Start the actual backup process using the user specified settings and options
	$dbBackupObj->executeBackup();
?>

Basic Restore Usage (With AWS S3 Support)

<?php
	require_once('lib/BackupClass.php');
	
	$dbConfig = array('host' => 'localhost',
					  'login' => '{DBUsername}',
					  'password' => '{DBPassword}',
					  'database_name' => '{DBName}');
	
	$amazonConfig = array('accessKey' => '{YOUR S3 ACCESS KEY}',
				 	  'secretKey' =>  '{Your S3 Secret Key}',
				  	  'bucketName' => '{Your Bucket}');
	
	$dbBackupObj = new DbBackup($dbConfig);
	$dbBackupObj->enableS3Support($amazonConfig);
	$dbBackupObj->executeRestore();
?>

mysql-php-backup-class's People

Contributors

aymanrb avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.