disk)->path($backup->path); $restorePath = storage_path('app/restore-temp'); if (! file_exists($backupPath)) { throw new Exception(__('domains/system/messages.backup.file_not_found')); } $zip = new ZipArchive; if ($zip->open($backupPath) === true) { $zip->extractTo($restorePath); $zip->close(); $this->restoreDatabase($restorePath); $this->restoreFiles($restorePath); File::deleteDirectory($restorePath); $this->syncBackupCatalog->execute(); } } private function restoreDatabase(string $tempPath): void { $dbDump = $tempPath.'/db-dumps/mysql-'.config('database.connections.mysql.database').'.sql'; if (file_exists($dbDump)) { $restoreSql = Process::run([ 'mysql', '-u', config('database.connections.mysql.username'), '-p'.config('database.connections.mysql.password'), '-h'.config('database.connections.mysql.host'), config('database.connections.mysql.database'), '-e', "source {$dbDump}", ]); if ($restoreSql->failed()) { throw new RuntimeException(__('domains/system/messages.backup.restored_error').' '.$restoreSql->errorOutput()); } } } private function restoreFiles(string $tempPath): void { $uploadsPath = $tempPath.'/storage'; if (file_exists($uploadsPath)) { File::copyDirectory($uploadsPath, storage_path()); } } }