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
Quebra de linha na data e hora no Linux Mint
Organizando seus PDF com o Zotero
tentando instalar em um notebook antigo o Linux LegacyOS_2023... [RESO... (9)
Problema com Conexão Outlook via Firewall (OpenSUSE) com Internet Fibr... (5)