2017 © Pedro Peláez
 

library rsyncer

Lightweigt rsync wrapper without dependencies

image

codeplayr/rsyncer

Lightweigt rsync wrapper without dependencies

  • Wednesday, November 16, 2016
  • by codeplayr
  • Repository
  • 1 Watchers
  • 2 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

### rsyncer

A thin rsync wrapper class for PHP without any dependencies

##### Requirements

PHP 5.4+, rsync, composer, (*1)

##### Installation

  • Use Composer to install the package, (*2)

  • From project root directory execute, (*3)

    composer install, (*4)

    or, (*5)

    composer require codeplayr/rsyncer, (*6)

  • Composer will take care of autoloading. Just include the autoloader at the top of the file, (*7)

    require_once __DIR__ . '/vendor/autoload.php';, (*8)

##### Usage

See following example:, (*9)

use \Codeplayr\Rsyncer\Option;
use \Codeplayr\Rsyncer\SSH;
use \Codeplayr\Rsyncer\Rsync;

$source = __DIR__ . '/src/';
$destination = __DIR__ . '/backup/';

$date = date('Y-m-d', time());

//rsync options
$option = new Option([
    Option::FILES_FROM  => __DIR__ . '/rules.txt',
    Option::EXCLUDE_FROM=> __DIR__ . '/exclude-rules.txt',
    Option::LOG_FILE    => __DIR__ . "/logs/{$date}.log",
    Option::ARCHIVE     => false,
    Option::LINKS       => true,
    Option::TIMES       => true,
    Option::RECURSIVE   => true,
    Option::VERBOSE     => true,
    Option::COMPRESS    => true,
    Option::CHECKSUM    => true,
    Option::DRY_RUN     => false,
]);

//add additional flags
$option->addFlag('human-readable')
        ->addArgument('exclude', '/path/to/exclude')
        ->addArgument('include', '*.html')
        ->addArgument('include', '*.php')
        ->addArgument('include', '*/')
        ->addArgument('exclude', '*');      

//optional ssh connection to remote host
$ssh = new SSH([
    SSH::USERNAME       => 'root',
    SSH::HOST           => '1.2.3.4',
    SSH::PORT           => 22,
    SSH::IDENTITY_FILE  => '/path/to/private/key',
]);

//configuration options
$conf = [
    Rsync::SHOW_OUTPUT  => true,
];

$rsnyc = new Rsync( $option, $ssh, $conf );

//assemble and show Command
echo $rsnyc->getCommand( $source, $destination );

//start syncing directories
if( ! $rsnyc->sync( $source, $destination ) ){
    echo $rsnyc->getMessage()->toString();
}

Running the script generates following rsync command and options:, (*10)

rsync
    -ltrvzc
    --human-readable        
    --files-from="/path/to/rules.txt"
    --exclude-from="/path/to/exclude-rules.txt"
    --log-file="/path/to/logs/2016-10-29.log"
    --exclude='/path/to/exclude'
    --include="*.html"
    --include="*.php"
    --include="*/"
    --exclude="*"
    -e="ssh -i /path/to/your/private/key"
    root@1.2.3.4:"/path/to/src/" "/path/to/backup/"

##### Run Tests:

  • All tests are inside tests folder.
  • Execute composer install --dev phpunit/phpunit to install phpunit
  • Run phpunit from inside the tests directory to execute testcase
  • Set --coverage-text option to show code coverage report in terminal

##### Notes:

If you like this script or have some features to add: contact me, fork this project, send pull requests, you know how it works., (*11)

The Versions

16/11 2016

dev-master

9999999-dev

Lightweigt rsync wrapper without dependencies

  Sources   Download

The Requires

  • php >=5.4.0

 

by Avatar codeplayr