Kaydet (Commit) e80a2306 authored tarafından Ali GOREN's avatar Ali GOREN

Add Files

üst f251d688
Options +FollowSymlinks
Options -Indexes
RewriteEngine On
RewriteBase /backup/
RewriteRule ^error$ error.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^do/(.*)$ fd.php?f=download/$1
# RewriteRule ^ index.php [QSA,L]
ErrorDocument 404 /backup/error
<html>
<head>
<title>File Not Found!</title>
<meta charset="utf-8">
<!-- Latest compiled and minified CSS & JS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<script src="//code.jquery.com/jquery.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script type="text/javascript" src="js/main.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<h1>ERROR</h1>
<p><span>File Not Found!</span></p>
<hr class="small">
<p><span>Return <a href="/backup">Home</a></span></p>
</div>
</div>
</div>
</body>
</html>
\ No newline at end of file
<?php
$f = $_GET['f'];
$f_ex = explode('.', $f);
$f_ex = end($f_ex);
if ($f_ex === "zip") {
if ($f and file_exists($f))
{
header('Content-Description: File Transfer');
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename='.basename($f));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($f));
ob_clean();
flush();
if (readfile($f))
{
unlink($f);
}
} else {
header('Location: ../error');
}
} else {
header('Location: ../error');
}
?>
\ No newline at end of file
<html>
<head>
<title>MySQL Database Backup Tool</title>
<meta charset="utf-8">
<!-- Latest compiled and minified CSS & JS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<script src="//code.jquery.com/jquery.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script type="text/javascript" src="js/main.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<form id="frmYedekle" method="POST" role="form" onsubmit="return false;" autocomplete="off">
<legend>MySQL Database Backup Tool</legend>
<div class="form-group">
<label for="">MySQL Host</label>
<input name="host" type="text" class="form-control" id="" placeholder="localhost">
</div>
<div class="form-group">
<label for="">MySQL Port</label>
<input name="port" type="text" class="form-control" id="" placeholder="3306">
</div>
<div class="form-group">
<label for="">MySQL User</label>
<input name="dbuser" type="text" class="form-control" id="" placeholder="root">
</div>
<div class="form-group">
<label for="">MySQL User Password</label>
<input name="dbpass" type="password" class="form-control" id="" placeholder="Enter your password">
</div>
<div class="form-group">
<label for="">MySQL Database</label>
<input name="db" type="text" class="form-control" id="" placeholder="test">
</div>
<button type="submit" class="btn btn-primary" onclick="$.btnYedekle()">Backup Now</button>
</form>
<span class="msgShow"></span>
</div>
</div>
</div>
</body>
</html>
\ No newline at end of file
$(function() {
$.btnYedekle = function() {
/*
serialize fonksiyonu ile formda post edilen tüm ögeler alınır.
form#frmLogin kullanıldığı formdaki frmLogin id'sine sahip form'un verilerini seçtirir.
dataType json olması bizim için daha işe yarar.
success ile post ajax işlemi başarılı ise olacakları belirttik.
istek sonucu gelen cevabı yazdırdık.
timeout ile belirtilen timeout'a dek ajax çağrısı sonuçlanmazsa hata var demektir. bunun kontrolünü yapabiliriz.
post.php kısmında kullanılan sleep(2) fonksiyonu da 2 saniye bekletiyor. yani 2 yerine 3 saniye olursa çağrı sonlanır ve dilersek bir hata yazdırabiliriz.
*/
var params = $("form#frmYedekle").serialize();
$.ajax({
url: "run.php",
type: "POST",
data: params,
dataType: "json",
/*timeout: 3000,*/
success: function(cevap) {
if (cevap.msgOk) {
$(".msgShow").html('<p class="bg-success">Database Backup Successfully: <a href="do/'+cevap.msgOk+'" target="_blank">Download Backup</a></p>');
} else {
$(".msgShow").html('<p class="bg-danger">ERROR: Check your database info</p>');
}
}
});
}
});
\ No newline at end of file
# MySQL Database Backup Tool
Backup Class by [MYAZARC](http://myazarc.com/)
##### Techs: PDO, Jquery
##### NOTICE: ( !!Backup file delete system after download!! )
------------------------------
Yedekleme yapar. Tabloyu belirtirsiniz o tablonun yedeğini alır ve Download Backup linkine tıklayınca indirme işlemi yapar.
##### Teknolojiler: PDO, Jquery
##### UYARI: ( !!İndirme işleminden sonra backup dosyası sistemden silinir.!! )
# Screenshot
![Mysql Database Backup Tool](screenshot.PNG)
\ No newline at end of file
<?php
error_reporting(0);
header('content-type:text/html; charset=utf-8');
ob_start();
if (!function_exists('boolval')) {
function boolval($in, $strict = false) {
$out = null;
$in = (is_string($in) ? strtolower($in) : $in);
// if not strict, we only have to check if something is false
if (in_array($in, array('false', 'no', 'n', '0', 'off', false, 0), true) || !$in) {
$out = false;
} else if ($strict) {
// if strict, check the equivalent true values
if (in_array($in, array('true', 'yes', 'y', '1', 'on', true, 1), true)) {
$out = true;
}
} else {
// not strict? let the regular php bool check figure it out (will
// largely default to true)
$out = ($in ? true : false);
}
return $out;
}
}
class Backup {
private $host = '';
private $user = '';
private $name = '';
private $pass = '';
private $port = '';
private $tables;
private $db;
private $ds = "\n";
public function __construct($host = NULL, $user = NULL, $name = NULL, $pass = NULL, $tables = array('*'), $port = 3306) {
try {
if ($host !== NULL) {
$this->host = $host;
$this->name = $name;
$this->port = $port;
$this->pass = $pass;
$this->user = $user;
}
$this->db = new PDO('mysql:host=' . $this->host . ';dbname=' . $this->name . '; port=' . $port, $this->user, $this->pass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
$this->tables = $tables;
} catch (Exception $exc) {
$this->show_err('Connection Error', $exc->getMessage());
exit();
}
$this->db->exec('SET NAMES "utf8"');
}
public function backup($backUpdir = 'download/') {
$sql=$this->_init();
$zip = new ZipArchive();
$date=date('d.m.Y-H.i.s');
$filename = $backUpdir."backup-$this->name-$date.zip";
if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) {
exit("Could not open <$filename>\n");
}
$zip->addFromString("backup-$this->name-$date.sql", $sql);
$zip->close();
}
private function _init() {
$data = '';
$ds = '<br>';
ob_flush();
flush();
ob_flush();
flush();
if (in_array('*', $this->tables)) {
$tables = $this->_getTables();
} else {
$this->show_err('Table doesn\'t exists.', 'Table doesn\'t exists.');
}
ob_flush();
flush();
ob_flush();
flush();
$ret["msgOk"] = "";
foreach ($tables as $c) {
//$ret["msg"] .= 'Initializing <strong>' . $c . '</strong> table fields...' . $ds;
ob_flush();
flush();
$fields = $this->_getTableFields($c);
//$ret["msg"] .= 'Initializing <strong>' . $c . '</strong> table create sql...' . $ds;
ob_flush();
flush();
$createtables = $this->_getCreateTables($c);
//$ret["msg"] .= 'Initializing <strong>' . $c . '</strong> table insert sql...' . $ds;
ob_flush();
flush();
$insert = $this->_createInsertSql($c, $fields);
//$ret["msg"] .= 'Merging sqls...' . $ds;
ob_flush();
flush();
$data.=$createtables[1] . $this->ds . $this->ds . $insert . $this->ds . $this->ds ;
$date=date('d.m.Y-H.i.s');
$filename = "backup-$this->name-$date.zip";
$ret["msgOk"] = $filename;
ob_flush();
flush();
}
echo json_encode($ret);
return $data;
}
private function _getTables($param = TRUE) {
$tableList = array();
if ($param === TRUE) {
$result = $this->db->query("SHOW TABLES");
while ($row = $result->fetch(PDO::FETCH_NUM)) {
$tableList[] = $row[0];
}
}
return $tableList;
}
private function _getCreateTables($param) {
$w = $param;
$result = $this->db->query("SHOW CREATE TABLE $w");
$row = $result->fetch(PDO::FETCH_NUM);
return $row;
}
private function _getTableFields($tablename) {
$column = array();
$select = $this->db->query("SELECT * FROM $tablename LIMIT 1");
$total_column = $select->columnCount();
for ($counter = 0; $counter < $total_column; $counter ++) {
$meta = $select->getColumnMeta($counter);
$column[] = $meta['name'];
}
return $column;
}
private function _createInsertSql($tablename, $fields) {
$sql = "select `" . rtrim(implode('`, `', $fields), ', `') . "` from $tablename";
$data = $this->basicQuery($sql);
$insert = '';
$insert.="INSERT INTO `$tablename` (`" . rtrim(implode('`, `', $fields), ', `') . "`) VALUES" . $this->ds;
foreach ($data as $q) {
$insert.='(';
foreach ($fields as $m) {
$insert.="'" . $q->$m . "',";
}
$insert = rtrim($insert, ',');
$insert.='),' . $this->ds;
}
$insert = rtrim(rtrim($insert, $this->ds), ',') . ';' . $this->ds;
return $insert;
}
private function basicQuery($sql) {
$result = array();
$query = $this->db->query($sql);
$this->queryStatus = boolval($query);
if ($this->queryStatus) {
if ($query->rowCount()) {
foreach ($query as $w) {
$result[] = (object) $w;
} // foreach query end;
}
} else {
$this->show_err($sql, $this->db->errorInfo());
} // if query end;
return $result;
}
public function show_err($sql, $sqlerr) {
$ret["msgErr"] = "HATA: Veritabanı Bilgilerinizi Kontrol Edin";
echo json_encode($ret);
}
}
ob_end_flush();
$host = $_POST[host];
$user = $_POST[dbuser];
$db = $_POST[db];
$pass = $_POST[dbpass];
$port = $_POST[port];
$back = new Backup($host,$user,$db,$pass,["*"],$port);
$back->backup();
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment