iobotis / php-incremental-backup
PHP library to support file incremental backups
v1.0
2017-09-20 21:19 UTC
Requires
- php: >=5.4.0
- league/flysystem: ^1.0.35
Requires (Dev)
- phpunit/phpunit: >=3.7.38
This package is auto-updated.
Last update: 2024-05-26 23:48:21 UTC
README
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
Tools supported
These tools are used to perform incremental backups on the directories chosen.
Requirements:
- php 5.4 or greater installed.
- one of the above libraries to be installed in your system.
How to install
- Using composer
composer require iobotis/php-incremental-backup
- Download and run
composer install
Follow the examples in the examples folder
Examples:
- Simple Duplicity backup.
use Backup\Tools\Factory as ToolFactory; $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.
use Backup\Tools\Factory as ToolFactory; use Backup\IncrementalBackup; use Backup\Tools\Factory as ToolFactory; $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 = new IncrementalBackup ($backup); $backups = $backupClass->getAllBackups(); foreach ($backups as $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.
use Backup\Tools\Factory as ToolFactory; use Backup\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 = new IncrementalBackup ($duplicity); // Restore last backup to this directory. $backupClass->restoreTo(end( $backups ), '/path/to/restore');
- Simple Tar backup.
use Backup\Tools\Factory as ToolFactory; use Backup\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 = new IncrementalBackup ($backup); $backups = $backupClass->getAllBackups(); foreach ($backups as $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.
use Backup\Tools\Factory as ToolFactory; use Backup\IncrementalBackup; $settings = array( 'path_to_backup' => $path_to_backup, 'destination' => array( 'type' => 'local', 'path' => $path_to_save ), ); $backup = ToolFactory::create('Tar', $settings); $backupClass = new IncrementalBackup ( $backup ); $backups = $backupClass->getAllBackups(); // Restore last backup to this directory. $backupClass->restoreTo( end( $backups ), '/path/to/restore' );
Advanced usage
1)Duplicity without Factory
use Backup\Binary; use Backup\FileSystem\Source; use Backup\Destination\Factory as DesFactory; use Backup\Tools\Duplicity; use Backup\FileSystem\Folder; $binary = new Binary('/usr/bin/duplicity'); $source = new Source('/var/www/example_com'); $destination = DesFactory::create('/var/backups/example_com'); $duplicity = new Duplicity($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 = new Folder('/var/www/example_com'); $duplicity->restore($backups[0], $folder);
How to run unit tests
From the root folder run: php {location of phpunit phar}/phpunit.phar
or Install composer dependencies and run the scripts defined in composer.json.