Enviado em 26/07/2024 - 09:30h
A variável $command no código é equivalente a este comando, e todas as variáveis existem e são recebidas na função corretamente:
public function BackupDatabaseData($tableName = null) {
$dbname = $this->dbname;
$dbserver = $this->dbserver;
$username = $this->dbuser;
$password = $this->dbpass;
// Get the current date and time
$datetime = date('Ymd_His');
// Generate a unique filename with date and time
$backupFile = $tableName ? "{$dbname}_{$tableName}_backup_{$datetime}.sql" : "{$dbname}_backup_{$datetime}.sql";
$zipFile = "{$backupFile}.zip";
// Construct the mysqldump command
$command = "mysqldump --host=$dbserver --user=$username --password='$password' --lock-tables $dbname";
if ($tableName) {
$command .= " $tableName";
}
$command .= " > $backupFile";
// Execute the command
shell_exec($command);
// Check if the backup file was created
if (!file_exists($backupFile)) {
echo "Error: backup file was not created <br><br>";
var_dump(error_get_last());
exit;
}
// Check if file size exceeds a limit (e.g., 20MB)
$fileSize = filesize($backupFile);
$maxSize = 20 * 1024 * 1024; // 20MB
if ($fileSize > $maxSize) {
// Compress the backup file
shell_exec("zip $zipFile $backupFile");
// Send the compressed file for download
header('Content-Type: application/zip');
header("Content-Disposition: attachment; filename=\"$zipFile\"");
readfile($zipFile);
// Remove the temporary files
unlink($backupFile);
unlink($zipFile);
} else {
// Send the backup file for download
header('Content-Type: application/sql');
header("Content-Disposition: attachment; filename=\"$backupFile\"");
readfile($backupFile);
// Remove the temporary file
unlink($backupFile);
}
}
Aprenda a Gerenciar Permissões de Arquivos no Linux
Como transformar um áudio em vídeo com efeito de forma de onda (wave form)
Como aprovar Pull Requests em seu repositório Github via linha de comando
Visualizar arquivos em formato markdown (ex.: README.md) pelo terminal
Dando - teoricamente - um gás no Gnome-Shell do Arch Linux
Como instalar o Google Cloud CLI no Ubuntu/Debian
Mantenha seu Sistema Leve e Rápido com a Limpeza do APT!
Procurando vídeos de YouTube pelo terminal e assistindo via mpv (2025)
Sinto uma leve lentidão ao arrastar, miniminizar e restauras as janela... (3)
Alguém já usou o framework Avalonia para desenvolver interfaces de usu... (4)
Ajuda Pra Melhoria do NFTABLES. (8)
Pastas da raiz foram para a área de trabalho [RESOLVIDO] (7)