<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Veritabanı Yedekleme</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f9;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.container {
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
text-align: center;
}
h1 {
color: #333;
margin-bottom: 20px;
}
.backup-button {
background-color: #28a745;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s ease;
}
.backup-button:hover {
background-color: #218838;
}
.backup-button:active {
background-color: #1e7e34;
}
.message {
margin-top: 20px;
color: #333;
font-size: 14px;
}
</style>
</head>
<body>
<div class="container">
<h1>Veritabanı Yedekleme</h1>
<form method="post">
<button type="submit" name="backup" class="backup-button">Yedek Al</button>
</form>
<div class="message">
<?php
if (isset($_POST['backup'])) {
// Veritabanı Bağlantı Bilgileri
$host = 'localhost';
$user = 'kullanici_adi';
$password = 'parola';
$database = 'veritabani_adi';
// Yedek dosyası ismi
$backup_file = $database . '_' . date('Y-m-d_H-i-s') . '.sql';
// Veritabanına bağlan
$conn = mysqli_connect($host, $user, $password, $database);
// Bağlantı kontrolü
if (!$conn) {
die("Veritabanı bağlantısı başarısız: " . mysqli_connect_error());
}
// Tabloları al
$tables = array();
$result = mysqli_query($conn, "SHOW TABLES");
while ($row = mysqli_fetch_row($result)) {
$tables[] = $row[0];
}
// Yedek içeriğini oluştur
$content = "";
foreach ($tables as $table) {
// Tablo yapısını al
$result = mysqli_query($conn, "SHOW CREATE TABLE $table");
$row = mysqli_fetch_row($result);
$content .= "\n\n" . $row[1] . ";\n\n";
// Tablo verilerini al
$result = mysqli_query($conn, "SELECT * FROM $table");
$num_fields = mysqli_num_fields($result);
while ($row = mysqli_fetch_row($result)) {
$content .= "INSERT INTO $table VALUES(";
for ($i = 0; $i < $num_fields; $i++) {
$row[$i] = addslashes($row[$i]);
$row[$i] = str_replace("\n", "\\n", $row[$i]);
if (isset($row[$i])) {
$content .= '"' . $row[$i] . '"';
} else {
$content .= 'NULL';
}
if ($i < ($num_fields - 1)) {
$content .= ',';
}
}
$content .= ");\n";
}
$content .= "\n";
}
// Yedek dosyasını kaydet
$handle = fopen($backup_file, 'w+');
fwrite($handle, $content);
fclose($handle);
// Yedek dosyasını indir
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($backup_file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($backup_file));
readfile($backup_file);
// Dosyayı sunucudan sil (isteğe bağlı)
unlink($backup_file);
// Bağlantıyı kapat
mysqli_close($conn);
echo "Yedekleme başarıyla tamamlandı ve dosya indirildi.";
}
?>
</div>
</div>
</body>
</html>