Download the PHP package runopencode/backup without Composer

On this page you can find all versions of the php package runopencode/backup. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package backup

[DEPRECIATED] Simple web application backup library

This library is depreciated, please use https://phpbu.de


Packagist Scrutinizer Code Quality Code Coverage Build Status Build Status

SensioLabsInsight

NOTE: This library is fork of 'kbond/php-backup' library with significant modifications which disables compatibility with its original.

Every process of backup can be broken down to several activities:

Having in mind the process stated above, we can identify several major parts of backup system:

Note that author of this brilliant idea on how to brake down to fundamental backup system components is Kevin Bond.

See if this library is for you by evaluating simple example

Let's backup our website by creating simple application that will be executed by crontab. Let's say that our code is in some app.php file (Don't be scared with amount of code - each line is commented so you can understand the concept with ease).

<?php 
/**
 * file: app.php
 */

require_once('vendor/autoload.php'); // We are going to use composer for autoloading.

use Psr\Log\NullLogger;
use Symfony\Component\EventDispatcher\EventDispatcher;
use RunOpenCode\Backup\Source\MySqlDumpSource;
use RunOpenCode\Backup\Source\SourceCollection;
use RunOpenCode\Backup\Processor\ZipArchiveProcessor;
use RunOpenCode\Backup\Namer\Timestamp;
use RunOpenCode\Backup\Rotator\NullRotator;
use RunOpenCode\Backup\Rotator\MaxCountRotator;
use RunOpenCode\Backup\Destination\FlysystemDestination;
use RunOpenCode\Backup\Backup\Profile;
use RunOpenCode\Backup\Workflow\Workflow;
use RunOpenCode\Backup\Manager;

use League\Flysystem\Dropbox\DropboxAdapter;
use League\Flysystem\Filesystem;
use Dropbox\Client;

$logger = new NullLogger();                                 // Or you can use concrete logger if you like.
$eventDispatcher = new EventDispatcher();                   // We need event dispatcher as well.

// Let's define source of our website files, we will use glob source to fetch files
// Array keys are path to directories where files residue, while values are path prefixes which we would like to remove
// and work only with relative paths
$files = new GlobSource(array(
    '/path/to/directory/with/files' => 'path/to/directory',           
    '/other/path/to/directory/with/files' => 'other/path'            
));

// Let's backup database as well...
$settings = array(...);
$database = new MySqlDumpSource($settings['database'], $settings['username'], $settings['password'], $settings['host'], $settings['port']);

// Our files and databases are things that we are want to backup, so we have to use source collection...
$source = new SourceCollection(array(
    $files,
    $database
));

// We will zip our backup files in order to save storage space 
$processor = new ZipArchiveProcessor('archive.zip');
// Note that processor requires event dispatcher...
$processor->setEventDispatcher($eventDispatcher);

// Our backups will get name based on current timestamp
$namer = new Timestamp();

// We will not use pre-rotator...
$preRotator = new NullRotator();
// But we will use post-rotator... (see docs below for difference, this is just example) limiting number of backups to some number.
$postRotator = new MaxCountRotator(5);

// And let's define our backup storage, per example, Dropbox via Flysystem (which is optional).
// @see http://flysystem.thephpleague.com/adapter/dropbox/
$client = new Client($accessToken, $appSecret);
$adapter = new DropboxAdapter($client, [$prefix]);
$filesystem = new Filesystem($adapter);
$destination = new FlysystemDestination($filesystem);

// When we have components, lets define our profile:
$profile = new Profile('my-profile', $source, $processor, $namer, $preRotator, $destination, $postRotator);

// We need workflow for manager, so we will build it and provide it with logger and event dispatcher
$workflow = Workflow::build();
$workflow->setEventDispatcher($eventDispatcher);
$workflow->setLogger($logger);

// Finally, we will create manager, and feed him with profile.
$manager = new Manager($workflow, array($profile));

// And we can now execute backup process...
$manager->execute('my-profile');

This library provides you with very flexible way to define and execute your backups. However, library is intended to be used within frameworks where profile construction process ought to be simplified via various configurations possibilities of concrete framework.

Do read further more to find out how to use and extend library to your needs.

Source and File

Source is defined within RunOpenCode\Backup\Contract\SourceInterface and have only one method defined: fetch(). Expected result from Source implementation is collection of RunOpenCode\Backup\Contract\FileInterface. File interface is abstraction of file which is subject of backup process. Concrete implementation is provided within this library as RunOpenCode\Backup\Backup\File.

Backup library currently provides you with several SourceInterface implementations:

Backup

Backup is abstraction of backup job, it is a collection of backup Files, and has its unique name.

Processor

Usually, when we are doing some backup, we process our backup files (per example - we compress them into one single archive). Processor is defined within RunOpenCode\Backup\Contract\ProcessorInterface and have only one method defined: process(array $files).

Purpose of processor is to somehow modify the collection of files scheduled for backup, and to return the resulting files of that modification.

Backup library currently provides you with several ProcessorInterface implementations:

Namer

Your backup files will be stored in one directory in your backup storage. Namer will provide a name for that directory. Namers implement RunOpenCode\Backup\Contract\NamerInterface which contains only one method: getName().

Backup library provides you with two default namer implementations:

Depending on naming strategy, you can get different results with your backup. With RunOpenCode\Backup\Namer\Constant you can implement incremental backup, snapshot backup, which will behave as rsync Unix utility. With timestamp namer, RunOpenCode\Backup\Namer\Timestamp, each new backup can be stored in new directory.

However, you can configure timestamp namer to use, per example, only day of the week, so you can store only last 7 backups without using rotators.

Nevertheless, it is advise to use namers for defining weather it will be a incremental backup, or complete backup, while rotators should be used for rotations of old backups.

Rotator

Rotator will nominate old backups for removal from backup storage, if some conditions are met. Rotator is defined with RunOpenCode\Backup\Contract\RotatorInterface and have only one method: nominate(array $backups). Rotator can not remove old backups, rotator is not aware of backup storage, his only role in process is to nominate old backups for removal from list of backups.

Backup library provides you with several rotators:

Note that default backup workflow within this library defines pre-rotation and post-rotation. Pre-rotation is executed before backup is copied to backup storage (destination), while post-rotation is executed after backup is copied to backup storage.

The reason behind this is that file system operations are not transactional. If removal of old backup is executed prior to pushing new backup to backup storage, and coping fails, you could end up with one backup less as a result of operation. However, if removal of old backup is executed after pushing new backup to backup storage, and coping fails, you would still keep old backups.

Pre and post rotation should support wishes of booth more and/or less conservative system administrator.

Destination

Destination is abstraction of backup storage. Each destination implements RunOpenCode\Backup\Contract\Destination interface which is most complex component in this library and have several responsibilities:

Backup library provide you with several default implementations:

Additionally, you are provided with possibility to use multiple destinations for your backups, by using:

Note that you can combine ReplicatedDestination and DestinationCollection to achieve various different backup storage systems, from simple ones to very complex.

Workflow

Workflow is abstraction of backup process, a sequence of activities which needs to be undertaken for backup process to be successfully completed.

Workflow is defined with RunOpenCode\Backup\Contract\WorkflowInterface, while workflow activity is defined with RunOpenCode\Backup\Contract\WorkflowActivityInterface. In that matter, you can consider a Workflow as collection of Activities, executed in ordered sequence.

Backup library provides you with default implementation of workflow: RunOpenCode\Backup\Workflow\Workflow with static method build() that will create default workflow with following activities in sequence:

  1. RunOpenCode\Backup\Workflow\Fetch activity in which files for backup are fetched from source.
  2. RunOpenCode\Backup\Workflow\Process activity in which files for backup are processed.
  3. RunOpenCode\Backup\Workflow\Name activity in which backup gets its name.
  4. RunOpenCode\Backup\Workflow\PreRotate activity in which existing old backups on destination are rotated.
  5. RunOpenCode\Backup\Workflow\Push activity in which backup is pushed to destination.
  6. RunOpenCode\Backup\Workflow\PostRotate activity in which existing old backups on destination are rotated.

Note that you can modify this workflow to suit your needs, if provided one is not according to your desired backup workflow. However, this can be considered as edge case.

You should note that default implementation of workflow, RunOpenCode\Backup\Workflow\Workflow depends on Symfony\Component\EventDispatcher\EventDispatcherInterface and Psr\Log\LoggerInterface, as well as provided workflow activities. However, neither workflow, nor its activities, resolves that dependency during the construction process. Workflow will provide EventDispatcher and Logger to the activities prior to their execution via setters, while workflow should be provided with mentioned prior to its execution.

Events

Events and Symfony EventDispatcher are major difference between this library and original kbond/php-backup library. Events which are dispatched within this library and default workflow are defined in RunOpenCode\Backup\Event\BackupEvents while dispatched events are instance of RunOpenCode\Backup\Event\BackupEvent.

Events are used to follow up every defined backup workflow activity which allows you to:

By using event dispatching, API for backup components is simplified - there is no need for cleanUp() methods.

Important note: some events will be dispatched, and some won't. However, in your application, you can always count on following events:

Other events depends on workflow and result of each workflow activity, as well as fact if there were some error in execution.

Profile

Profile is defined with RunOpenCode\Backup\Contract\ProfileInterface while default implementation RunOpenCode\Backup\Backup\Profile is provided. Backup profile defines:

If you think about your project, application which you want to backup, profiles for your application would be, per example:

Manager

Manager is defined with RunOpenCode\Backup\Contract\ManagerInterface, default implementation is given with RunOpenCode\Backup\Manager. He holds references to all profiles, allows iteration trough profiles, and their execution. If you are using dependency injection or service locator in your project, Manager should be only one public entry point into library, while other components should be injected into manager as hidden/private dependencies.

Notes on EventDispatcher, Logger and throwing exceptions

Note that some of the components in library depends on event dispatcher and/or logger. However, dependency is not provided via constructor, it is provided via setters. Some of the components do depend on dispatcher and/or logger, some don't.

In order to identify weather some class depends on dispatcher you can investigate if that class implements RunOpenCode\Backup\Contract\EventDispatcherAwareInterface, while logger dependency can be investigated by checking if RunOpenCode\Backup\Contract\LoggerAwareInterface is implemented.

Instances of RunOpenCode\Backup\Contract\WorkflowInterface and RunOpenCode\Backup\Contract\WorkflowActivityInterface depends on logger and dispatcher by design. They will log about progress of backup process and dispatch backup progress events.

Some other classes within this library depends on event dispatcher in order to clean up temporary files and to release resources.

However, do note that by design it is intended for workflow and its activities to log and to dispatch events. Other components should subscribe to events only. If they have to notify about error - they should throw exception.

Logger and Event Dispatcher traits

To simplify your implementation, when implementing RunOpenCode\Backup\Contract\EventDispatcherAwareInterface and RunOpenCode\Backup\Contract\LoggerAwareInterface, please note that

are at your disposal.

Extending the library

Do you need your own source, destination, processor? You can easily extend the library.

Implementing your own source

Your class needs to implement RunOpenCode\Backup\Contract\SourceInterface. Method fetch() should return collection of files RunOpenCode\Backup\Contract\File for backup.

Note that each file has its path and relative path. Path is absolute path to file, so backup library can access to it and copy it to the backup destination. However, within backup directory, file will be saved under relative path. Relative path is determined by root path of file.

Implementing your own processor

Your class needs to implement RunOpenCode\Backup\Contract\ProcessorInterface with method process(array $files). You will get an collection of files that needs to be backed up. Your processor should do something with those files, and return collection of files that should be backed up after processing.

Implementing your own rotator

Your class needs to implement RunOpenCode\Backup\Contract\RotatorInterface. Rotator will get collection of backups on backup destination and should only nominate which backups should be removed.

Implementing your own destination

Your class needs to implement RunOpenCode\Backup\Contract\Destination. Destination is collection of RunOpenCode\Backup\Contract\BackupInterface, while it needs to be noted that physically, for each backup, destination will create a directory and store all backup files within that directory.

When implementing method push(BackupInterface $backup) destination should support creating new backups, as well as maintaining incremental backups. That means that if backup directory exists on destination, on push, destination should sync source files with files that exists in backup directory. To speed up implementation, RunOpenCode\Backup\Destination\BaseDestination is at your disposal.


This library is licensed under MIT license, same license as original library. For original library license, please visit: https://github.com/kbond/php-backup/blob/master/LICENSE.

For license of this library, see LICENSE file distributed with this package.


All versions of backup with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4
psr/log Version 1.*
symfony/event-dispatcher Version ~2.7.6
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package runopencode/backup contains the following files

Loading the files please wait ....