PHP Backup: Backup data using several methods

Recommend this page to a friend!
  Info   View files (108)   Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 415 All time: 6,341 This week: 406
Version License PHP version Categories
php-backup 1.0.2MIT/X Consortium ...5.2PHP 5, System information, Unix
Description Author

This package can backup data using several methods.

It can read a configuration file in the INI format to determine which data is to be backed up with one or more of the supported backup methods.

The main class creates a task object for each backup method to be executed and passes it parameters that determine which backup observer class needes to be instantiated to implement each backup task.

Currently it provides backup observer classes for taking backups of MySQL data using the mysqldump program, PostgreSQL data using pg_dump, data available via FTP servers using the wget program, filesystem backups using tar and backups over ssh using scp.

Backup programs are run using the pcntl extension, so it should only support Unix like systems.

Additional backup observer classes may be provides to implement new types of backup methods.

A logger class may output information about the performed backup tasks to a file, to the console, or sent by email.

Innovation Award
PHP Programming Innovation award nominee
March 2014
Number 3


Prize: One year server license IP to country, region, city, latitude, longitude, ZIP code, time zone, area code database
Every developer should be concerned with putting reliable backup methods to save their applications data in case something bad happens.

There can be many types of data to backup like files, databases, among other things.

This class provides a general backup solution that can be adapted to backup anything by the means of extensions that can add support to custom backup methods.

Manuel Lemos
Picture of Andi P. Trix
Name: Andi P. Trix <contact>
Classes: 2 packages by
Country: Romania Romania
Age: ???
All time rank: 243649 in Romania Romania
Week rank: 771 11 in Romania Romania
Innovation award
Innovation award
Nominee: 1x

Details
PHP Backup
==========

This set of scripts provide a framework for making backups using the PHP language.  
It was developed and tested in Ubuntu using PHP 5.5.9 but it might work with lower versions. Because it uses `pcntl_fork`, it does not run on Windows platforms.  
It supports out of the box 6 kind of backups: ftp using `wget`, mysql using `mysqldump`, filesystem and individual directories using `tar`, scp and postgresql.

Requirements
------------

* PHP 5.5.9 on *nix platform (it might work with lower PHP versions)
* the tar and bzip2 commands used by the directory and filesystem observers;
* the wget command used by the ftp observer;
* the mysqldump command used by the mysqldump observer;
* the scp and sshpass commands used by the ssh observer;
* the pg_dump command used by the psql observer;

FTP and MySQL backup
--------------------

* make the script executable: `chmod +x php-backup`
* prepare the ini and the csv file
    * `cp ftp_and_mysql.ini.dist ftp_and_mysql.ini`
    * `touch ftp_and_mysql`
    * add the ftp and mysql login information in your ftp_and_mysql file
* run the command: `./php-backup -i ftp_and_mysql.ini`

Filesystem backup
-----------------

This method iterates through a list of paths defined in a CSV file and it creates archives of each children directories (useful when you have all projects in the same directory).

### Usage

* `cp filesystem.ini.dist filesystem.ini` and edit it to suit your needs
* `cp filesystem.dist filesystem`
* edit `filesystem` and add the parent directories, each on a new line
* run the script: `./php-backup -i filesystem.ini`

Directories and MySQL backup
----------------------------

This method reads a CSV file with records made out of a path to a project and the mysql info for that project.

### Usage

* `cp directories_and_mysql.ini.dist directories_and_mysql.ini` and edit it to suit your needs
* `cp directories_and_mysql.dist directories_and_mysql`
* edit `directories_and_mysql` and add the project directory and the mysql info on the same line
* run the script: `./php-backup -i directories_and_mysql.ini`


Directories and PostgreSQL backup
----------------------------

This method reads a CSV file with records made out of a path to a project and the postgresql info for that project.

### Usage

* `cp directories_and_postgresql.ini.dist directories_and_postgresql.ini` and edit it to suit your needs
* `cp directories_and_postgresql.dist directories_and_postgresql`
* edit `directories_and_postgresql` and add the project directory and the postgresql info on the same line
* run the script: `./php-backup -i directories_and_postgresql.ini`

SSH and MySQL backup
----------------------------

This method reads a CSV file with records made out of ssh login info and the project path on the server together with the mysql info for that project.

### Usage

* `cp ssh_and_mysql.ini.dist ssh_and_mysql.ini` and edit it to suit your needs
* `cp ssh_and_mysql.dist ssh_and_mysql`
* edit `ssh_and_mysql` and add the ssh info and the mysql info on the same line
* run the script: `./php-backup -i ssh_and_mysql.ini`

**Note**: You can combine the observers in the ini file as you see fit.

Extending
---------
* create your namespace: `mkdir -p com/example/backup/observers`
* `cd com/example/backup/observers`
* `vi custom.class.php`
* paste this code:


    ```php
    <?php
    namespace Com\Example\Backup\Observers;

    class Custom implements \SplObserver {
        protected $name = 'Custom Observer';

        public function update(\SplSubject $subject) {
            //do your thing here
        }
    }
    ```

    You might want to extend the `Common` class which already has implemented an `execute` method:

    ```php
    <?php
    namespace Com\Example\Backup\Observers;
    
    use Org\Impavidly\Backup\Observers\Common;

    class Custom extends Common {
        protected $name = 'Custom Observer';

        public function update(\SplSubject $subject) {
            $command = "<some command>";
            $status = $this->execute($subject, $command);
            
            return $status;
        }
    }
    ```    
    
* add the observer class to the "observers" section of the ini file:
    `custom = Com\Example\Backup\Observers\Custom`
* add your configuration in a new ini section, something like

    ```
    [custom]
    name = value
    ```

    accessible in the observer as `$subject->config['custom']['name']`
* run the command: `./php-backup -i <some_ini_file>.ini`


### Companies using PHP-Backup

* http://webkoenig.ch/
* http://agentur-am-see.ch/ 

  Files  
File Role Description
log4php (19 files, 8 directories)
org (1 directory)
directories_and_mysql.dist Data Auxiliary data
directories_and_mysql.ini.dist Data Auxiliary data
directories_and_postgresql.dist Data added postgresql observer
directories_and_postgresql.ini.dist Data added postgresql observer
filesystem.dist Data Auxiliary data
filesystem.ini.dist Data Auxiliary data
ftp_and_mysql.dist Data explicit ftp&mysql settings
ftp_and_mysql.ini.dist Data explicit ftp&mysql settings
LICENSE Lic. Auxiliary data
php-backup Data Auxiliary data
README.md Doc. Auxiliary data
ssh_and_mysql.dist Data Auxiliary data
ssh_and_mysql.ini.dist Data Auxiliary data

  Files  /  log4php  
File Role Description
appenders (14 files)
configurators (5 files)
filters (4 files)
helpers (4 files)
layouts (6 files)
pattern (24 files)
renderers (4 files)
xml (1 file)
   LICENSE Lic. License text
   Logger.php Class Class source
   LoggerAppender.php Class Class source
   LoggerAppenderPool.php Class Class source
   LoggerAutoloader.php Class Class source
   LoggerConfigurable.php Class Class source
   LoggerConfigurator.php Class Class source
   LoggerException.php Class Class source
   LoggerFilter.php Class Class source
   LoggerHierarchy.php Class Class source
   LoggerLayout.php Class Class source
   LoggerLevel.php Class Class source
   LoggerLocationInfo.php Class Class source
   LoggerLoggingEvent.php Class Class source
   LoggerMDC.php Class Class source
   LoggerNDC.php Class Class source
   LoggerReflectionUtils.php Class Class source
   LoggerRoot.php Class Class source
   LoggerThrowableInformation.php Class Class source

  Files  /  log4php  /  appenders  
File Role Description
   LoggerAppenderConsole.php Class Class source
   LoggerAppenderDailyFile.php Class Class source
   LoggerAppenderEcho.php Class Class source
   LoggerAppenderFile.php Class Class source
   LoggerAppenderFirePHP.php Class Class source
   LoggerAppenderMail.php Class Class source
   LoggerAppenderMailEvent.php Class Class source
   LoggerAppenderMongoDB.php Class Class source
   LoggerAppenderNull.php Class Class source
   LoggerAppenderPDO.php Class Class source
   LoggerAppenderPhp.php Class Class source
   LoggerAppenderRollingFile.php Class Class source
   LoggerAppenderSocket.php Class Class source
   LoggerAppenderSyslog.php Class Class source

  Files  /  log4php  /  configurators  
File Role Description
   LoggerConfigurationAdapter.php Class Class source
   LoggerConfigurationAdapterINI.php Class Class source
   LoggerConfigurationAdapterPHP.php Class Class source
   LoggerConfigurationAdapterXML.php Class Class source
   LoggerConfiguratorDefault.php Class Class source

  Files  /  log4php  /  filters  
File Role Description
   LoggerFilterDenyAll.php Class Class source
   LoggerFilterLevelMatch.php Class Class source
   LoggerFilterLevelRange.php Class Class source
   LoggerFilterStringMatch.php Class Class source

  Files  /  log4php  /  helpers  
File Role Description
   LoggerFormattingInfo.php Class Class source
   LoggerOptionConverter.php Class Class source
   LoggerPatternParser.php Class Class source
   LoggerUtils.php Class Class source

  Files  /  log4php  /  layouts  
File Role Description
   LoggerLayoutHtml.php Class Class source
   LoggerLayoutPattern.php Class Class source
   LoggerLayoutSerialized.php Class Class source
   LoggerLayoutSimple.php Class Class source
   LoggerLayoutTTCC.php Class Class source
   LoggerLayoutXml.php Class Class source

  Files  /  log4php  /  pattern  
File Role Description
   LoggerPatternConverter.php Class Class source
   LoggerPatternConverterClass.php Class Class source
   LoggerPatternConverterCookie.php Class Class source
   LoggerPatternConverterDate.php Class Class source
   LoggerPatternConverterEnvironment.php Class Class source
   LoggerPatternConverterFile.php Class Class source
   LoggerPatternConverterLevel.php Class Class source
   LoggerPatternConverterLine.php Class Class source
   LoggerPatternConverterLiteral.php Class Class source
   LoggerPatternConverterLocation.php Class Class source
   LoggerPatternConverterLogger.php Class Class source
   LoggerPatternConverterMDC.php Class Class source
   LoggerPatternConverterMessage.php Class Class source
   LoggerPatternConverterMethod.php Class Class source
   LoggerPatternConverterNDC.php Class Class source
   LoggerPatternConverterNewLine.php Class Class source
   LoggerPatternConverterProcess.php Class Class source
   LoggerPatternConverterRelative.php Class Class source
   LoggerPatternConverterRequest.php Class Class source
   LoggerPatternConverterServer.php Class Class source
   LoggerPatternConverterSession.php Class Class source
   LoggerPatternConverterSessionID.php Class Class source
   LoggerPatternConverterSuperglobal.php Class Class source
   LoggerPatternConverterThrowable.php Class Class source

  Files  /  log4php  /  renderers  
File Role Description
   LoggerRenderer.php Class Class source
   LoggerRendererDefault.php Class Class source
   LoggerRendererException.php Class Class source
   LoggerRendererMap.php Class Class source

  Files  /  log4php  /  xml  
File Role Description
   log4php.dtd Data Auxiliary data

  Files  /  org  
File Role Description
impavidly (1 directory)

  Files  /  org  /  impavidly  
File Role Description
backup (4 files, 2 directories)

  Files  /  org  /  impavidly  /  backup  
File Role Description
exceptions (3 files)
observers (7 files)
   backup.class.php Class Class source
   backup.php Class Class source
   logger.class.php Class Class source
   task.class.php Class Class source

  Files  /  org  /  impavidly  /  backup  /  exceptions  
File Role Description
   exception.class.php Class Class source
   fail_exception.class.php Class Class source
   fork_exception.class.php Class Class source

  Files  /  org  /  impavidly  /  backup  /  observers  
File Role Description
   common.class.php Class Class source
   directory.class.php Class Class source
   filesystem.class.php Class Class source
   ftp.class.php Class Class source
   mysqldump.class.php Class Class source
   psql.class.php Class added postgresql observer
   ssh.class.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:415
This week:0
All time:6,341
This week:406

For more information send a message to info at phpclasses dot org.