It's a best practice to NOT store your backups locally, or at least not only storing them locally.
With PHPBU Sync
adapters you can copy your backups to different locations.
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.
PHPBU supports cleaning up you locally stored backups by configuring a Cleanup.
Note that Cleanup
configurations do not affect remote files synced with Sync
configurations.
But some Sync
adapters support cleaning up remote files as well.
This is done by using cleanup.*
options in your Sync
configuration.
In order to better understand how remote cleanups work and how they are configured have a look at the Cleanups section.
Table 8.1. Supported types of syncs:
Type | Description | Remote Cleanup |
---|---|---|
amazon | Sync your backup to your Amazon S3 account. | yes |
Dropbox | Sync your backup to a Dropbox account. | yes |
Google Drive | Sync your backup to a Google Drive account. | yes |
OpenStack | Sync your backups to an OpenStack storage. | yes |
rsync | Sync your backups with rsync. | no |
sftp | Sync your backup to a server via SFTP. | yes |
SoftLayer Object Storage | Sync your backup to a Softlayer Object Storage account. | no |
Sync your backup to an amazon S3 account.
If you are not using the PHAR Version you have to require "aws/aws-sdk-php": "^3.10"
in your composer file.
Table 8.2. amazons3-Options
Name | Value | Required | Default | Description |
---|---|---|---|---|
key | string | yes | - | The amazon s3 key. |
secret | string | yes | - | The amazon S3 secret. |
bucket | string | yes | - | A bucket where to store the backup. |
region | string | yes | - | The region where the bucket is located e.g. 'eu-central-1'. |
path | string | no | / | Path where to store the backup in your bucket. |
useMultiPartUpload | boolean | no | false | Use Amazon S3 MultiPartUpload functionality. |
cleanup.type | string | no | - | The remote cleanup strategy (capacity|outdated|quantity|stepwise). |
cleanup.* | string | no | - | The remote cleanup strategy settings. For example "cleanup.size" if you use "cleanup.type" = "capacity". For details have a look at the corresponding Cleanup configurations. |
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" } }
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
Name | Value | Required | Default | Description |
---|---|---|---|---|
token | string | yes | - | 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 |
path | string | yes | - | 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" } }
Sync your backup to a Google Drive account.
If you are not using the PHAR Version you have to require
"google/apiclient":"^2.0"
in your composer file.
Table 8.4. Google Drive-Options
Name | Value | Required | Default | Description |
---|---|---|---|---|
secret | string | yes | - | Google Drive authentication json file. |
access | string | yes | - | Json file containing your access token. |
parentId | string | yes | - | The Google Drive element id where your backups should be stored. |
If you are unsure on how to obtain the secret and access files or the directory ID have a look at
sebastianfeldmann/phpbu-google-drive
a utility to generate your access token and to list the files and their IDs from your Google Drive account.
Example 8.5: Google Drive XML example
<!-- sync dropbox --> <sync type="googledrive"> <option name="secret" value="config/google/secret.json"/> <option name="access" value="config/google/access.json"/> <option name="parentId" value="bkjnwqr8123njndcqw12r"/> </sync> </section>
Example 8.6: Google Drive JSON example
{ "type": "googledrive", "options": { "secret": "config/google/secret.json", "access": "config/google/access.json", "parentId": "bkjnwqr8123njndcqw12r" } }
Sync your backup to a provider supporting the OpenStack API.
Table 8.5. OpenStack-Options
Name | Value | Required | Default | Description |
---|---|---|---|---|
auth_url | string | yes | - | The remote authentication url. |
region | string | yes | - | The OpenStack region. |
user | string | yes | - | The user name for authentication. |
password | string | yes | - | The user password. |
container_name | string | yes | - | The name of the container to store the backup. |
service_name | string | no | swift | The service to use for the upload. |
path | string | no | - | Remote path to store the backup. |
Example 8.7: OpenStack XML example
<!-- sync openstack --> <sync type="openstack"> <option name="auth_url" value="www.example.com"/> <option name="region" value="my-region"/> <option name="user" value="username"/> <option name="password" value="top-secret"/> <option name="path" value="/some/path"/> </sync>
Example 8.8: OpenStack JSON example
{ "type": "openstack", "options": { "auth_url": "www.example.com", "region": "my-region", "user": "username" "password": "my-secret" "path": "/some/path", } }
Sync your backup via the rsync command.
Table 8.6. rsync-Options
Name | Value | Required | Default | Description |
---|---|---|---|---|
path | string | yes | - | The remote path where your backups should be synced to. |
host | string | yes | - | The remote host where your backups should be synced to. |
user | string | no | OS-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. |
dirsync | boolean | no | false | Sync the target directory instead of syncing only the target file. |
delete | boolean | no | false | Add the --delete option to the rsync call, so locally deleted files will be deleted remotely as well. |
exclude | string | no | - | List of files to exclude from the sync separated by ":" e.g. "*.suffix:foo.bar". |
args | string | no | - | 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.9: 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.10: rsync JSON example
{ "type": "rsync", "options": { "path": "/backup/some/path", "dirsync": "true", "host": "backup.example.com", "user": "backup" } }
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.7. (s)ftp-Options
Name | Value | Required | Default | Description |
---|---|---|---|---|
host | string | yes | - | The host you want do copy your backups to. |
port | integer | no | 22 | The port you want do connect to. |
user | string | yes | - | The user you want to connect with. |
password | string | no | - | The password to authenticate the user. If 'key' is provided this will be used as private key password. |
key | string | no | - | Path to private key file to authenticate the user. |
path | string | yes | - | The remote path where to copy the backup. |
passive | boolean | no | false | Use passive ftp mode. |
Example 8.11: sftp XML example
<!-- sync sftp --> <sync type="sftp"> <option name="host" value="backup.example.com"/> <option name="port" value="22"/> <option name="user" value="user.name"/> <option name="password" value="topsecret"/> <option name="path" value="backup/someName"/> <option name="passive" value="true"/> </sync>
Example 8.12: sftp JSON example
{ "type": "sftp", "options": { "host": "backup.example.com", "port": 22, "user": "user.name", "password": "topsecret", "path": "backup/someName", "passive": "false" } }
If you want to use plain FTP just use ftp
as type, options stay the same.
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.8. softlayer-Options
Name | Value | Required | Default | Description |
---|---|---|---|---|
user | string | yes | - | The user you want to connect with. |
secret | string | no | - | The api key to authenticate the user. |
host | string | yes | - | The host you want do copy your backups to. |
container | string | yes | - | The Object Storage Container where to put the backup. |
path | string | yes | - | The remote path where to copy the backup. |
Example 8.13: 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.14: softlayer JSON example
{ "type": "softlayer", "options": { "user": "user.name", "secret": "topsecret", "host": "some.softlayer.domain.com", "container": "backup", "path": "/backup/someName" } }