PHP incremental backup is a php library designed to support setting incremental backups run by cron scripts.The library is a wrapper to different commands
These tools are used to perform incremental backups on the directories chosen.
- php 5.4 or greater installed.
- one of the above libraries to be installed in your system.
- Using composer
composer require iobotis/php-incremental-backup
- Download and run
composer installFollow the examples in the examples folder
- Simple Duplicity backup.
useBackup\Tools\FactoryasToolFactory;$settings =array('path_to_backup' =>$path_to_backup,'destination' =>array('type' =>'local','path' =>'/path/to/save' ),// 'passphrase' => 'abcdef',// 'exclude' => array('folder'));$backup = ToolFactory::create('Duplicity',$settings);$backup->execute();- Simple Duplicity backup with wrapper class.
useBackup\Tools\FactoryasToolFactory;useBackup\IncrementalBackup;useBackup\Tools\FactoryasToolFactory;$settings =array('path_to_backup' =>$path_to_backup,'destination' =>array('type' =>'local','path' =>'/path/to/save' ),// 'passphrase' => 'abcdef',// 'exclude' => array('folder'));$backup = ToolFactory::create('Duplicity',$settings);$backupClass =newIncrementalBackup ($backup);$backups =$backupClass->getAllBackups();foreach ($backupsas$time) {echo'There is a backup at' .$time ."\n";}if($backupClass->isChanged() ) {// back me up.echo'Back up initiated' ."\n";$backupClass->createBackup();}else {echo'No need to backup.' ."\n";}- Simple Duplicity backup restore last backup.
useBackup\Tools\FactoryasToolFactory;useBackup\IncrementalBackup;$settings =array('path_to_backup' =>$path_to_backup,'destination' =>array('type' =>'local','path' =>'/path/to/save' ),// 'passphrase' => 'abcdef');$duplicity = ToolFactory::create('Duplicity',$settings);$backupClass =newIncrementalBackup ($duplicity);// Restore last backup to this directory.$backupClass->restoreTo(end($backups ),'/path/to/restore');- Simple Tar backup.
useBackup\Tools\FactoryasToolFactory;useBackup\IncrementalBackup;$settings =array('path_to_backup' =>$path_to_backup,'destination' =>array('type' =>'local','path' =>$path_to_save ),//'exclude' => array('exclude', 'exclude1'));$backup = ToolFactory::create('Tar',$settings);$backupClass =newIncrementalBackup ($backup);$backups =$backupClass->getAllBackups();foreach ($backupsas$time) {echo'There is a backup at' .$time ."\n";}if($backupClass->isChanged() ) {// back me up.echo'Back up initiated' ."\n";$backupClass->createBackup();}else {echo'No need to backup.' ."\n";}- Tar restore last backup.
useBackup\Tools\FactoryasToolFactory;useBackup\IncrementalBackup;$settings =array('path_to_backup' =>$path_to_backup,'destination' =>array('type' =>'local','path' =>$path_to_save ),);$backup = ToolFactory::create('Tar',$settings);$backupClass =newIncrementalBackup ($backup );$backups =$backupClass->getAllBackups();// Restore last backup to this directory.$backupClass->restoreTo(end($backups ),'/path/to/restore' );1)Duplicity without Factory
useBackup\Binary;useBackup\FileSystem\Source;useBackup\Destination\FactoryasDesFactory;useBackup\Tools\Duplicity;useBackup\FileSystem\Folder;$binary =newBinary('/usr/bin/duplicity');$source =newSource('/var/www/example_com');$destination = DesFactory::create('/var/backups/example_com');$duplicity =newDuplicity($source,$destination,$binary);$duplicity->setArchiveDir('/var/www/cache');$duplicity->setExludedSubDirectories(array('cache','logs','tmp'));// check if duplicity is installed.$duplicity->isInstalled();// get duplicity version.$duplicity->getVersion();// verify backup location.$duplicity->verify();// backup if needed.$duplicity->execute();// retrieve existing backups.$backups =$duplicity->getAllBackups();// restore 1st backup.$folder =newFolder('/var/www/example_com');$duplicity->restore($backups[0],$folder);From the root folder run:php {location of phpunit phar}/phpunit.phar
orInstall composer dependencies and run the scripts defined in composer.json.