WordPress: MacOS X Local Mirror:修订间差异

来自站长百科
跳转至: 导航、​ 搜索
无编辑摘要
无编辑摘要
第1行: 第1行:
Here's what I did to set up a local mirror of my Wordpress blog on MacOS X.
下面是我怎样在MacOS X上 为我的WordPress博客设置一个本地镜像。
下面是我怎样在MacOS X上 为我的WordPress博客设置一个本地镜像。
== Motivation and Assumptions ==
==动机和设想==
==动机和设想==
Firstly, why do this? Well I can think of a few reasons:


首先,为什么要这么做?哦,我能够想到一些原因:
首先,为什么要这么做?哦,我能够想到一些原因:
* keeping an up-to-date and <em>working</em> backup


*保存一个最新的并且<em>运转的</em>文件备份
*保存一个最新的并且<em>运转的</em>文件备份
* using it for testing changes to the blog before you inflict them on the world. Like formatting, software updates, or anything really.


*在你将博客公之于众之前,用文件备份来测试博客上的变化。像格式,软件更新,或者其它的什么内容。
*在你将博客公之于众之前,用文件备份来测试博客上的变化。像格式,软件更新,或者其它的什么内容。
* It's fun (except for the MySQL setup, which we'll get to)


*非常有趣(MySQL设置除外,我们即将开始MySQL设置)
*非常有趣(MySQL设置除外,我们即将开始MySQL设置)
The basic idea is to take a snapshot of the database and file system your hosting provider, download it and extract it locally, then be able to view the result.


基本的方法是take a snapshot of the database and file system your hosting provider,将其下载并且在本地提取,然后再查看结果。
基本的方法是take a snapshot of the database and file system your hosting provider,将其下载并且在本地提取,然后再查看结果。
So I'm assuming that you have a blog at http://example.com (no subdirectory). Substitute your own blog name for this in the instructions below. For the sake of this HOWTO I'm assuming that you are logged in as <code>alastair</code> (MacOS calls this your "short name").


因此,我假定你在http://example.com (没有子目录)有一个博客。在下面的指示中,你可以用你自己的博客名来代替这个。出于怎样做的目的,我假定你以<code>alastair</code>登录(MacOS称这个为你的"简称")。
因此,我假定你在http://example.com (没有子目录)有一个博客。在下面的指示中,你可以用你自己的博客名来代替这个。出于怎样做的目的,我假定你以<code>alastair</code>登录(MacOS称这个为你的"简称")。
I'm assuming also that you're running MacOS X 10.3 and for the sake of simplicity want to install the minimum software. Or in other words use the standard OS distribution as much as possible. This takes advantage of patches and other updates, amongst other benefits. MacOS X 10.3 comes with Apache and PHP pre-installed, all we need is MySQL and Wordpress. (This HOWTO was written when 10.3 was current, but the procedure is identical on 10.4, as I have verified personally).


我还假定你正在运行MacOS X 10.3,而且希望安装最小的软件,使得过程更加简单。或者换句话说,尽可能地使用标准的OS发行版本。这样做,利用了patches和其它的更新,还有其它的好处。MacOS X10.3拥有先前安装好的Apache和PHP,我们所需要的就是MySQL和WordPress。(写好这篇文章的时候,10.3还是当前的版本,但是在10.4上这个过程是一样的,我个人对此进行检验过了)。
我还假定你正在运行MacOS X 10.3,而且希望安装最小的软件,使得过程更加简单。或者换句话说,尽可能地使用标准的OS发行版本。这样做,利用了patches和其它的更新,还有其它的好处。MacOS X10.3拥有先前安装好的Apache和PHP,我们所需要的就是MySQL和WordPress。(写好这篇文章的时候,10.3还是当前的版本,但是在10.4上这个过程是一样的,我个人对此进行检验过了)。
If you want to upgrade to a more recent PHP and MySQL, you may find [http://www.andybudd.com/archives/2005/02/the_no_hassle_guide_to_installing_php_and_mysql_on_os_x_103/index.php Andy Budd's guide] useful.


如果你想要升级到一个更新的PHP和MySQL,你会发现[http://www.andybudd.com/archives/2005/02/the_no_hassle_guide_to_installing_php_and_mysql_on_os_x_103/index.php Andy Budd的指南]很有用。
如果你想要升级到一个更新的PHP和MySQL,你会发现[http://www.andybudd.com/archives/2005/02/the_no_hassle_guide_to_installing_php_and_mysql_on_os_x_103/index.php Andy Budd的指南]很有用。
== Configure Apache and PHP ==


== 配置 Apache 和 PHP ==
== 配置 Apache 和 PHP ==
First let's make sure that Apache and PHP are configured. Check that Apache is started in the Sharing Preference Pane:


首先要确定Apache和PHP都配置好了。确定Apache是在分享喜好板块上开始的:
首先要确定Apache和PHP都配置好了。确定Apache是在分享喜好板块上开始的:
[[WordPress:Image:pws-capture.png|Personal Web Sharing]]


[[WordPress:Image:pws-capture.png|个人网络分享]]
[[WordPress:Image:pws-capture.png|个人网络分享]]
Then go into <code>/etc/httpd/httpd.conf</code> and uncomment (ie remove the # at the start of) the following lines:


然后进入<code>/etc/httpd/httpd.conf</code>并且uncomment (例如开头部分的#) 下面的行:
然后进入<code>/etc/httpd/httpd.conf</code>并且uncomment (例如开头部分的#) 下面的行:
LoadModule php4_module        libexec/httpd/libphp4.so
... 
AddModule mod_php4.c


LoadModule php4_module        libexec/httpd/libphp4.so
LoadModule php4_module        libexec/httpd/libphp4.so
  ...   
  ...   
  AddModule mod_php4.c
  AddModule mod_php4.c
You will need to edit this as root. One way to do this is open a terminal session and type <code>sudo pico /etc/httpd/httpd.conf</code>, but I'm sure there are others.


你可能要将这个像根目录一样编辑。一种方法是打开一个终端部分,并且输入<code>sudo pico /etc/httpd/httpd.conf</code>,但是我确定还有其它的方法。
你可能要将这个像根目录一样编辑。一种方法是打开一个终端部分,并且输入<code>sudo pico /etc/httpd/httpd.conf</code>,但是我确定还有其它的方法。
Now let's restart Apache...


现在,让我们来重启Apaceh…
现在,让我们来重启Apaceh…
sudo apachectl graceful
sudo apachectl graceful
sudo apachectl graceful
...and see if it worked. Create a file in your Sites directory (within your Home directory) named <code>info.php</code>. Edit it to contain the following:


…查看是否能够运行。在你的站点目录(在主目录内部)创建一个文件,命名为<code>info.php</code>。编辑文件,使得文件包含:
…查看是否能够运行。在你的站点目录(在主目录内部)创建一个文件,命名为<code>info.php</code>。编辑文件,使得文件包含:
< ? php phpinfo(); ?>


< ? php phpinfo(); ?>
< ? php phpinfo(); ?>
Then open up http://localhost/~alastair/info.php in your browser (remember to substitute for your own name) and marvel at the result. You should get a detailed listing of all information that PHP has to hand. Congrats, now on to...


然后在你的浏览器中打开http://localhost/~alastair/info.php(记住要替换你自己的名字)并且会对结果感到惊奇。你会得到PHP需要处理的所有的详细信息的列表。祝贺你,现在继续…
然后在你的浏览器中打开http://localhost/~alastair/info.php(记住要替换你自己的名字)并且会对结果感到惊奇。你会得到PHP需要处理的所有的详细信息的列表。祝贺你,现在继续…
== Create a example.mirror static site ==


== 创建一个例子.mirror 静态网页 ==
== 创建一个例子.mirror 静态网页 ==
If you're running a blog at the top-level of a host (like http://example.com and not like http://example.com/blog) you probably have your intra-site links set up to use absolute paths. In fact I don't think Wordpress gives you a choice in the matter for certain links like stylesheets.


如果你在一个顶级级别的主机(如http://example.com而不是http://example.com/blog)上运行博客,你可能将你的内部站点链接设置使用绝对路径。事实上,我认为对于某些链接,像样式表,WordPress没有向你提供选择。
如果你在一个顶级级别的主机(如http://example.com而不是http://example.com/blog)上运行博客,你可能将你的内部站点链接设置使用绝对路径。事实上,我认为对于某些链接,像样式表,WordPress没有向你提供选择。
So the problem with creating a local mirror is that you need to create a new hostname for it, so as not to conflict with any other content you're running on your MacOS system. If you don't have this need, feel free to skip to the end of this section, and just mirror your blog's filesysem into <code>/Library/WebServer/Documents</code>.


因此创建一个本地镜像的问题是,你需要为之创建一个主机名,这样不会与你在MacOS系统上运行的其它内容相冲突。如果你没有必要这样做,你只要随心所欲地跳到这个部分的末尾,只要将你的博客文件系统反映到<code>/Library/网络服务器/文件</code>。
因此创建一个本地镜像的问题是,你需要为之创建一个主机名,这样不会与你在MacOS系统上运行的其它内容相冲突。如果你没有必要这样做,你只要随心所欲地跳到这个部分的末尾,只要将你的博客文件系统反映到<code>/Library/网络服务器/文件</code>。
What we're going to do is create a new, bogus, hostname and have it served locally. The .local top-level domain is taken already (it's used for Rendezvous), so we'll pick .mirror. The local mirror will be at http://example.mirror


我们要做的是创建一个新的,伪造的主机名,并使得这个主机名在本地服务。已经采取了.本地最高级别域(用作Rendezvous),因此我们选择.mirror。本地镜像会在http://example.mirror
我们要做的是创建一个新的,伪造的主机名,并使得这个主机名在本地服务。已经采取了.本地最高级别域(用作Rendezvous),因此我们选择.mirror。本地镜像会在http://example.mirror
The first thing to do is to add this host name to your <code>/etc/hosts</code> file. Just append the following:


首先要做的是,将这个主机名添加到你的<code>/etc/主机</code>文件。只要添加:
首先要做的是,将这个主机名添加到你的<code>/etc/主机</code>文件。只要添加:
127.0.0.1 example.mirror


127.0.0.1 example.mirror
127.0.0.1 example.mirror


You should be able to ping this address now:
你现在能够ping这个地址了:
你现在能够ping这个地址了:
alastair $ ping example.mirror 
PING example.mirror (127.0.0.1): 56 data bytes 
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.159 ms 
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=5.078 ms 
^C 


alastair $ ping example.mirror   
alastair $ ping example.mirror   
第129行: 第60行:
  64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=5.078 ms   
  64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=5.078 ms   
  ^C   
  ^C   
--- example.mirror ping statistics --- 


--- example.mirror ping 统计数据 ---   
--- example.mirror ping 统计数据 ---   
第138行: 第65行:
  2 packets transmitted, 2 packets received, 0% packet loss   
  2 packets transmitted, 2 packets received, 0% packet loss   
  round-trip min/avg/max = 0.159/2.618/5.078 ms
  round-trip min/avg/max = 0.159/2.618/5.078 ms
传递两包,收到两包,,丢失 0% 包
round-trip min/avg/max = 0.159/2.618/5.078 ms
[Aside: [http://www.evolt.org/MacOSX_vhosts/ Bob Davis describes] another, possibly better, way of doing this, through the NetInfo Manager. I haven't tested this, and it looks like a good technique, but according to an [http://docs.info.apple.com/article.html?artnum=88158 Apple KB article], editing the <code>/etc/hosts</code> file is preferred for MacOS 10.2 and later. I have no idea why.]


[Aside: [http://www.evolt.org/MacOSX_vhosts/ Bob Davis 描述了]另一种,通过NetInfo 管理器执行的更好的操作。我没有测试这个,看起来是一种很好的方法,但是根据一篇[http://docs.info.apple.com/article.html?artnum=88158 Apple KB 文章],MacOS10.2以及以后的版本更乐意于编辑文章。我不知道为什么。]
[Aside: [http://www.evolt.org/MacOSX_vhosts/ Bob Davis 描述了]另一种,通过NetInfo 管理器执行的更好的操作。我没有测试这个,看起来是一种很好的方法,但是根据一篇[http://docs.info.apple.com/article.html?artnum=88158 Apple KB 文章],MacOS10.2以及以后的版本更乐意于编辑文章。我不知道为什么。]
Now go and add this as a VirtualHost in your Apache configuration. What you may want to do is edit <code>/private/etc/httpd/users/alastair.conf</code> (or your username) instead of the main <code>httpd.conf</code> file. This minimises changes to the main Apache configuration file and simplifies upgrades. In any case you need to add something like the following:


现在继续,将这个作为VirtualHost添加到Apache配置。你想要做的可能是编辑<code>/private/etc/httpd/users/alastair.conf</code>(或者你的用户名)而不是主要的<code>httpd.conf</code>文件。这个minimises更改为主要的Apache配置文件和简化的更新。在任何情况下,你需要添加:
现在继续,将这个作为VirtualHost添加到Apache配置。你想要做的可能是编辑<code>/private/etc/httpd/users/alastair.conf</code>(或者你的用户名)而不是主要的<code>httpd.conf</code>文件。这个minimises更改为主要的Apache配置文件和简化的更新。在任何情况下,你需要添加:
NameVirtualHost *:80
<VirtualHost *>
    DocumentRoot /Users/alastair/Sites/example.com
    ServerName example.mirror
    <Directory "/Users/alastair/Sites/example.com">
        Options FollowSymLinks
        AllowOverride All 
    </Directory>
</VirtualHost>


NameVirtualHost *:80
NameVirtualHost *:80
第170行: 第78行:
         AllowOverride All   
         AllowOverride All   
     </Directory>
     </Directory>
  </VirtualHost
  </VirtualHost.  
 
 
This creates a new virtual host at the specified document root. This directory is where we're going to store the mirrored files.  


这在一个特别的文件根中创建了一个新的虚拟主机。我们准备在这个目录中储存mirrored文件。
这在一个特别的文件根中创建了一个新的虚拟主机。我们准备在这个目录中储存mirrored文件。
Restart Apache again: <code>sudo apachectl graceful</code>


再次重新启动Apache:<code>sudo apachectl graceful</code>
再次重新启动Apache:<code>sudo apachectl graceful</code>
Now is as good a time as any to actually copy the files from your hosting provider to this local mirror directory. You can use whatever tool you like. If your provider supports cPanel, you could just get a home directory backup, and extract the relevant files (probably everything in <code>public_html</code>).


现在是个好时机,任何人都可以将你的主机供应商的文件复制到这个本地镜像目录。你可以使用任何你喜欢的工具。如果你的供应商支持cPanel,你只能得到一个主目录文件备份,提取出相关文件(可能所有的内容都在<code>public_html</code>)。
现在是个好时机,任何人都可以将你的主机供应商的文件复制到这个本地镜像目录。你可以使用任何你喜欢的工具。如果你的供应商支持cPanel,你只能得到一个主目录文件备份,提取出相关文件(可能所有的内容都在<code>public_html</code>)。
I use [http://www.interarchy.com Interarchy], which allows you to do a true mirror (ie only copy the files that need to be copied). If you use Interarchy too, please make sure that it is set to use UNIX line endings and not Mac.


我使用[http://www.interarchy.com Interarchy],运行执行一个真正的mirror(例如,复制需要复制的文件)。如果你也使用Interarchy,请确定设置Interarchy是用作UNIX行结尾的,而不是用作Mac。
我使用[http://www.interarchy.com Interarchy],运行执行一个真正的mirror(例如,复制需要复制的文件)。如果你也使用Interarchy,请确定设置Interarchy是用作UNIX行结尾的,而不是用作Mac。
Now you should be able to view the static portion of your blog. A good test for this is the wordpress readme file, which you will now find at http://example.mirror/readme.html. If all has gone well so far you should be reading the WordPress readme.


现在你应该能够看到你的博客的静态部分。WordPress自述文件能够很好地测试这一点,你可以在http://example.mirror/readme.html找到这个自述文件。如果迄今为止,一切顺利了,你应该正在阅读WordPress自述文件。
现在你应该能够看到你的博客的静态部分。WordPress自述文件能够很好地测试这一点,你可以在http://example.mirror/readme.html找到这个自述文件。如果迄今为止,一切顺利了,你应该正在阅读WordPress自述文件。


== Install and Configure MySQL ==
== 安装和配置MySQL ==
== 安装和配置MySQL ==
Now the un-fun bit. Well it was for me anyway. There are several different flavours of MySQL for MacOS X, and I tried a few of them, but the standard distribution from MySQL AG seemed fine to me. The question is: which version? The answer depends on the version of MySQL you wish to mirror. In other words: which version does your hosting provider use?


现在临到un-fun bit了,不管怎么说,un-fun bit是拥护我的。MacOS X有几种不同的MySQL,我尝试了其中的几个MySQL,但是MySQL AG标准发行的版本,似乎更适合我。问题是:哪个版本?答案取决于,你想要mirror哪个版本的MySQL。换句话说,你的主机供应商使用哪个版本?
现在临到un-fun bit了,不管怎么说,un-fun bit是拥护我的。MacOS X有几种不同的MySQL,我尝试了其中的几个MySQL,但是MySQL AG标准发行的版本,似乎更适合我。问题是:哪个版本?答案取决于,你想要mirror哪个版本的MySQL。换句话说,你的主机供应商使用哪个版本?
As a general rule, you should probably use the same (ie x.y) version that your hosting provider uses. For version 4.1 and later, we will be using a [http://dev.mysql.com/doc/refman/4.1/en/old-client.html workaround] for a change to the password hashing algorithm that was introduced in 4.1. Not that that should worry you.


一般的规则是,你可能与你的主机供应商使用同一个版本(例如x.y)。对于4.1版本以及以后发行的版本,我们会使用一个[http://dev.mysql.com/doc/refman/4.1/en/old-client.html 工作区]更改4.1版本中引入的密码hashing算法。倒不是那个让你烦恼的。
一般的规则是,你可能与你的主机供应商使用同一个版本(例如x.y)。对于4.1版本以及以后发行的版本,我们会使用一个[http://dev.mysql.com/doc/refman/4.1/en/old-client.html 工作区]更改4.1版本中引入的密码hashing算法。倒不是那个让你烦恼的。


All you need to do is download the chosen version (ie [http://dev.mysql.com/downloads/mysql/4.0.html 4.0], or [http://dev.mysql.com/downloads/mysql/4.1.html 4.1] or [http://dev.mysql.com/downloads/ what-have you]) and install it. The instructions for [http://dev.mysql.com/doc/refman/4.1/en/mac-os-x-installation.html installation], [http://dev.mysql.com/doc/refman/4.1/en/unix-post-installation.html post-installation configuration] and [http://dev.mysql.com/doc/refman/4.1/en/default-privileges.html securing the initial accounts] are long and detailed, so here is the PowerPoint Slide version:
你所要做的就是下载挑选的版本(例如[http://dev.mysql.com/downloads/mysql/4.0.html 4.0], 或者[http://dev.mysql.com/downloads/mysql/4.1.html 4.1] 或者[http://dev.mysql.com/downloads/ what-have you])并且将其安装。关于[http://dev.mysql.com/doc/refman/4.1/en/mac-os-x-installation.html 安装], [http://dev.mysql.com/doc/refman/4.1/en/unix-post-installation.html 文章安装配置] 和[http://dev.mysql.com/doc/refman/4.1/en/default-privileges.html 保护初始帐户]的指示说明既详细又长,下面是PowerPoint幻灯片版本。
 
你所要做的就是下载挑选的版本(例如[http://dev.mysql.com/downloads/mysql/4.0.html 4.0], 或者[http://dev.mysql.com/downloads/mysql/4.1.html 4.1] 或者[http://dev.mysql.com/downloads/ what-have you])并且将其安装。关于[http://dev.mysql.com/doc/refman/4.1/en/mac-os-x-installation.html 安装], [http://dev.mysql.com/doc/refman/4.1/en/unix-post-installation.html 文章安装配置] 和[http://dev.mysql.com/doc/refman/4.1/en/default-privileges.html 保护初始帐户]的指示说明即详细有长,下面是PowerPoint幻灯片版本。
 
* Run the installer for both the mysql software and the startup item


*为mysql软件和启动项运行installer。
*为mysql软件和启动项运行installer。
* (MacOS X 10.4.4+ <em>only</em>) Update your <code>/etc/my.cnf</code> file to point to the new secure location for the socket. See note below.


* (MacOS X 10.4.4+ <em>只有</em>)更新你的<code>/etc/my.cnf</code>文件,指向socket的新的安全位置。请看看下面的注释。
* (MacOS X 10.4.4+ <em>只有</em>)更新你的<code>/etc/my.cnf</code>文件,指向socket的新的安全位置。请看看下面的注释。
* Start the database server with <code>sudo /Library/StartupItems/MySQLCOM/MySQLCOM start</code>


*用<code>sudo /Library/StartupItems/MySQLCOM/MySQLCOM start</code>启动数据库服务器
*用<code>sudo /Library/StartupItems/MySQLCOM/MySQLCOM start</code>启动数据库服务器


* <code>cd /usr/local/mysql</code>
* <code>cd /usr/local/mysql</code>
* <code>cd /usr/local/mysql</code>
* <code>sudo scripts/mysql_install_db --user=mysql</code>


* <code>sudo 脚本/mysql_安装_db –用户=mysql</code>
* <code>sudo 脚本/mysql_安装_db –用户=mysql</code>
* <code>bin/mysqladmin -u root password</code> <em>a-secure-password</em>


* <code>bin/mysqladmin -u 根密码</code> <em>一个-安全的-密码</em>
* <code>bin/mysqladmin -u 根密码</code> <em>一个-安全的-密码</em>
MacOS X 10.4.4+ users need to set up the MySQL server to listen on a socket other than the default one. To do this, create a <code>/etc/my.cnf</code> file with the following contents:


MacOS X 10.4.4+用户需要设置MySQL服务器在一个socket上聆听而不是默认的socket。要做到这一点,就要创建一个拥有以下内容的<code>/etc/my.cnf</code>文件:
MacOS X 10.4.4+用户需要设置MySQL服务器在一个socket上聆听而不是默认的socket。要做到这一点,就要创建一个拥有以下内容的<code>/etc/my.cnf</code>文件:
[mysqld]
socket=/var/mysql/mysql.sock


[mysqld]
[mysqld]
  socket=/var/mysql/mysql.sock
  socket=/var/mysql/mysql.sock
Then create the directory if it doesn't exist:


如果目录不存在的话,再创建一个目录:
如果目录不存在的话,再创建一个目录:
$ sudo mkdir /var/mysql
$ sudo chown mysql /var/mysql
$ sudo mkdir /var/mysql
$ sudo mkdir /var/mysql
   $ sudo chown mysql /var/mysql
   $ sudo chown mysql /var/mysql
This is to match the new location expected by Apple's PHP installation. Again, you only need this stuff for MacOS X 10.4.4+ (although it probably won't hurt on earlier releases). See [http://docs.info.apple.com/article.html?artnum=302977 here] for (slightly) more information.


这是要匹配Apple的PHP安装所期望的新位置。同样,你只要为MacOS X 10.4.4+准备这个stuff。(但是在先前的版本中,这个stuff可能不会有危害)请阅读[http://docs.info.apple.com/article.html?artnum=302977 这儿]得到(稍微)更多的信息。
这是要匹配Apple的PHP安装所期望的新位置。同样,你只要为MacOS X 10.4.4+准备这个stuff。(但是在先前的版本中,这个stuff可能不会有危害)请阅读[http://docs.info.apple.com/article.html?artnum=302977 这儿]得到(稍微)更多的信息。


Note that the root password set in the last step above doesn't have to match the wordpress password we use later. In fact it's probably a good idea if it doesn't. Pick something you can remember. At this point it's probably a good idea to verify that you can access the database as root using the <code>mysql</code> tool:
注意,在上面最后一步中设置的根密码,不需要与我们之后使用的WordPress密码相同。事实上,如果根密码与我们之后使用的WordPress密码不同,会是一件好事。选一些你能够记住的内容作为密码。这时候,确定你能够访问数据库,因为根使用<code>mysql</code>工具,会是个好主意:
 
注意,在上面最后一步中设置的根密码,不需要于我们之后使用的WordPress密码相同。事实上,如果根密码与我们之后使用的WordPress密码不同,会是一件好事。选一些你能够记住的内容作为密码。这时候,确定你能够访问数据库,因为根使用<code>mysql</code>工具,会是个好主意:
 
mysql $ bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3 to server version: 4.1.15-standard
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;
+----------+
| Database |
+----------+
| mysql    |
| test    |
+----------+
2 rows in set (0.00 sec)
mysql> \q
Bye
 
Mmmm, ASCII art!
 
 
 
 


mysql $ bin/mysql -u root -p
mysql $ bin/mysql -u root -p
  输入秘密:  
  输入密码:  
欢迎来到MySQL监控器。  命令行以 ; or \g结束。
欢迎来到MySQL监控器。  命令行以 ; or \g结束。
  Your MySQL connection id is 3 to server version: 4.1.15-standard
  Your MySQL connection id is 3 to server version: 4.1.15-standard
第310行: 第144行:


Mmmm, ASCII art!
Mmmm, ASCII art!
Checking that you can access the database with [http://cocoamysql.sourceforge.net/ CocoaMySQL] is probably worthwhile also. Make sure you get the right version for your MySQL installation (support for 4.1+ is available in the [http://cocoamysql.sourceforge.net/beta.php beta releases]).


核实你能够访问数据库,[http://cocoamysql.sourceforge.net/ CocoaMySQL]也是值得做的。确认你得到了MySQL安装的合适的版本(支持[http://cocoamysql.sourceforge.net/beta.php beta 版本]中拥有的4.1+版本。
核实你能够访问数据库,[http://cocoamysql.sourceforge.net/ CocoaMySQL]也是值得做的。确认你得到了MySQL安装的合适的版本(支持[http://cocoamysql.sourceforge.net/beta.php beta 版本]中拥有的4.1+版本。
== Set up the WordPress user and database ==


==设置WordPress用户和数据库 ==
==设置WordPress用户和数据库 ==
Almost done! You just have to install a user/password and database for the wordpress blog. This should match the setup in your <code>wp-config.php</code> file! Well, strictly speaking it doesn't <em>have</em> to match, but if you want to download your blog and run it straight away, it helps to use the same details for connection. Let's assume that the username is <code>example_u</code>, the database is called <code>example_db</code> and the password is <code>example_pw</code>.


几乎完成了!你只要为WordPress博客安装一个用户/密码和数据库,应该与你的<code>wp-config.php</code>文件中的设置相匹配!严格地说,不<em>需要</em>匹配,但是如果你想下载你的博客并且马上将博客运行,匹配信息会帮你使用同样的详细的连接信息。假定用户名是<code>example_u</code>,数据库称为<code>example_db</code>,密码是<code>example_pw</code>。
几乎完成了!你只要为WordPress博客安装一个用户/密码和数据库,应该与你的<code>wp-config.php</code>文件中的设置相匹配!严格地说,不<em>需要</em>匹配,但是如果你想下载你的博客并且马上将博客运行,匹配信息会帮你使用同样的详细的连接信息。假定用户名是<code>example_u</code>,数据库称为<code>example_db</code>,密码是<code>example_pw</code>。
Firstly connect to the database and add the grant for the wordpress user:


首先连接到数据库并且为WordPress用户添加保证:
首先连接到数据库并且为WordPress用户添加保证:
mysql $ bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 4.1.15-standard
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> grant all on example_db.* to 'example_u'@'localhost';
Query OK, 0 rows affected (0.00 sec)


mysql $ bin/mysql -u root -p
mysql $ bin/mysql -u root -p
第351行: 第162行:
  mysql> grant all on example_db.* to 'example_u'@'localhost';
  mysql> grant all on example_db.* to 'example_u'@'localhost';
  Query OK, 0 rows affected (0.00 sec)
  Query OK, 0 rows affected (0.00 sec)
The procedure for setting the password differs if you're using MySQL 4.0 instead of a later version. Use this if you're on MySQL 4.0:


如果你使用MySQL4.0而不是更高的版本,那么设置密码的过程会有所不同。如果你使用MySQL4.0,请使用:
如果你使用MySQL4.0而不是更高的版本,那么设置密码的过程会有所不同。如果你使用MySQL4.0,请使用:
第359行: 第168行:
  Query OK, 0 rows affected (0.06 sec)
  Query OK, 0 rows affected (0.06 sec)


mysql> set password for 'example_u'@'localhost' = password('example_pw');
查询 OK, 0排收到影响 (0.06 sec)
Or this for 4.1+:
或者这个用于4.1+:
或者这个用于4.1+:
  mysql> set password for 'example_u'@'localhost' = old_password('example_pw');
  mysql> set password for 'example_u'@'localhost' = old_password('example_pw');
  Query OK, 0 rows affected (0.05秒)
  Query OK, 0 rows affected (0.05秒)
mysql>为 'example_u'@'localhost' = old_password('example_pw')设置密码;
查询OK, 0排受到影响 (0.05 秒)
[MacOS X 10.4.4+ update: I <em>think</em> that the <code>password</code> method (ie the first of the two statements above) will also work for MacOS X 10.4.4 and later, although I haven't verified this myself.]


[MacOS X 10.4.4+ 更新: 我<em>认为</em> <code>密码</code> 方法 (ie the first of the two statements above) 同样适用于MacOS X 10.4.4 及以后的版本, 虽然我自己还没有证实。]
[MacOS X 10.4.4+ 更新: 我<em>认为</em> <code>密码</code> 方法 (ie the first of the two statements above) 同样适用于MacOS X 10.4.4 及以后的版本, 虽然我自己还没有证实。]


Now create the database:
现在创建数据库:
现在创建数据库:


第384行: 第180行:
   
   
  mysql> \q
  mysql> \q
mysql> 创建数据库 example_db;
查询 OK, 1 排受到影响 (0.00 秒)
mysql> \q
If all goes well we can import the blog database from our hosting provider. I'm assuming you've downloaded this as a single compressed database dump (as supported by the Backup function of cPanel, for example). If the database dump is called <code>example.gz</code> we might do:


如果一切进展顺利,我们可以从主机供应商那里导入博客数据库。假定你已经下载了这个单一的压缩的数据库(例如,如cPanel支持的文件备份功能)。如果数据库dump称为<code>example.gz</code>,我们可能会:
如果一切进展顺利,我们可以从主机供应商那里导入博客数据库。假定你已经下载了这个单一的压缩的数据库(例如,如cPanel支持的文件备份功能)。如果数据库dump称为<code>example.gz</code>,我们可能会:
alastair $ gzcat example.gz | mysql -u example_u -p example_db
Enter password: (example_pw)


alastair $ gzcat example.gz | mysql -u example_u -p example_db
alastair $ gzcat example.gz | mysql -u example_u -p example_db
  输入密码: (example_pw)
  输入密码: (example_pw)
At this point it might pay to use CocoaMySQL or the mysql command tool to view the database, and check that everything was imported successfully. If it didn't you probably got lots of error messages in the above command output.


这时,可能要付款使用CocaMySQL或者mysql命令工具,访问数据库,并且核实所有的内容是否都成功地导入了。如果没有成功导入,你可能在上面的命令中,得到许多错误信息。
这时,可能要付款使用CocaMySQL或者mysql命令工具,访问数据库,并且核实所有的内容是否都成功地导入了。如果没有成功导入,你可能在上面的命令中,得到许多错误信息。
== Finishing off ==
== 完成 ==
== 完成 ==
And now for the moment of truth. Open up http://example.mirror in your browser. If all goes well your blog should be displayed.


现在是关键时刻了。打开你的浏览器中的http://example.mirror。如果一切进展顺利,就应该显示你的博客了。
现在是关键时刻了。打开你的浏览器中的http://example.mirror。如果一切进展顺利,就应该显示你的博客了。
You may notice however that some of the links point back to your original site at example.com. To fix this you will need to update the "Wordpress Address" and the "Blog Address" options in the Wordpress general options, found at http://example.mirror/wp-admin/options-general.php.


你可能注意到一些链接在example.com上仍然指向你的原始站点。要解决这个问题,你需要在http://example.mirror/wp-admin/options-general.php 中的WordPress总选项,中更新"Wordpress 地址" 和 "博客地址"。
你可能注意到一些链接在example.com上仍然指向你的原始站点。要解决这个问题,你需要在http://example.mirror/wp-admin/options-general.php 中的WordPress总选项,中更新"Wordpress 地址" 和 "博客地址"。
== Automating it ==


== 使其自动化 ==
== 使其自动化 ==
There are many different ways to automate updating your local mirror with the contents of your blog. These depend on what tools you have available and what tools your hosting provider has. To provide some inspiration, the AppleScript that I use is listed below. It relies on Interarchy to do the file transfers.


有几种不同的方法,用博客内容自动更新本地镜像。这些方法取决于你拥有什么工具,以及你的主机供应商有什么工具。我在下面列出来了我使用的AppleScript,给你提供一些灵感。AppleScript依赖于Interarchy进行文件传输。
有几种不同的方法,用博客内容自动更新本地镜像。这些方法取决于你拥有什么工具,以及你的主机供应商有什么工具。我在下面列出来了我使用的AppleScript,给你提供一些灵感。AppleScript依赖于Interarchy进行文件传输。
-- Script to automate updating of a local mirror of a wordpress site
--
-- Written by alastair@girtby.net
--
-- Licensed under the Creative Commons Attribution License,
-- see http://creativecommons.org/licenses/by/2.0/
-- Set these up to match your wp-config.php
property u : "example_u"
property db : "example_db"
property pw : "example_pw"
-- Update the wordpress options to use this url
property newurl : "http://example.mirror"
-- Invoke mysql like this
set mysqlcmd to "/usr/local/mysql/bin/mysql -u " & u & " -p" & pw & " " & db
-- Site files live here:
set dest to alias ((path to home folder from user domain as string) & "Sites:example.com:")
-- Download database here:
set tempDir to path to "temp" from user domain
tell application "Interarchy"
-- mirror the static portion of the site
mirrordownload dest host "ftp.example.com" path "public_html" user "example"
-- download the database (disable post process files preference)
set ppf to contents of preference "PostProcessFiles"
set contents of preference "PostProcessFiles" to "false"
webfetch tempDir url "http://example.com:2082/getsqlbackup/wrdp1.gz" user "example"
set contents of preference "PostProcessFiles" to ppf
end tell
set dbfile to POSIX path of ((tempDir as string) & "wrdp1.gz")
-- Import the database
do shell script "gzcat " & dbfile & "| " & mysqlcmd
-- Cleanup: remove database file
do shell script "rm " & dbfile
-- Fix up the siteurl and home options in wordpress
do shell script "echo 'update wp_options set option_value = \"" & newurl & "\" where option_name = \"home\"; update wp_options set option_value = \"" & newurl & "\" where option_name = \"siteurl\";' | " & mysqlcmd


--自动更新WordPress一个站点的本地镜像的脚本  
--自动更新WordPress一个站点的本地镜像的脚本  
第521行: 第240行:
  do shell script "rm " & dbfile
  do shell script "rm " & dbfile
   
   
  -- Fix up the siteurl and home options in wordpress
  -- 在wordpress中修复站点url和主页选项
  do shell script "echo 'update wp_options set option_value = \"" & newurl & "\" where option_name = \"home\"; update wp_options set option_value = \"" & newurl & "\" where option_name = \"siteurl\";' | " & mysqlcmd
  do shell script "echo 'update wp_options set option_value = \"" & newurl & "\" where option_name = \"home\"; update wp_options set option_value = \"" & newurl & "\" where option_name = \"siteurl\";' | " & mysqlcmd
In order to get this script to work you will need to edit it in the Script Editor to change the various locations, URLs and passwords. Hopefully this will be easy enough to do. In addition you will need to add the passwords to the keychain for downloading your static site and accessing your database dump so that Interarchy can find them. The best way to do this is to access the site interactively in Interarchy and be sure to click the "add password to Keychain" checkbox.


为了使得这个脚本运行,你需要在脚本编辑器中编辑脚本,并且更改不同的位置,URLs和密码。希望这些能够轻易地执行。此外,你需要向keychain添加密码,以下载你的静态站点,访问你的数据库dump,这样Interarchy能够找到这些内容。执行这一步的最好方法,是在Interarchy中交互式地访问站点并且确定在检验框中点击了"向 Keychain添加密码"。
为了使得这个脚本运行,你需要在脚本编辑器中编辑脚本,并且更改不同的位置,URLs和密码。希望这些能够轻易地执行。此外,你需要向keychain添加密码,以下载你的静态站点,访问你的数据库dump,这样Interarchy能够找到这些内容。执行这一步的最好方法,是在Interarchy中交互式地访问站点并且确定在检验框中点击了"向 Keychain添加密码"。
If you don't use Interarchy you may still find this script valuable as it shows how to use SQL queries to update the various "Wordpress Address" and "Blog Address" options programattically.


如果你没有使用Interarchy,你仍然会发现这个脚本具有价值,因为这个脚本显示了怎样使用SQL查询,从软件程序方面,更新不同的"Wordpress 地址" 和"博客地址" 选项 。
如果你没有使用Interarchy,你仍然会发现这个脚本具有价值,因为这个脚本显示了怎样使用SQL查询,从软件程序方面,更新不同的"Wordpress 地址" 和"博客地址" 选项 。


{{Stub}}
{{Stub}}

2008年6月28日 (六) 16:08的版本

下面是我怎样在MacOS X上 为我的WordPress博客设置一个本地镜像。

动机和设想

首先,为什么要这么做?哦,我能够想到一些原因:

  • 保存一个最新的并且运转的文件备份
  • 在你将博客公之于众之前,用文件备份来测试博客上的变化。像格式,软件更新,或者其它的什么内容。
  • 非常有趣(MySQL设置除外,我们即将开始MySQL设置)

基本的方法是take a snapshot of the database and file system your hosting provider,将其下载并且在本地提取,然后再查看结果。

因此,我假定你在http://example.com (没有子目录)有一个博客。在下面的指示中,你可以用你自己的博客名来代替这个。出于怎样做的目的,我假定你以alastair登录(MacOS称这个为你的"简称")。

我还假定你正在运行MacOS X 10.3,而且希望安装最小的软件,使得过程更加简单。或者换句话说,尽可能地使用标准的OS发行版本。这样做,利用了patches和其它的更新,还有其它的好处。MacOS X10.3拥有先前安装好的Apache和PHP,我们所需要的就是MySQL和WordPress。(写好这篇文章的时候,10.3还是当前的版本,但是在10.4上这个过程是一样的,我个人对此进行检验过了)。

如果你想要升级到一个更新的PHP和MySQL,你会发现Andy Budd的指南很有用。

配置 Apache 和 PHP

首先要确定Apache和PHP都配置好了。确定Apache是在分享喜好板块上开始的:

个人网络分享

然后进入/etc/httpd/httpd.conf并且uncomment (例如开头部分的#) 下面的行:

LoadModule php4_module libexec/httpd/libphp4.so

...   
AddModule mod_php4.c

你可能要将这个像根目录一样编辑。一种方法是打开一个终端部分,并且输入sudo pico /etc/httpd/httpd.conf,但是我确定还有其它的方法。

现在,让我们来重启Apaceh… sudo apachectl graceful

…查看是否能够运行。在你的站点目录(在主目录内部)创建一个文件,命名为info.php。编辑文件,使得文件包含:

< ? php phpinfo(); ?>

然后在你的浏览器中打开http://localhost/~alastair/info.php(记住要替换你自己的名字)并且会对结果感到惊奇。你会得到PHP需要处理的所有的详细信息的列表。祝贺你,现在继续…

创建一个例子.mirror 静态网页

如果你在一个顶级级别的主机(如http://example.com而不是http://example.com/blog)上运行博客,你可能将你的内部站点链接设置使用绝对路径。事实上,我认为对于某些链接,像样式表,WordPress没有向你提供选择。

因此创建一个本地镜像的问题是,你需要为之创建一个主机名,这样不会与你在MacOS系统上运行的其它内容相冲突。如果你没有必要这样做,你只要随心所欲地跳到这个部分的末尾,只要将你的博客文件系统反映到/Library/网络服务器/文件

我们要做的是创建一个新的,伪造的主机名,并使得这个主机名在本地服务。已经采取了.本地最高级别域(用作Rendezvous),因此我们选择.mirror。本地镜像会在http://example.mirror

首先要做的是,将这个主机名添加到你的/etc/主机文件。只要添加:

127.0.0.1 example.mirror

你现在能够ping这个地址了:

alastair $ ping example.mirror

PING example.mirror (127.0.0.1): 56 data bytes  
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.159 ms  
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=5.078 ms  
^C  

--- example.mirror ping 统计数据 ---

2 packets transmitted, 2 packets received, 0% packet loss  
round-trip min/avg/max = 0.159/2.618/5.078 ms

[Aside: Bob Davis 描述了另一种,通过NetInfo 管理器执行的更好的操作。我没有测试这个,看起来是一种很好的方法,但是根据一篇Apple KB 文章,MacOS10.2以及以后的版本更乐意于编辑文章。我不知道为什么。]

现在继续,将这个作为VirtualHost添加到Apache配置。你想要做的可能是编辑/private/etc/httpd/users/alastair.conf(或者你的用户名)而不是主要的httpd.conf文件。这个minimises更改为主要的Apache配置文件和简化的更新。在任何情况下,你需要添加:

NameVirtualHost *:80

<VirtualHost *>
    DocumentRoot /Users/alastair/Sites/example.com
    ServerName example.mirror
    <Directory "/Users/alastair/Sites/example.com">
        Options FollowSymLinks
        AllowOverride All   
    </Directory>
</VirtualHost. 

这在一个特别的文件根中创建了一个新的虚拟主机。我们准备在这个目录中储存mirrored文件。

再次重新启动Apache:sudo apachectl graceful

现在是个好时机,任何人都可以将你的主机供应商的文件复制到这个本地镜像目录。你可以使用任何你喜欢的工具。如果你的供应商支持cPanel,你只能得到一个主目录文件备份,提取出相关文件(可能所有的内容都在public_html)。

我使用Interarchy,运行执行一个真正的mirror(例如,复制需要复制的文件)。如果你也使用Interarchy,请确定设置Interarchy是用作UNIX行结尾的,而不是用作Mac。

现在你应该能够看到你的博客的静态部分。WordPress自述文件能够很好地测试这一点,你可以在http://example.mirror/readme.html找到这个自述文件。如果迄今为止,一切顺利了,你应该正在阅读WordPress自述文件。

安装和配置MySQL

现在临到un-fun bit了,不管怎么说,un-fun bit是拥护我的。MacOS X有几种不同的MySQL,我尝试了其中的几个MySQL,但是MySQL AG标准发行的版本,似乎更适合我。问题是:哪个版本?答案取决于,你想要mirror哪个版本的MySQL。换句话说,你的主机供应商使用哪个版本?

一般的规则是,你可能与你的主机供应商使用同一个版本(例如x.y)。对于4.1版本以及以后发行的版本,我们会使用一个工作区更改4.1版本中引入的密码hashing算法。倒不是那个让你烦恼的。

你所要做的就是下载挑选的版本(例如4.0, 或者4.1 或者what-have you)并且将其安装。关于安装, 文章安装配置保护初始帐户的指示说明既详细又长,下面是PowerPoint幻灯片版本。

  • 为mysql软件和启动项运行installer。
  • (MacOS X 10.4.4+ 只有)更新你的/etc/my.cnf文件,指向socket的新的安全位置。请看看下面的注释。
  • sudo /Library/StartupItems/MySQLCOM/MySQLCOM start启动数据库服务器
  • cd /usr/local/mysql
  • sudo 脚本/mysql_安装_db –用户=mysql
  • bin/mysqladmin -u 根密码 一个-安全的-密码

MacOS X 10.4.4+用户需要设置MySQL服务器在一个socket上聆听而不是默认的socket。要做到这一点,就要创建一个拥有以下内容的/etc/my.cnf文件:

[mysqld]

socket=/var/mysql/mysql.sock

如果目录不存在的话,再创建一个目录: $ sudo mkdir /var/mysql

  $ sudo chown mysql /var/mysql

这是要匹配Apple的PHP安装所期望的新位置。同样,你只要为MacOS X 10.4.4+准备这个stuff。(但是在先前的版本中,这个stuff可能不会有危害)请阅读这儿得到(稍微)更多的信息。

注意,在上面最后一步中设置的根密码,不需要与我们之后使用的WordPress密码相同。事实上,如果根密码与我们之后使用的WordPress密码不同,会是一件好事。选一些你能够记住的内容作为密码。这时候,确定你能够访问数据库,因为根使用mysql工具,会是个好主意:

mysql $ bin/mysql -u root -p

输入密码: 

欢迎来到MySQL监控器。 命令行以 ; or \g结束。

Your MySQL connection id is 3 to server version: 4.1.15-standard

你的MySQL连接id是3,相对的服务器版本:4.1.15-标准

输入 'help;' 或者 '\h' 寻求帮助。输入 '\c' 清除缓冲区。

mysql>显示数据库;
+----------+
| 数据库 |
+----------+
| mysql    |
| 测试    |
+----------+
2 rows in set (0.00 sec)

mysql> \q
Bye

Mmmm, ASCII art!

核实你能够访问数据库,CocoaMySQL也是值得做的。确认你得到了MySQL安装的合适的版本(支持beta 版本中拥有的4.1+版本。

设置WordPress用户和数据库

几乎完成了!你只要为WordPress博客安装一个用户/密码和数据库,应该与你的wp-config.php文件中的设置相匹配!严格地说,不需要匹配,但是如果你想下载你的博客并且马上将博客运行,匹配信息会帮你使用同样的详细的连接信息。假定用户名是example_u,数据库称为example_db,密码是example_pw

首先连接到数据库并且为WordPress用户添加保证:

mysql $ bin/mysql -u root -p

输入密码: 
欢迎来到 MySQL监控器。  命令以 ; or \g结束。
你的 MySQL连接id 是 4 ,服务器版本是: 4.1.15-标准的

然后输入 'help;' 或者'\h' 寻求帮助。 输入 '\c' to 清除缓冲区。

mysql> grant all on example_db.* to 'example_u'@'localhost';
Query OK, 0 rows affected (0.00 sec)

如果你使用MySQL4.0而不是更高的版本,那么设置密码的过程会有所不同。如果你使用MySQL4.0,请使用:

mysql> set password for 'example_u'@'localhost' = password('example_pw');
Query OK, 0 rows affected (0.06 sec)

或者这个用于4.1+:

mysql> set password for 'example_u'@'localhost' = old_password('example_pw');
Query OK, 0 rows affected (0.05秒)

[MacOS X 10.4.4+ 更新: 我认为 密码 方法 (ie the first of the two statements above) 同样适用于MacOS X 10.4.4 及以后的版本, 虽然我自己还没有证实。]

现在创建数据库:

mysql> create database example_db;
Query OK, 1 row affected (0.00 sec)

mysql> \q

如果一切进展顺利,我们可以从主机供应商那里导入博客数据库。假定你已经下载了这个单一的压缩的数据库(例如,如cPanel支持的文件备份功能)。如果数据库dump称为example.gz,我们可能会:

alastair $ gzcat example.gz | mysql -u example_u -p example_db

输入密码: (example_pw)

这时,可能要付款使用CocaMySQL或者mysql命令工具,访问数据库,并且核实所有的内容是否都成功地导入了。如果没有成功导入,你可能在上面的命令中,得到许多错误信息。

完成

现在是关键时刻了。打开你的浏览器中的http://example.mirror。如果一切进展顺利,就应该显示你的博客了。

你可能注意到一些链接在example.com上仍然指向你的原始站点。要解决这个问题,你需要在http://example.mirror/wp-admin/options-general.php 中的WordPress总选项,中更新"Wordpress 地址" 和 "博客地址"。

使其自动化

有几种不同的方法,用博客内容自动更新本地镜像。这些方法取决于你拥有什么工具,以及你的主机供应商有什么工具。我在下面列出来了我使用的AppleScript,给你提供一些灵感。AppleScript依赖于Interarchy进行文件传输。

--自动更新WordPress一个站点的本地镜像的脚本 --

-- 由 alastair@girtby.net写的
--
-- 由Creative Commons Attribution License得到许可,
-- 请看看 http://creativecommons.org/licenses/by/2.0/

--设置这些来匹配你的wp-config.php
property u : "example_u"
property db : "example_db"
property pw : "example_pw"

-- 更新WordPress 选项来使用这个url
property newurl : "http://example.mirror"

--像这样地调用 mysql
将mysqlcmd设置为 "/usr/local/mysql/bin/mysql -u " & u & " -p" & pw & " " & db

-- 站点文件在这儿: 
将 dest 设置为 alias ((path to home folder from user domain as string) & "Sites:example.com:")

-- 从这儿下载数据库:
set tempDir to path to "temp" from user domain

tell application "Interarchy"
	-- 反映站点的静态部分
	mirrordownload dest host "ftp.example.com" path "public_html" user "example"
	
	-- 下载数据库(disable post process files preference)
	set ppf to contents of preference "PostProcessFiles"
	set contents of preference "PostProcessFiles" to "false"
	webfetch tempDir url "http://example.com:2082/getsqlbackup/wrdp1.gz" user "example"
	set contents of preference "PostProcessFiles" to ppf
end tell

将 dbfile设置为POSIX path of ((tempDir as string) & "wrdp1.gz")

-- 导入数据库
do shell script "gzcat " & dbfile & "| " & mysqlcmd

-- 清除: 移除数据库文件
do shell script "rm " & dbfile

-- 在wordpress中修复站点url和主页选项
do shell script "echo 'update wp_options set option_value = \"" & newurl & "\" where option_name = \"home\"; update wp_options set option_value = \"" & newurl & "\" where option_name = \"siteurl\";' | " & mysqlcmd

为了使得这个脚本运行,你需要在脚本编辑器中编辑脚本,并且更改不同的位置,URLs和密码。希望这些能够轻易地执行。此外,你需要向keychain添加密码,以下载你的静态站点,访问你的数据库dump,这样Interarchy能够找到这些内容。执行这一步的最好方法,是在Interarchy中交互式地访问站点并且确定在检验框中点击了"向 Keychain添加密码"。

如果你没有使用Interarchy,你仍然会发现这个脚本具有价值,因为这个脚本显示了怎样使用SQL查询,从软件程序方面,更新不同的"Wordpress 地址" 和"博客地址" 选项 。

This page is [[WordPress::Category:Stubs|marked]] as incomplete. You can help Codex by expanding it.