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);
}
}
Servidor de Backup com Ubuntu Server 24.04 LTS, RAID e Duplicati (Dell PowerEdge T420)
Visualizar câmeras IP ONVIF no Linux sem necessidade de instalar aplicativos
Atualizar Debian Online de uma Versão para outra
Instalar driver Nvidia no Debian 13
Redimensionando, espelhando, convertendo e rotacionando imagens com script
Debian 13 Trixie para Iniciantes
Convertendo pacotes DEB que usam ZSTD (Padrão Novo) para XZ (Padrão Antigo)
baschrc customizado pegeui vários. (3)
Rust é o "C da nossa geração"? (8)