Working with Custom Backup Storages
Plesk provides the option of choosing a remote storage to keep your backups, such as an FTP server. Using Plesk SDK, it is also possible to add more different custom backup storages, and enable Plesk to use them to keep the backups.
pm_Hook_Backup_Transport defines a set of methods, which describe the necessary functions of authentication and authorization, working with files, etc. With the help of this hook, Plesk Backup Manager knows about the new custom storage, and provides all the same operations and information that are available for the default backup storages.
To illustrate the subject, the following sample project is provided by Plesk: https://github.com/plesk/ext-cloud-backup-example.
As the extension developer, you may choose to handle authorization, using either OAuth2 or login and password.
Login and Password
The login and password (or access key/secret key) used for authentication with the custom storage are specified on the custom storage settings sub-form,
pm_Hook_Backup_Transport::getSettingsSubForm(), along with other settings. The entered login and password must be validated in the
OAuth2 authorization must be implemented in the
pm_Hook_Backup_Transport::authorize() method. This method is always called before displaying the custom storage settings sub-form,
pm_Hook_Backup_Transport::check() should be used to make sure all the functions involved in backup and restore operations (e.g., CRUD) are available. This method is called before each backup operation.
- Make sure to use the Plesk Key-Value Storage to encrypt and safely store passwords and access tokens.
- Create separate directories in the custom storage root directory for the different objects to keep their backup files from mixing.
Working with Files
Writing to Custom Storage
The methods responsible for writing the created backup to the custom storage are called in the following order:
Some storages may require the size of the file written to be known before starting the file upload. This information is not available during the Plesk backup creation. In this case, the backup should be split into a set of files of a known size. The files should be named in the following manner:
This way, Plesk Backup Manager will be able to correctly display information and work with the backup.
Reading from Custom Storage
The methods responsible for reading the backup from the custom storage are called in the following order:
Testing Your Extension with Custom Storage
To make sure all the backup/restore-related extension functions work properly, run the following command:
/opt/psa/admin/bin/pmm-ras --check-repository --debug --verbose --dump-storage=ext://<ext name>/subscription/<id>/ --session-path=/var/log/plesk/PMM