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);
}
}
Passkeys: A Evolução da Autenticação Digital
Instalação de distro Linux em computadores, netbooks, etc, em rede com o Clonezilla
Título: Descobrindo o IP externo da VPN no Linux
Armazenando a senha de sua carteira Bitcoin de forma segura no Linux
Enviar mensagem ao usuário trabalhando com as opções do php.ini
Como configurar posicionamento e movimento de janelas no Lubuntu (Openbox) com atalhos de teclado
Máquinas Virtuais com IP estático acessando Internet no Virtualbox
Instalar o Microsoft Edge no Slackware 15
Instalando Brave Browser no Linux Mint 22
vídeo pra quem quer saber como funciona Proteção de Memória:
Separar trafego da VPN da VPS (0)
Formatando cartão de memoria que nao formata[AJUDA] (17)
warsaw parou de funcionar após atualização do sistema (solução) (0)
Desde que seja DDR3, posso colocar qualquer memória? [RESOLVIDO] (6)