国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

sys_data_done.php 11KB

il y a 3 ans
il y a 2 ans
il y a 3 ans
il y a 2 ans
il y a 3 ans
il y a 2 ans
il y a 3 ans
il y a 3 ans
il y a 3 ans
il y a 3 ans
il y a 2 ans
il y a 3 ans
il y a 2 ans
il y a 3 ans
il y a 1 an
il y a 3 ans
il y a 3 ans
il y a 3 ans
il y a 3 ans
il y a 2 ans
il y a 3 ans
il y a 3 ans
il y a 2 ans
il y a 3 ans
il y a 3 ans
il y a 3 ans
il y a 1 an
il y a 3 ans
il y a 2 ans
il y a 3 ans
il y a 2 ans
il y a 3 ans
il y a 2 ans
il y a 3 ans
il y a 2 ans
il y a 3 ans
il y a 2 ans
il y a 3 ans
il y a 3 ans
il y a 3 ans
il y a 2 ans
il y a 3 ans
il y a 1 an
il y a 3 ans
il y a 2 ans
il y a 3 ans
il y a 2 ans
il y a 3 ans
il y a 2 ans
il y a 3 ans
il y a 3 ans
il y a 2 ans
il y a 3 ans
il y a 1 an
il y a 3 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <?php
  2. /**
  3. * 数据库备份还原操作
  4. *
  5. * @version $id:sys_data_done.php 17:19 2010年7月20日 tianya $
  6. * @package DedeBIZ.Administrator
  7. * @copyright Copyright (c) 2022 DedeBIZ.COM
  8. * @license GNU GPL v2 (https://www.dedebiz.com/license)
  9. * @link https://www.dedebiz.com
  10. */
  11. @ob_start();
  12. @set_time_limit(0);
  13. ini_set('memory_limit', '-1');
  14. require_once(dirname(__FILE__).'/config.php');
  15. if (DEDEBIZ_SAFE_MODE) {
  16. die(DedeAlert("系统已启用安全模式,无法使用当前功能",ALERT_DANGER));
  17. }
  18. CheckPurview('sys_Data');
  19. if (empty($dopost)) $dopost = '';
  20. $bkdir = DEDEDATA.'/'.$cfg_backup_dir;
  21. //跳转一下页的js
  22. $gotojs = "function GotoNextPage(){document.gonext."."submit();}"."\r\nset"."Timeout('GotoNextPage()',500);";
  23. $dojs = "<script>$gotojs</script>";
  24. //备份数据
  25. if ($dopost == 'bak') {
  26. if (empty($tablearr)) {
  27. ShowMsg('您还没选择备份数据表', 'javascript:;');
  28. exit();
  29. }
  30. if (!is_dir($bkdir)) {
  31. MkdirAll($bkdir, $cfg_dir_purview);
  32. }
  33. //初始化使用到的变量
  34. $tables = explode(',', $tablearr);
  35. if (!isset($isstruct)) {
  36. $isstruct = 0;
  37. }
  38. if (!isset($startpos)) {
  39. $startpos = 0;
  40. }
  41. if (!isset($iszip)) {
  42. $iszip = 0;
  43. }
  44. if (empty($nowtable)) {
  45. $nowtable = '';
  46. }
  47. if (empty($fsize)) {
  48. $fsize = 2048;
  49. }
  50. $fsizeb = $fsize * 1024;
  51. //第一页的操作
  52. if ($nowtable == '') {
  53. $tmsg = '';
  54. $dh = dir($bkdir);
  55. while ($filename = $dh->read()) {
  56. if (!preg_match("#txt$#", $filename)) {
  57. continue;
  58. }
  59. $filename = $bkdir."/$filename";
  60. if (!is_dir($filename)) {
  61. unlink($filename);
  62. }
  63. }
  64. $dh->close();
  65. $tmsg .= "完成备份目录旧数据清理";
  66. if ($isstruct == 1) {
  67. $bkfile = $bkdir."/tables_struct_".substr(md5(time().mt_rand(1000, 6000).$cfg_cookie_encode), 0, 16).".txt";
  68. $mysql_version = $dsql->GetVersion();
  69. $fp = fopen($bkfile, "w");
  70. foreach ($tables as $t) {
  71. fwrite($fp, "DROP TABLE IF EXISTS `$t`;\r\n");
  72. $dsql->SetQuery("SHOW CREATE TABLE `".$dsql->dbName."`.".$t); //感谢:LandQ
  73. $dsql->Execute('me');
  74. $row = $dsql->GetArray('me', MYSQL_BOTH);
  75. //去除AUTO_INCREMENT
  76. $row[1] = preg_replace("#AUTO_INCREMENT=([0-9]{1,})[\r\n]{1,}#i", "", $row[1]);
  77. //4.1以下版本备份为低版本
  78. if ($datatype == 4.0 && $mysql_version > 4.0) {
  79. $eng1 = "#ENGINE=MyISAM[\r\n]{1,}DEFAULT[\r\n]{1,}CHARSET=".$cfg_db_language."#i";
  80. $tableStruct = preg_replace($eng1, "TYPE=MyISAM", $row[1]);
  81. }
  82. //4.1以下版本备份为高版本
  83. else if ($datatype == 4.1 && $mysql_version < 4.1) {
  84. $eng1 = "#ENGINE=MyISAM DEFAULT CHARSET={$cfg_db_language}#i";
  85. $tableStruct = preg_replace("TYPE=MyISAM", $eng1, $row[1]);
  86. }
  87. //普通备份
  88. else {
  89. $tableStruct = $row[1];
  90. }
  91. fwrite($fp,''.$tableStruct.";\r\n");
  92. }
  93. fclose($fp);
  94. $tmsg .= "完成备份数据表结构信息";
  95. }
  96. $tmsg .= "正在进行数据备份初始化工作,请稍后";
  97. $doneForm = "<form name='gonext' method='post' action='sys_data_done.php'>
  98. <input type='hidden' name='isstruct' value='$isstruct'>
  99. <input type='hidden' name='dopost' value='bak'>
  100. <input type='hidden' name='fsize' value='$fsize'>
  101. <input type='hidden' name='tablearr' value='$tablearr'>
  102. <input type='hidden' name='nowtable' value='{$tables[0]}'>
  103. <input type='hidden' name='startpos' value='0'>
  104. <input type='hidden' name='iszip' value='$iszip'>\r\n</form>\r\n{$dojs}\r\n";
  105. PutInfo($tmsg, $doneForm);
  106. exit();
  107. }
  108. //执行分页备份
  109. else {
  110. $j = 0;
  111. $fs = array();
  112. $bakStr = '';
  113. //分析表里的字段信息
  114. $nowtable = str_replace("`", "", $nowtable);
  115. if (!$dsql->IsTable($nowtable)) {
  116. PutInfo("数据表名称错误", "");
  117. exit();
  118. }
  119. $dsql->GetTableFields($nowtable);
  120. $intable = "INSERT INTO `$nowtable` VALUES(";
  121. while ($r = $dsql->GetFieldObject()) {
  122. $fs[$j] = trim($r->name);
  123. $j++;
  124. }
  125. $fsd = $j - 1;
  126. //读取表的文档
  127. $dsql->SetQuery("SELECT * FROM `$nowtable`");
  128. $dsql->Execute();
  129. $m = 0;
  130. $bakfilename = "$bkdir/{$nowtable}_{$startpos}_".substr(md5(time().mt_rand(1000, 6000).$cfg_cookie_encode), 0, 16).".txt";
  131. while ($row2 = $dsql->GetArray()) {
  132. if ($m < $startpos) {
  133. $m++;
  134. continue;
  135. }
  136. //检测数据是否达到规定大小
  137. if (strlen($bakStr) > $fsizeb) {
  138. $fp = fopen($bakfilename, "w");
  139. fwrite($fp, $bakStr);
  140. fclose($fp);
  141. $tmsg = "正在备份{$m}条数据,继续备份{$nowtable}";
  142. $doneForm = "<form name='gonext' method='post' action='sys_data_done.php'>
  143. <input type='hidden' name='isstruct' value='$isstruct'>
  144. <input type='hidden' name='dopost' value='bak'>
  145. <input type='hidden' name='fsize' value='$fsize'>
  146. <input type='hidden' name='tablearr' value='$tablearr'>
  147. <input type='hidden' name='nowtable' value='$nowtable'>
  148. <input type='hidden' name='startpos' value='$m'>
  149. <input type='hidden' name='iszip' value='$iszip'>\r\n</form>\r\n{$dojs}\r\n";
  150. PutInfo($tmsg, $doneForm);
  151. exit();
  152. }
  153. //正常情况
  154. $line = $intable;
  155. for ($j = 0; $j <= $fsd; $j++) {
  156. if ($j < $fsd) {
  157. $line .= "'".RpLine(addslashes($row2[$fs[$j]]))."',";
  158. } else {
  159. $line .= "'".RpLine(addslashes($row2[$fs[$j]]))."');\r\n";
  160. }
  161. }
  162. $m++;
  163. $bakStr .= $line;
  164. }
  165. //如果数据比卷设置值小
  166. if ($bakStr != '') {
  167. $fp = fopen($bakfilename, "w");
  168. fwrite($fp, $bakStr);
  169. fclose($fp);
  170. }
  171. for ($i = 0; $i < count($tables); $i++) {
  172. if ($tables[$i] == $nowtable) {
  173. if (isset($tables[$i + 1])) {
  174. $nowtable = $tables[$i + 1];
  175. $startpos = 0;
  176. break;
  177. } else {
  178. PutInfo("成功完成所有数据备份", "");
  179. exit();
  180. }
  181. }
  182. }
  183. $tmsg = "正在备份{$m}条数据,继续备份{$nowtable}";
  184. $doneForm = "<form name='gonext' method='post' action='sys_data_done.php?dopost=bak'>
  185. <input type='hidden' name='isstruct' value='$isstruct'>
  186. <input type='hidden' name='fsize' value='$fsize'>
  187. <input type='hidden' name='tablearr' value='$tablearr'>
  188. <input type='hidden' name='nowtable' value='$nowtable'>
  189. <input type='hidden' name='startpos' value='$startpos'>\r\n</form>\r\n{$dojs}\r\n";
  190. PutInfo($tmsg, $doneForm);
  191. exit();
  192. }
  193. //分页备份代码结束
  194. }
  195. //还原数据
  196. else if ($dopost == 'redat') {
  197. if ($bakfiles == '') {
  198. ShowMsg('您还没选择还原数据表', 'javascript:;');
  199. exit();
  200. }
  201. $bakfilesTmp = $bakfiles;
  202. $bakfiles = explode(',', $bakfiles);
  203. if (empty($structfile)) {
  204. $structfile = '';
  205. }
  206. if (empty($delfile)) {
  207. $delfile = 0;
  208. }
  209. if (empty($startgo)) {
  210. $startgo = 0;
  211. }
  212. if ($startgo == 0 && $structfile != '') {
  213. $tbdata = '';
  214. $fp = fopen("$bkdir/$structfile", 'r');
  215. while (!feof($fp)) {
  216. $tbdata .= fgets($fp, 1024);
  217. }
  218. fclose($fp);
  219. $querys = explode(';', $tbdata);
  220. foreach ($querys as $q) {
  221. $q = preg_replace("#TYPE=MyISAM#i","ENGINE=MyISAM DEFAULT CHARSET=".$cfg_db_language, $q);
  222. $rs = $dsql->ExecuteNoneQuery(trim($q).';');
  223. }
  224. if ($delfile == 1) {
  225. @unlink("$bkdir/$structfile");
  226. }
  227. $tmsg = "成功完成数据表还原,继续还原其它数据";
  228. $doneForm = "<form name='gonext' method='post' action='sys_data_done.php?dopost=redat'>
  229. <input type='hidden' name='startgo' value='1'>
  230. <input type='hidden' name='delfile' value='$delfile'>
  231. <input type='hidden' name='bakfiles' value='$bakfilesTmp'>
  232. </form>\r\n{$dojs}\r\n";
  233. PutInfo($tmsg, $doneForm);
  234. exit();
  235. } else {
  236. $nowfile = $bakfiles[0];
  237. $bakfilesTmp = preg_replace("#".$nowfile."[,]{0,1}#", "", $bakfilesTmp);
  238. $oknum = 0;
  239. if (filesize("$bkdir/$nowfile") > 0) {
  240. $fp = fopen("$bkdir/$nowfile", 'r');
  241. while (!feof($fp)) {
  242. $line = trim(fgets($fp, 512 * 1024));
  243. if ($line == "") continue;
  244. $rs = $dsql->ExecuteNoneQuery($line);
  245. if ($rs) $oknum++;
  246. }
  247. fclose($fp);
  248. }
  249. if ($delfile == 1) {
  250. @unlink("$bkdir/$nowfile");
  251. }
  252. if ($bakfilesTmp == "") {
  253. ShowMsg('成功还原所有数据', 'javascript:;');
  254. exit();
  255. }
  256. $tmsg = "正在还原{$nowfile}文件{$oknum}条数据,继续还原其它数据";
  257. $doneForm = "<form name='gonext' method='post' action='sys_data_done.php?dopost=redat'>
  258. <input type='hidden' name='startgo' value='1'>
  259. <input type='hidden' name='delfile' value='$delfile'>
  260. <input type='hidden' name='bakfiles' value='$bakfilesTmp'>
  261. </form>\r\n{$dojs}\r\n";
  262. PutInfo($tmsg, $doneForm);
  263. exit();
  264. }
  265. }
  266. function PutInfo($msg1, $msg2)
  267. {
  268. global $cfg_soft_lang;
  269. $msginfo = "<!DOCTYPE html><html><head><meta charset='utf-8'><meta http-equiv='X-UA-Compatible' content='IE=Edge,chrome=1'><meta name='viewport' content='width=device-width,initial-scale=1'><title>系统提示</title><link rel='stylesheet' href='/static/web/css/bootstrap.min.css'><link rel='stylesheet' href='/static/web/css/admin.css'></head><base target='_self'><body><div class='tips'><div class='tips-box'><div class='tips-head'><p>系统提示</p></div><div class='tips-body'>{$msg1}{$msg2}</div></div></div>";
  270. echo $msginfo."</body></html>";
  271. }
  272. function RpLine($str)
  273. {
  274. $str = str_replace("\r", "\\r", $str);
  275. $str = str_replace("\n", "\\n", $str);
  276. return $str;
  277. }
  278. ?>