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);
}
}
tux-gpt - Assistente de IA para o Terminal
Instalação e configuração do Chrony
Programa IRPF - Guia de Instalação e Resolução de alguns Problemas
Instalando o Team Viewer no Debian Trixie - problema no Policykit
O Que Fazer Após Instalar Ubuntu 25.04
O Que Fazer Após Instalar Fedora 42
Debian 12 -- Errata - Correções de segurança
Instalando o Pi-Hole versão v5.18.4 depois do lançamento da versão v6.0
Não consigo acessar servidores a partir da LAN (0)
Pra quem contribui com artigos e dicas (7)
Alguém poderia me ajudar a escolher peças pra montar um desktop? (27)
Meu PC perde o boot de várias distros Linux após ficar desligado (2)