【发布时间】:2010-07-19 21:30:06
【问题描述】:
我们正在迁移 Web 服务器,如果有一种自动化的方式来检查一些基本的站点结构,以查看在新服务器上呈现的页面是否与旧服务器上的相同,那就太好了。我只是想知道是否有人知道可以帮助完成这项任务?
【问题讨论】:
标签: linux apache webserver migration compare
我们正在迁移 Web 服务器,如果有一种自动化的方式来检查一些基本的站点结构,以查看在新服务器上呈现的页面是否与旧服务器上的相同,那就太好了。我只是想知道是否有人知道可以帮助完成这项任务?
【问题讨论】:
标签: linux apache webserver migration compare
获取两个站点的格式化输出(这里我们使用 w3m,但 lynx 也可以):
w3m -dump http://google.com 2>/dev/null > /tmp/1.html
w3m -dump http://google.de 2>/dev/null > /tmp/2.html
然后使用wdiff,它可以为您提供两个文本相似程度的百分比。
wdiff -nis /tmp/1.html /tmp/2.html
使用colordiff 也可以更轻松地查看差异。
wdiff -nis /tmp/1.html /tmp/2.html | colordiff
输出摘录:
Web Images Vidéos Maps [-Actualités-] Livres {+Traduction+} Gmail plus »
[-iGoogle |-]
Paramètres | Connexion
Google [hp1] [hp2]
[hp3] [-Français-] {+Deutschland+}
[ ] Recherche
avancéeOutils
[Recherche Google][J'ai de la chance] linguistiques
/tmp/1.html: 43 words 39 90% common 3 6% deleted 1 2% changed
/tmp/2.html: 49 words 39 79% common 9 18% inserted 1 2% changed
(他居然把 google.com 改成了法语……好笑)
common % 值表示两个文本的相似程度。另外,您可以通过单词轻松查看差异(而不是按行查看,这可能会很混乱)。
【讨论】:
wdiff -nis /tmp/1.html /tmp/2.html | tail -2 | awk '{print $5}'
关键是如何检查“渲染”页面。如果页面没有任何动态内容,最简单的方法是使用 md5 或 sha1 命令为文件生成哈希,然后检查新服务器。
如果页面包含动态内容,您必须使用 wget 等工具下载该网站
wget --mirror http://thewebsite/thepages
然后按照 Warner 的建议使用 diff 或再次进行哈希处理。我认为 diff 可能是最好的方法,因为即使更改 1 个字符也会弄乱哈希。
【讨论】:
【讨论】:
使用开源工具recheck-web(https://github.com/retest/recheck-web),有两种可能:
对于这两种解决方案,您目前需要手动列出所有相关的 URL。在大多数情况下,这应该不是什么大问题。 recheck-web 将比较呈现的网站并准确显示它们的不同之处(即不同的字体、不同的元标记,甚至不同的链接 URL)。它还为您提供强大的过滤器,让您专注于与您相关的内容。
免责声明:我帮助创建了 recheck-web。
【讨论】:
将文件复制到/tmp/directory1和/tmp/directory2中的同一台服务器上并运行以下命令:
diff -r /tmp/directory1 /tmp/directory2
出于所有意图和目的,您可以使用您喜欢的命名约定将它们放在您喜欢的位置。
编辑 1
您可能会使用 lynx -dump 或 wget 并对结果进行比较。
【讨论】:
没有渲染每个页面、截屏并比较这些屏幕截图,我认为无法比较渲染的页面。
不过,用wget递归下载后,对比下载的网站肯定是可以的。
wget [option]... [URL]...
-m
--mirror
Turn on options suitable for mirroring. This option turns on recursion and time-stamping, sets infinite recursion depth and keeps FTP
directory listings. It is currently equivalent to -r -N -l inf --no-remove-listing.
下一步就是执行 Warner 推荐的递归 diff。
【讨论】: