" . escapeshellarg($sqlDumpFilePath); if (empty($password)) { $command = "mysqldump --user={$userName} --host={$host} {$databaseName} > " . escapeshellarg($sqlDumpFilePath); } exec($command); $zip = new ZipArchive; if ($zip->open($backupFilePath, ZipArchive::CREATE) === TRUE) { // Add DB dump if (file_exists($sqlDumpFilePath)) { $zip->addFile($sqlDumpFilePath, 'database.sql'); } // Add documents specifically searching the local disk $allFiles = Storage::disk('local')->allFiles(); foreach ($allFiles as $filePath) { $fullPath = Storage::disk('local')->path($filePath); // The zip structure will have a folder 'storage_files' containing the relative path $zip->addFile($fullPath, 'storage_files/' . $filePath); } $zip->close(); } if (file_exists($sqlDumpFilePath)) { unlink($sqlDumpFilePath); } if (file_exists($backupFilePath)) { return response()->download($backupFilePath)->deleteFileAfterSend(true); } return back()->with('error', 'Erreur lors de la création de la sauvegarde.'); } }