jenwachter/php-rsync

2.0.0 2024-02-21 19:37 UTC

This package is auto-updated.

Last update: 2024-04-21 19:59:52 UTC


README

A simple rsync library for PHP, able to perform local, remote, and Akamai NetStorage syncs. Note that this library is not all-inclusive of everything that can be done with the rsync command.

Requirements

  • PHP >= 8.0

Installation

To install the library, you will need to use Composer in your project.

composer require jenwachter/php-rsync

Usage

Create a connection

To start using the library, you must first create a connection. This connection is then passed to the Rsync class.

$connection = new PhpRsync\Connection($type);
$rsync = new Rsync($connection);

There are three types of connections:

Local

Use this type of connection when the source and destination are on the same machine. Example: transferring files from one directory to another on your local machine.

$local = new PhpRsync\Connection(
  'local',
  '/path/to/destination/root/dir'
);

$rsync = new Rsync($local);

Remote

Use this type of connection when the source and destination are different machines. Example: transferring files from your local machine to a remote machine.

$remote = new PhpRsync\Connection(
  'remote',
  '/path/to/destination/root/dir',
  'remote.host.com',
  'username',
  ['ssh_key' => '/path/to/ssh/key']
);

$rsync = new Rsync($remote);

Alternatively, you can use a password for authentication by passing ['password' => 'your_password'] as the fifth parameter.

Akamai

Use this type of connection when the destination is Akamai NetStorage. For details on how to connect to NetStorage, see the NetStorage Rsync documentation

$akamai = new PhpRsync\Connection(
  'akamai',
  '/path/to/destination/root/dir',
  'cpcode.rsync.upload.akamai.com',
  'username',
  ['ssh_key' => '/path/to/ssh/key']
);

$rsync = new Rsync($akamai);

Perform rsync transfers

$options = [];

$rsync->run(
  '/path/to/source/dir',
  'relative/path/to/destination/dir',
  $options
);

Available options

  • archive: Boolean. Adds --archive flag, if true. Default: true
  • compress: Boolean. Adds --compress flag, if true. Default: true
  • cwd: String. Changes the current working directory prior to running the rsync command. Default: null
  • delete: Boolean. Adds --delete flag, if true. Default: false
  • dryrun: Boolean. Adds --dry-run and --verbose flags, if true. Default: false
  • exclude: Array|String. If a string is passed, adds --exclude="<string>" flag. if an array of strings is passed, adds multiple --exclude="<string>" flags. Default: null
  • include: Array|String. If a string is passed, adds --include="<string>" flag. if an array of strings is passed, adds multiple --include="<string>" flags. Default: null
  • relative: Boolean. Adds --relative flag, if true. Default: false