数据库备份程序ddump
<?php
$verify='hash';
$dbhost='localhost';
$dbuser='user';
$dbpass='pass';
$dbname='name';
if(!extension_loaded('zlib')){die('no_zlib');}
if(!extension_loaded('pdo_mysql')){die('no_pdo');}
if(!empty($_POST)){
$time=file_exists('ddump.cfg')?file_get_contents('ddump.cfg'):0;file_put_contents('ddump.cfg',time());
if(time()-$time>60 && $_POST['verify']==$verify){
try{$pdo=new PDO('mysql:host='.$dbhost.';dbname='.$dbname,$dbuser,$dbpass);}catch(Exception $e){die('sqlsb');}$pdo->query('SET NAMES utf8');
$dump='#ddump: qiukong.com'."\n";
$tables=$pdo->query('SHOW TABLES FROM '.$dbname)->fetchAll(PDO::FETCH_ASSOC);
foreach($tables as $table){
$dump.='#ddump: '.$table['Tables_in_'.$dbname]."\n";
$stru=$pdo->query('SHOW CREATE TABLE '.$table['Tables_in_'.$dbname])->fetch(PDO::FETCH_ASSOC);
$dump.=$stru['Create Table'].';'."\n";
$rows=$pdo->query('SELECT * FROM `'.$table['Tables_in_'.$dbname].'`');
$cols=$rows->columnCount();
foreach($rows as $arr){
$dump.='INSERT INTO `'.$table['Tables_in_'.$dbname].'` VALUES (';
$sdot='';for($i=0;$i<$cols;$i++){$dump.=$sdot.'"'.addslashes($arr[$i]).'"';$sdot=',';}
$dump.=');'."\n";
}
}
$dump.='#ddump: qiukong.com'."\n";
$file=$dbname.'_'.time().'.gz';
$open=gzopen($file,'w9');
gzwrite($open,$dump);
gzclose($open);
header("Content-Type:application/gz");
header('Content-Disposition:attachment;filename='.$file);
header('Content-Transfer-Encodeing:binary');
header('Pragma:no-cache');
readfile($file);
unlink($file);
die;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
<title>ddump</title>
<style>
html,body{height:90%;text-align:center;}
input{width:60%;height:60px;font-size:36px;text-align:center;border:none;}
.none{height:50%;}
</style>
</head>
<body>
<div class="none"></div>
<form method="post"><input type="password" name="verify" placeholder="ddump" /></form>
</body>
</html>
早啊,聖誕快樂(好像錯過了什麽)
「早啊,聖誕快樂(好像錯過了什麽)」
_(:3 」∠)_
并没有错过什么……
看起来圣诞节什么都没有发生
什么东西???我继续水贴
0.0097939968109131