Beispiel #1
0
 protected function createZipContainingEveryFileInManifest(Manifest $manifest)
 {
     consoleOutput()->info("Zipping {$manifest->count()} files...");
     $pathToZip = $this->temporaryDirectory->path(config('laravel-backup.backup.destination.filename_prefix') . Carbon::now()->format('Y-m-d-H-i-s') . '.zip');
     $zip = Zip::createForManifest($manifest, $pathToZip);
     consoleOutput()->info("Created zip containing {$zip->count()} files. Size is {$zip->humanReadableSize()}");
     event(new BackupZipWasCreated($pathToZip));
     return $pathToZip;
 }
Beispiel #2
0
 public function run()
 {
     $this->temporaryDirectory = TemporaryDirectory::create();
     try {
         if (!count($this->backupDestinations)) {
             throw InvalidBackupJob::noDestinationsSpecified();
         }
         $manifest = $this->createBackupManifest();
         if (!$manifest->count()) {
             throw InvalidBackupJob::noFilesToBeBackedUp();
         }
         $zipFile = $this->createZipContainingEveryFileInManifest($manifest);
         $this->copyToBackupDestinations($zipFile);
     } catch (Exception $exception) {
         consoleOutput()->error("Backup failed because {$exception->getMessage()}." . PHP_EOL . $exception->getTraceAsString());
         event(new BackupHasFailed($exception));
     }
     $this->temporaryDirectory->delete();
 }