|
4 | 4 | use phpbu\App\Backup; |
5 | 5 | use phpbu\App\Backup\Compressor; |
6 | 6 | use phpbu\App\Backup\Collector; |
| 7 | +use phpbu\App\Backup\Source\Status; |
7 | 8 | use phpbu\App\Backup\Target; |
8 | 9 |
|
9 | 10 | /** |
@@ -237,10 +238,43 @@ protected function executeBackup(Configuration\Backup $conf, Target $target) |
237 | 238 | { |
238 | 239 | $this->result->backupStart($conf); |
239 | 240 | $source = Factory::createSource($conf->getSource()->type, $conf->getSource()->options); |
240 | | - $source->backup($target, $this->result); |
| 241 | + $status = $source->backup($target, $this->result); |
| 242 | + if (is_a($status, '\\phpbu\\App\\Backup\\Source\\Status') && !$status->handledCompression()) { |
| 243 | + $this->handleCompression($target, $status); |
| 244 | + } |
241 | 245 | $this->result->backupEnd($conf); |
242 | 246 | } |
243 | 247 |
|
| 248 | + /** |
| 249 | + * Handle directory compression for sources which can't handle compression by them self. |
| 250 | + * |
| 251 | + * @param \phpbu\App\Backup\Target $target |
| 252 | + * @param \phpbu\App\Backup\Source\Status $status |
| 253 | + * @throws \phpbu\App\Exception |
| 254 | + */ |
| 255 | + protected function handleCompression(Target $target, Status $status) |
| 256 | + { |
| 257 | + $pathToCompress = $status->getDataPath(); |
| 258 | + if (empty($pathToCompress)) { |
| 259 | + throw new Exception('no path to compress set'); |
| 260 | + } |
| 261 | + if (!is_dir($pathToCompress)) { |
| 262 | + throw new Exception('path to compress should be a directory'); |
| 263 | + } |
| 264 | + try { |
| 265 | + $tar = new Backup\Source\Tar(); |
| 266 | + $tar->setup( |
| 267 | + array( |
| 268 | + 'path' => $pathToCompress, |
| 269 | + 'removeDir' => 'true', |
| 270 | + ) |
| 271 | + ); |
| 272 | + $tar->backup($target, $this->result); |
| 273 | + } catch (\Exception $e) { |
| 274 | + throw new Exception('Failed to \'tar\' directory: ' . $pathToCompress . PHP_EOL . $e->getMessage(), 1, $e); |
| 275 | + } |
| 276 | + } |
| 277 | + |
244 | 278 | /** |
245 | 279 | * Execute checks. |
246 | 280 | * |
|
0 commit comments