Page 1 of 1

Backup of mysql

Posted: Fri Dec 03, 2010 8:23 am
by Oliveira - Uibaí-Ba - Brazil

the file is written out of the web server and then read with readfile and available for download

##backup.php"##
<?php
session_start();
$usuario_backup = $_SESSION[USER_NAME];
$file = $usuario_backup.".".sql;
system("mysqldump.exe --user $usuario_backup -pUser_Password_Database --databases $usuario_backup > d:\bkp/$usuario_backup.sql");

header('Content-Description: File Transfer');
header('Content-Type: application/sql');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: text');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile(\'d:\bkp\\'\.$file);
?>
as I am in windows, I had to copy the mysqldump.exe to the folder with the backup.php

It is assumed that was logged in a separate table by putting the username in the session.
assumed to have a bench in mysql with the same name used in the User login and User in mysql with the same name of the bank and with the necessary privileges on it.


Re: Backup of mysql

Posted: Sat Dec 04, 2010 9:21 am
by Oliveira

For linux
backup.php
<?php
session_start();
$usuario_backup = $_SESSION[EW_SESSION_USER_NAMES];
system("mysqldump --user $usuario_backup -senha --databases $usuario_backup > /home/olive/bkp/$usuario_backup.sql");
system("zip -9 /home/olive/bkp/$usuario_backup.zip /home/olive/bkp/$usuario_backup.sql | rm /home/olive/bkp/$usuario_backup.sql");
header ("Location: backup2.php");
?>

backup2.php
<?php
session_start();
$usuario_backup = $_SESSION[EW_SESSION_USER_NAMES];
$file = $usuario_backup.".".zip;
header('Content-Description: File Transfer');
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile(\'/home/olive/bkp//'\.$file);
?>


Re: Backup of mysql

Posted: Sun Jan 25, 2015 2:09 pm
by nyukuri

Hello Oliveira,

I read your script about creating a backup of the database. It looks like the windows version creates a simple sql file while your linux version creates a zipped file.
How do I have to change your code to get also a zipped backup in windows?
Thank you!


Re: Backup of mysql

Posted: Fri Feb 13, 2015 6:16 am
by oliveira

You just have to research how to compress the file from the command line in Windows, then run system replacing the zip compression program:
https://technet.microsoft.com/en-us/lib ... 90884.aspx


Re: Backup of mysql

Posted: Thu Jul 02, 2015 12:48 am
by mpol_ch

Hallo Oliveira

Can I use this code in "Custom File" (V11)? If yes, could you please give some informtation howto?

thanks
mpol_ch