| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 
 |  
 
<?php
$host = "localhost"; 
$user = "root";
$pass = ""; // On définit les infos de la base de données
$db = "hotellerie1";
$date = date("d-m-Y"); // On définit le variable $date (ici, son format)
 
$backup = $db."bdd-backup_".$date.".sql.gz";
// Utilise les fonctions système : MySQLdump & GZIP pour générer un backup gzipé
$command = "mysqldump -u $user -p$pass --opt $db -h $host |gzip > $backup";
system($command);
// Démarre la procédure de téléchargement
$taille = filesize($backup);
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: application/gzip");
header("Content-Disposition: attachment; filename=$backup;");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$taille);
@readfile($backup);
// Supprime le fichier temporaire du serveur
unlink($backup);
?> | 
Partager