⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tools.php

📁 论坛代码网增加免费空间业务
💻 PHP
📖 第 1 页 / 共 5 页
字号:
		"<li>只能恢复存放在服务器(远程或本地)上的数据文件,如果您的数据不在服务器上,请用 FTP 上传</li>".
		"<li>数据文件必须为 Discuz! 导出格式,并设置相应属性使 PHP 能够读取</li>".
		"<li>请尽量选择服务器空闲时段操作,以避免超时.如程序长久(超过 10 分钟)不反应,请刷新</b></li></ul>";

	if($file) {
		if(strtolower(substr($file, 0, 7)) == "http://") {
			echo "从远程数据库恢复数据 - 读取远程数据:<br><br>";
			echo "从远程服务器读取文件 ... ";

			$sqldump = @fread($fp, 99999999);
			@fclose($fp);
			if($sqldump) {
				echo "成功<br><br>";
			} elseif (!$multivol) {
				cexit("失败<br><br><b>无法恢复数据</b>");
			}
		} else {
			echo "从本地恢复数据 - 检查数据文件:<br><br>";
			if(file_exists($file)) {
				echo "数据文件 $file 存在检查 ... 成功<br><br>";
			} elseif (!$multivol) {
				cexit("数据文件 $file 存在检查 ... 失败<br><br><br><b>无法恢复数据</b>");
			}

			if(is_readable($file)) {
				echo "数据文件 $file 可读检查 ... 成功<br><br>";
				@$fp = fopen($file, "r");
				@flock($fp, 3);
				$sqldump = @fread($fp, filesize($file));
				@fclose($fp);
				echo "从本地读取数据 ... 成功<br><br>";
			} elseif (!$multivol) {
				cexit("数据文件 $file 可读检查 ... 失败<br><br><br><b>无法恢复数据</b>");
			}
		}

		if($multivol && !$sqldump) {
			cexit("分卷备份范围检查 ... 成功<br><br><b>恭喜您,数据已经全部成功恢复!安全起见,请务必删除本程序.</b>");
		}

		echo "数据文件 $file 格式检查 ... ";
		@list(,,,$method, $volume) = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", preg_replace("/^(.+)/", "\\1", substr($sqldump, 0, 256)))));
		if($method == 'multivol' && is_numeric($volume)) {
			echo "成功<br><br>";
		} else {
			cexit("失败<br><br><b>数据非 Discuz! 分卷备份格式,无法恢复</b>");
		}

		if($onlysave == "yes") {
			echo "将数据文件保存到本地服务器 ... ";
			$filename = DISCUZ_ROOT.'./forumdata'.strrchr($file, "/");
			@$filehandle = fopen($filename, "w");
			@flock($filehandle, 3);
			if(@fwrite($filehandle, $sqldump)) {
				@fclose($filehandle);
				echo "成功<br><br>";
			} else {
				@fclose($filehandle);
				die("失败<br><br><b>无法保存数据</b>");
			}
			echo "成功<br><br><b>恭喜您,数据已经成功保存到本地服务器 <a href=\"".strstr($filename, "/")."\">$filename</a>.安全起见,请务必删除本程序.</b>";
		} else {
			$sqlquery = splitsql($sqldump);
			echo "拆分操作语句 ... 成功<br><br>";
			unset($sqldump);

			echo "正在恢复数据,请等待 ... <br><br>";
			foreach($sqlquery as $sql) {
				if(trim($sql)) {
					$db->query($sql);
					//echo "$sql<br>";
				}
			}
		if($auto == 'off'){
			$nextfile = str_replace("-$volume.sql", '-'.($volume + 1).'.sql', $file);
			cexit("数据文件 <b>$volume#</b> 恢复成功,如果有需要请继续恢复其他卷数据文件<br>请点击<b><a href=\"?action=restore&file=$nextfile&multivol=yes\">全部恢复</a></b>	或许单独恢复下一个数据文件<b><a href=\"?action=restore&file=$nextfile&multivol=yes&auto=off\">单独恢复下一数据文件</a></b>");
		} else {
			$nextfile = str_replace("-$volume.sql", '-'.($volume + 1).'.sql', $file);
			echo "数据文件 <b>$volume#</b> 恢复成功,现在将自动导入其他分卷备份数据.<br><b>请勿关闭浏览器或中断本程序运行</b>";
			redirect("?action=restore&file=$nextfile&multivol=yes");
		}
		}
	} else {
			$exportlog = array();
			if(is_dir(DISCUZ_ROOT.'./forumdata')) {
				$dir = dir(DISCUZ_ROOT.'./forumdata');
				while($entry = $dir->read()) {
					$entry = "./forumdata/$entry";
					if(is_file($entry) && preg_match("/\.sql/i", $entry)) {
						$filesize = filesize($entry);
						$fp = fopen($entry, 'rb');
						$identify = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", fgets($fp, 256))));
						fclose ($fp);
							if(preg_match("/\-1.sql/i", $entry) || $identify[3] == 'shell'){
								$exportlog[$identify[0]] = array(	'version' => $identify[1],
													'type' => $identify[2],
													'method' => $identify[3],
													'volume' => $identify[4],
													'filename' => $entry,
													'size' => $filesize);
							}
					} elseif (is_dir($entry) && preg_match("/backup\_/i", $entry)) {
						$bakdir = dir($entry);
							while($bakentry = $bakdir->read()) {
								$bakentry = "$entry/$bakentry";
								if(is_file($bakentry)){
									$fp = fopen($bakentry, 'rb');
									$bakidentify = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", fgets($fp, 256))));
									fclose ($fp);
									if(preg_match("/\-1\.sql/i", $bakentry) || $bakidentify[3] == 'shell') {
										$identify['bakentry'] = $bakentry;
									}
								}
							}
							if(preg_match("/backup\_/i", $entry)){
								$exportlog[filemtime($entry)] = array(	'version' => $bakidentify[1],
													'type' => $bakidentify[2],
													'method' => $bakidentify[3],
													'volume' => $bakidentify[4],
													'bakentry' => $identify['bakentry'],
													'filename' => $entry);
							}
					}
				}
				$dir->close();
			} else {
				echo 'error';
			}
			krsort($exportlog);
			reset($exportlog);

			$exportinfo = '<br><center><div style="margin-top: 4px; border-top: 1px solid #7AC4EA; border-right: 1px solid #7AC4EA; border-left: 1px solid #7AC4EA; width: 80%;float:center;"><table width="100%" border="0" cellpadding="6" cellspacing="0">
	<tr class="header"><td colspan="9">多卷数据备份记录详细信息</td></tr>
	<tr align="center" style="background: #FFFFD9;">
	<td>备份项目</td><td>版本</td>
	<td>时间</td><td>类型</td>
	<td>查看</td><td>操作</td></tr>';
			foreach($exportlog as $dateline => $info) {
				$info['dateline'] = is_int($dateline) ? gmdate("Y-m-d H:i", $dateline + 8*3600) : '未知';
					switch($info['type']) {
						case 'full':
							$info['type'] = '全部备份';
							break;
						case 'standard':
							$info['type'] = '标准备份(推荐)';
							break;
						case 'mini':
							$info['type'] = '最小备份';
							break;
						case 'custom':
							$info['type'] = '自定义备份';
							break;
					}
				//$info['size'] = sizecount($info['size']);
				$info['volume'] = $info['method'] == 'multivol' ? $info['volume'] : '';
				$info['method'] = $info['method'] == 'multivol' ? '多卷' : 'shell';
				$info['url'] = str_replace(".sql", '', str_replace("-$info[volume].sql", '', substr(strrchr($info['filename'], "/"), 1)));
				$exportinfo .= "<tr align=\"center\">\n".
					"<td class=\"altbg2\" align=\"left\">".$info['url']."</td>\n".
					"<td class=\"altbg1\">$info[version]</td>\n".
					"<td class=\"altbg2\">$info[dateline]</td>\n".
					"<td class=\"altbg1\">$info[type]</td>\n";
				if($info['bakentry']){
				$exportinfo .= "<td class=\"altbg2\"><a href=\"?action=restore&bakdirname=".$info['url']."\">查看</a></td>\n".
					"<td class=\"altbg1\"><a href=\"?action=restore&file=$info[bakentry]&importsubmit=yes\">[全部导入]</a></td>\n</tr>\n";
				} else {
				$exportinfo .= "<td class=\"altbg2\"><a href=\"?action=restore&filedirname=".$info['url']."\">查看</a></td>\n".
					"<td class=\"altbg1\"><a href=\"?action=restore&file=$info[filename]&importsubmit=yes\">[全部导入]</a></td>\n</tr>\n";
				}
			}
		$exportinfo .= '</center></table></div>';
		echo $exportinfo;
		unset($exportlog);
		unset($exportinfo);
		echo "<br>";
	//以前版本备份用到的备份情况
	if(!empty($filedirname)){
			$exportlog = array();
			if(is_dir(DISCUZ_ROOT.'./forumdata')) {
					$dir = dir(DISCUZ_ROOT.'./forumdata');
					while($entry = $dir->read()) {
						$entry = "./forumdata/$entry";
						if(is_file($entry) && preg_match("/\.sql/i", $entry) && preg_match("/$filedirname/i", $entry)) {
							$filesize = filesize($entry);
							$fp = fopen($entry, 'rb');
							$identify = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", fgets($fp, 256))));
							fclose ($fp);

							$exportlog[$identify[0]] = array(	'version' => $identify[1],
												'type' => $identify[2],
												'method' => $identify[3],
												'volume' => $identify[4],
												'filename' => $entry,
												'size' => $filesize);
						}
					}
					$dir->close();
				} else {
				}
				krsort($exportlog);
				reset($exportlog);

				$exportinfo = '<br><center><div style="margin-top: 4px; border: 1px solid #7AC4EA; width: 80%;float:center;"><table	width="100%" border="0" cellpadding="6" cellspacing="0">
								<tr class="header"><td colspan="9">数据备份记录</td></tr>
								<tr align="center" class="category">
								<td>文件名</td><td>版本</td>
								<td>时间</td><td>类型</td>
								<td>大小</td><td>方式</td>
								<td>卷号</td><td>操作</td></tr>';
				foreach($exportlog as $dateline => $info) {
					$info['dateline'] = is_int($dateline) ? gmdate("Y-m-d H:i", $dateline + 8*3600) : '未知';
						switch($info['type']) {
							case 'full':
								$info['type'] = '全部备份';
								break;
							case 'standard':
								$info['type'] = '标准备份(推荐)';
								break;
							case 'mini':
								$info['type'] = '最小备份';
								break;
							case 'custom':
								$info['type'] = '自定义备份';
								break;
						}
					//$info['size'] = sizecount($info['size']);
					$info['volume'] = $info['method'] == 'multivol' ? $info['volume'] : '';
					$info['method'] = $info['method'] == 'multivol' ? '多卷' : 'shell';
					$exportinfo .= "<tr align=\"center\">\n".
						"<td class=\"altbg2\" align=\"left\"><a href=\"$info[filename]\" name=\"".substr(strrchr($info['filename'], "/"), 1)."\">".substr(strrchr($info['filename'], "/"), 1)."</a></td>\n".
						"<td class=\"altbg1\">$info[version]</td>\n".
						"<td class=\"altbg2\">$info[dateline]</td>\n".
						"<td class=\"altbg1\">$info[type]</td>\n".
						"<td class=\"altbg2\">".get_real_size($info[size])."</td>\n".
						"<td class=\"altbg1\">$info[method]</td>\n".
						"<td class=\"altbg2\">$info[volume]</td>\n".
						"<td class=\"altbg1\"><a href=\"?action=restore&file=$info[filename]&importsubmit=yes&auto=off\">[导入]</a></td>\n</tr>\n";
				}
			$exportinfo .= '</center></table></div>';
			echo $exportinfo;
		}
	// 5.5版本用到的详细备份情况
	if(!empty($bakdirname)){
			$exportlog = array();
			$filedirname = DISCUZ_ROOT.'./forumdata/'.$bakdirname;
			if(is_dir($filedirname)) {
					$dir = dir($filedirname);
					while($entry = $dir->read()) {
						$entry = $filedirname.'/'.$entry;
						if(is_file($entry) && preg_match("/\.sql/i", $entry)) {
							$filesize = filesize($entry);
							$fp = fopen($entry, 'rb');
							$identify = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", fgets($fp, 256))));
							fclose ($fp);

							$exportlog[$identify[0]] = array(	'version' => $identify[1],
												'type' => $identify[2],
												'method' => $identify[3],
												'volume' => $identify[4],
												'filename' => $entry,
												'size' => $filesize);
						}
					}
					$dir->close();
			} else {
				}
			krsort($exportlog);
			reset($exportlog);

			$exportinfo = '<br><center><div style="margin-top: 4px; border-top: 1px solid #7AC4EA; border-right: 1px solid #7AC4EA; border-left: 1px solid #7AC4EA; width: 80%;float:center;"><table width="100%" border="0" cellpadding="6" cellspacing="0">
					<tr class="header"><td colspan="9">数据备份记录</td></tr>
					<tr align="center" style="background: #FFFFD9;">
					<td>文件名</td><td>版本</td>
					<td>时间</td><td>类型</td>
					<td>大小</td><td>方式</td>
					<td>卷号</td><td>操作</td></tr>';
			foreach($exportlog as $dateline => $info) {
				$info['dateline'] = is_int($dateline) ? gmdate("Y-m-d H:i", $dateline + 8*3600) : '未知';
				switch($info['type']) {
					case 'full':
						$info['type'] = '全部备份';
						break;
					case 'standard':
						$info['type'] = '标准备份(推荐)';
						break;
					case 'mini':
						$info['type'] = '最小备份';
						break;
					case 'custom':
						$info['type'] = '自定义备份';
						break;
				}
				//$info['size'] = sizecount($info['size']);
				$info['volume'] = $info['method'] == 'multivol' ? $info['volume'] : '';
				$info['method'] = $info['method'] == 'multivol' ? '多卷' : 'shell';
				$exportinfo .= "<tr align=\"center\">\n".
						"<td class=\"altbg2\" align=\"left\"><a href=\"$info[filename]\" name=\"".substr(strrchr($info['filename'], "/"), 1)."\">".substr(strrchr($info['filename'], "/"), 1)."</a></td>\n".
						"<td class=\"altbg1\">$info[version]</td>\n".
						"<td class=\"altbg2\">$info[dateline]</td>\n".
						"<td class=\"altbg1\">$info[type]</td>\n".
						"<td class=\"altbg2\">".get_real_size($info[size])."</td>\n".
						"<td class=\"altbg1\">$info[method]</td>\n".
						"<td class=\"altbg2\">$info[volume]</td>\n".
						"<td class=\"altbg1\"><a href=\"?action=restore&file=$info[filename]&importsubmit=yes&auto=off\">[导入]</a></td>\n</tr>\n";
			}
			$exportinfo .= '</center></table></div>';
			echo $exportinfo;
		}
		echo "<br>";
		cexit("");
	}
} elseif ($action == 'replace') {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -