diff --git a/app/Console/Commands/BarFullBackup.php b/app/Console/Commands/BarFullBackup.php new file mode 100644 index 00000000..398cf15a --- /dev/null +++ b/app/Console/Commands/BarFullBackup.php @@ -0,0 +1,38 @@ +exporter->process(); + + return Command::SUCCESS; + } +} diff --git a/app/Export/FullBackupToZip.php b/app/Export/FullBackupToZip.php new file mode 100644 index 00000000..10b218f1 --- /dev/null +++ b/app/Export/FullBackupToZip.php @@ -0,0 +1,56 @@ + $version, + 'date' => Carbon::now()->toJSON(), + 'called_from' => __CLASS__, + ]; + + $zip = new ZipArchive(); + + File::ensureDirectoryExists(storage_path('bar-assistant/backups')); + + $filename = storage_path(sprintf('bar-assistant/backups/%s_%s.zip', Carbon::now()->format('Ymdhi'), 'bass-backup')); + if ($exportPath) { + $filename = $exportPath; + } + + if ($zip->open($filename, ZipArchive::CREATE) !== true) { + $message = sprintf('Error creating zip archive with filepath "%s"', $filename); + $this->log->error($message); + + throw new ExportException($message); + } + + $zip->addGlob(storage_path('bar-assistant/*.sqlite'), options: ['remove_path' => storage_path('bar-assistant')]); + $zip->addGlob(storage_path('bar-assistant/uploads/*/*/*'), options: ['remove_path' => storage_path('bar-assistant')]); + + if ($metaContent = json_encode($meta)) { + $zip->addFromString('_meta.json', $metaContent); + } + + $zip->close(); + + return $filename; + } +}