|
| 1 | +# Custom behaviours |
| 2 | + |
| 3 | +You have the possibility to create your own step, name generator and compressor. |
| 4 | + |
| 5 | +- [Custom step](#custom-step) |
| 6 | +- [Custom name generator](#custom-name-generator) |
| 7 | +- [Custom compressor](#custom-compressor) |
| 8 | + |
| 9 | +## Custom step |
| 10 | + |
| 11 | +```php |
| 12 | +<?php |
| 13 | +namespace My\Vendor\Step; |
| 14 | + |
| 15 | +use Breadlesscode\Backups\Step\StepAbstract; |
| 16 | + |
| 17 | +class MyCustomExportStep extends StepAbstract |
| 18 | +{ |
| 19 | + /** |
| 20 | + * Folder name in backup file |
| 21 | + * |
| 22 | + * @var string |
| 23 | + */ |
| 24 | + protected $name = 'MySqlExport'; |
| 25 | + |
| 26 | + /** |
| 27 | + * your restore warning markdown string |
| 28 | + * if a this property is not sufficient, |
| 29 | + * you can override the getRestoreWarning() method |
| 30 | + * |
| 31 | + * @var string |
| 32 | + */ |
| 33 | + protected $restoreWarning = 'My custom warning'; |
| 34 | + |
| 35 | + /** |
| 36 | + * @inheritDoc |
| 37 | + */ |
| 38 | + public function backup(): bool |
| 39 | + { |
| 40 | + // your backup code here |
| 41 | + return true; |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * @inheritDoc |
| 46 | + */ |
| 47 | + public function restore(): bool |
| 48 | + { |
| 49 | + // your restore code here |
| 50 | + return true; |
| 51 | + } |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | +Settings.yaml |
| 56 | +```yaml |
| 57 | +Breadlesscode: |
| 58 | + Backups: |
| 59 | + steps: |
| 60 | + 'My\Vendor\Step\MyCustomExportStep': |
| 61 | + my: config |
| 62 | +``` |
| 63 | +
|
| 64 | +## Custom name generator |
| 65 | +BackupNameGenerator.php |
| 66 | +```php |
| 67 | +<?php |
| 68 | +namespace My\Vendor\Generators; |
| 69 | + |
| 70 | +class BackupNameGenerator implements BackupNameGeneratorInterface |
| 71 | +{ |
| 72 | + public function generate(): string |
| 73 | + { |
| 74 | + return (new \DateTime())->format('Y-m-d_H:i:s'); |
| 75 | + } |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +Objects.yaml |
| 80 | +```yaml |
| 81 | +Breadlesscode\Backups\Generators\BackupNameGeneratorInterface: |
| 82 | + className: 'My\Vendor\BackupNameGenerator' |
| 83 | +``` |
| 84 | +
|
| 85 | +## Custom compressor |
| 86 | +
|
| 87 | +```php |
| 88 | +<?php |
| 89 | +namespace My\Vendor\Compressor; |
| 90 | + |
| 91 | +class MyCompressor extends AbstractCompressor |
| 92 | +{ |
| 93 | + public function compress(string $source, string $targetFolder): ?string |
| 94 | + { |
| 95 | + // do your backup compressing |
| 96 | + return $archivePath; |
| 97 | + } |
| 98 | + |
| 99 | + public function decompress(string $source, string $targetFolder): ?string |
| 100 | + { |
| 101 | + // do your backup decompressing |
| 102 | + return $targetFolder; |
| 103 | + } |
| 104 | + |
| 105 | + public function generateFilename($name): string |
| 106 | + { |
| 107 | + return $name.'.tar.xyz'; |
| 108 | + } |
| 109 | +} |
| 110 | +``` |
0 commit comments