Chapter 8. Sync Backups

It's best practice to not store all you backups locally or not only storing them locally. With PHPBU you can copy your backups to different locations.

Caution

If you are syncing your backup to a cloud service it's advised to encrypt your backup beforehand. Especially if your backup contains personal identifiable information.

Table 8.1. Supported types of syncs:

TypeDescription
amazonCopy your backup to your amazon s3 account.
copy.comCopy your backup to a copy account.
dropboxCopy your backup to a dropbox account.
rsyncSync your backups with rsync.
sftpCopy your backup to a server via SFTP.
SoftLayer Object StorageSync your backup to a Softlayer Object Storage account.


Amazon S3

Sync your backup to an amazon S3 account.

If you are not using the PHAR Version you have to require "aws/aws-sdk-php": "2.7.*" in your composer file.

Table 8.2. amazons3-Options

NameValueRequiredDefaultDescription
keystringyes-The amazon s3 key.
secretstringyes-The amazon S3 secret.
bucketstringyes-A bucket where to store the backup.
regionstringyes-The region where the bucket is located e.g. 'eu-central-1'.
pathstringno/Path where to store the backup in your bucket.
useMultiPartUploadbooleannofalseUse Amazon S3 MultiPartUpload functionality.


Example 8.1: amazons3 XML example

<!-- sync amazon s3 -->
<sync type="amazons3">
  <option name="key" value="myAwsKey"/>
  <option name="secret" value="myAwsSecret"/>
  <option name="bucket" value="backup"/>
  <option name="region" value="eu-central-1"/>
  <option name="path" value="/some/dir"/>
</sync>


Example 8.2: amazons3 JSON example

{
  "type": "amazons3",
  "options": {
    "key": "myAwsKey",
    "secret": "myAwsSecret",
    "bucket": "backup",
    "region": "eu-central-1",
    "path": "/some/dir",
    "useMultiPartUpload": "true"
  }
}


Dropbox

Sync your backup to a dropbox account.

If you are not using the PHAR Version you have to require "dropbox/dropbox-sdk": "1.1.*" in your composer file.

Table 8.3. dropbox-Options

NameValueRequiredDefaultDescription
tokenstringyes- The dropbox authentication token. Go to www.dropbox.com/developers/apps Create your app Choose: dropbox api app files and datastore yes provide some app name "my-dropbox-app" generate access token to authenticate connection to your dropbox
pathstringyes-Directory where to store the backup in your dropbox account.


Example 8.3: dropbox XML example

<!-- sync dropbox -->
<sync type="dropbox">
  <option name="token" value="myCrazyLongApiTokenThatIGotFromDropbox"/>
  <option name="path" value="/some/dir"/>
</sync>
</section>


Example 8.4: dropbox JSON example

{
  "type": "dropbox",
  "options": {
    "token": "myCrazyLongApiTokenThatIGotFromDropbox",
    "path": "/some/dir"
  }
}


Rsync

Sync your backup via the rsync command.

Table 8.4. rsync-Options

NameValueRequiredDefaultDescription
pathstringyes-The remote path where your backups should be synced to.
hoststringyes-The remote host where your backups should be synced to.
userstringnoOS-User The user to connect to the remote host. Make sure the user is able to connect without entering a password otherwise you get prompted for a password while executing phpbu.
dirsyncbooleannofalseSync the target directory instead of syncing only the target file.
deletebooleannofalseAdd the --delete option to the rsync call, so locally deleted files will be deleted remotely as well.
excludestringno-List of files to exclude from the sync separated by ":" e.g. "*.suffix:foo.bar".
argsstringno- Advanced mode to use completely custom options. "rsync {args}". WARNING: phpbu is not escaping this in any way so use with caution! Use %TARGET_FILE% and %TARGET_DIR% as reference to your created backup.


Example 8.5: rsync XML example

<!-- sync rsync -->
<sync type="rsync">
  <option name="path" value="/backup/some/path"/>
  <option name="dirsync" value="true"/>
  <option name="host" value="backup.example.com"/>
  <option name="user" value="backup"/>
</sync>


Example 8.6: rsync JSON example

{
  "type": "rsync",
  "options": {
    "path": "/backup/some/path",
    "dirsync": "true",
    "host": "backup.example.com",
    "user": "backup"
  }
}


SFTP / FTP

Copy your backup to another server via SFTP or FTP.

If you want to use SFTP and you are not using the PHAR version you have to require "phpseclib/phpseclib": "2.0.*@dev" in your composer file. For this to work you have to set the minimum-stability to dev.

If you want to use the FTP-Sync your PHP has to be compiled with --enable-ftp.

Table 8.5. (s)ftp-Options

NameValueRequiredDefaultDescription
hoststringyes-The host you want do copy your backups to.
userstringyes-The user you want to connect with.
passwordstringno-The password to authenticate the user.
pathstringyes-The remote path where to copy the backup.


Example 8.7: sftp XML example

<!-- sync sftp -->
<sync type="sftp">
  <option name="host" value="backup.example.com"/>
  <option name="user" value="user.name"/>
  <option name="password" value="topsecret"/>
  <option name="path" value="backup/someName"/>
</sync>


Example 8.8: sftp JSON example

{
  "type": "sftp",
  "options": {
    "host": "backup.example.com",
    "user": "user.name",
    "password": "topsecret",
    "path": "backup/someName"
  }
}


If you want to use plain FTP just use ftp as type, options stay the same.

Softlayer Object Storage

Sync your backup to a Softlayer account.

If you are not using the PHAR Version you have to require "softlayer/objectstorage": "dev-master" in your composer file. For this to work you have to set the minimum-stability to dev.

Table 8.6. softlayer-Options

NameValueRequiredDefaultDescription
userstringyes-The user you want to connect with.
secretstringno-The api key to authenticate the user.
hoststringyes-The host you want do copy your backups to.
containerstringyes-The Object Storage Container where to put the backup.
pathstringyes-The remote path where to copy the backup.


Example 8.9: softlayer XML example

<!-- sync softlayer object storage -->
<sync type="softlayer">
  <option name="user" value="user.name"/>
  <option name="secret" value="topsecret"/>
  <option name="host" value="some.softlayer.domain.com"/>
  <option name="container" value="backup"/>
  <option name="path" value="/backup/someName"/>
</sync>


Example 8.10: softlayer JSON example

{
  "type": "softlayer",
  "options": {
    "user": "user.name",
    "secret": "topsecret",
    "host": "some.softlayer.domain.com",
    "container": "backup",
    "path": "/backup/someName"
  }
}


Please open a ticket on GitHub to suggest improvements to this page. Thanks!