在Ubuntu 18.04上使用Sitecopy维护远程网站

在Ubuntu 18.04上使用Sitecopy维护远程网站

Sitecopy是用于将本地存储的网站复制到远程Web服务器(通过FTP或WebDAV)的工具。通过上传修改的本地文件并删除在本地计算机上删除的远程文件,它可以帮助您使远程站点与本地副本保持同步。本教程向您展示如何使用Sitecopy从本地Ubuntu 18.04桌面管理远程站点。

1初步说明

直到我在本地Ubuntu桌面上都使用用户名(我以该用户身份在本地Linux桌面上登录-请不要以root用户身份登录)。远程网站example.com的文件存储在本地计算机上的目录/home/till/sites/example.com/中。远程文档的根目录是/var/www/example.com/web/。

您可以将sitecopy与FTP和WebDAV一起使用,因此远程服务器上应该具有FTP或WebDAV帐户。我在这里使用FTP用户名defaulttill和密码howforforge。

我用于这些示例的远程网站已使用ISPConfig创建。但是您可以访问FTP或WebDAV的任何站点都可以使用。

2安装sitecopy

Sitecopy可以按以下方式安装在本地桌面上(我们需要root特权,因此我们使用sudo):

sudo apt-get -y install sitecopy

现在,您应该查看sitecopy的手册页,以熟悉其选项:

man sitecopy

3配置站点副本

转到本地桌面上的主目录…

cd ~

…并创建权限为700的目录.sitecopy(sitecopy使用该目录存储文件详细信息):

mkdir -m 700 .sitecopy

接下来,创建sitecopy配置文件.sitecopyrc:

touch .sitecopyrc
chmod 600 .sitecopyrc

打开文件…

nano .sitecopyrc

…并填写example.com网站的配置。这是两个示例,一个用于FTP …

site example.com
  server example.com
  username defaulttill
  password howtoforge
  local /home/till/sites/example.com/
  remote ~/web/
  exclude *.bak
  exclude *~

…和一个用于WebDAV的:

site example.com
  server example.com
  protocol webdav
  username defaulttill
  password howtoforge
  local /home/till/sites/example.com/
  remote /var/www/example.com/web/
  exclude *.bak
  exclude *~

(您可以为要使用sitecopy管理的每个网站定义一个节。)

网站指令后必须跟网站名称-您可以自由选择一个,例如example.com或mysite。稍后将在sitecopy命令中使用此名称。属于该站点的以下配置选项必须缩进

以下大多数配置选项是不言自明的。默认协议是FTP;默认协议是FTP。如果要使用WebDAV,请指定协议webdav。 local指令包含网站副本的本地路径,remote包含远程服务器上网站的路径-它可以是绝对路径或相对路径。如果您的用户是chroot(通常是FTP用户),则应使用相对路径(例如〜/或〜/ web)。否则,请使用绝对路径。

排除行是可选的,它们仅用于说明如何排除站点复制维护的文件。

您可以在其手册页上找到有关sitecopy配置的更多信息:

man sitecopy

4首次使用

首次使用sitecopy之前,您必须确定以下三种情况中的哪一种符合您的情况:

  1. 现有的远程站点和本地副本都同步。
  2. 现有的远程站点,没有本地副本。
  3. 新的远程站点,现有的本地副本。

4.1现有的远程站点和本地副本,均同步

如果远程站点和本地副本都存在并且同步,请运行

sitecopy --catchup example.com

使sitecopy认为本地站点与远程副本完全相同。将example.com替换为您在.sitecopyrc文件中使用的网站的名称。

[email protected]:~$sitecopy --catchup example.com
sitecopy: Catching up site `example.com' (on example.com in ~/web/)
sitecopy: All the files and and directories are marked as updated remotely.

4.2现有远程站点,无本地副本

如果您没有现有远程网站的本地副本,请运行

sitecopy --fetch example.com

首先,以便sitecopy从远程服务器获取文件列表(将example.com替换为您在.sitecopyrc文件中使用的站点的名称):

[email protected]:~$sitecopy --fetch example.com
sitecopy: Fetching site `example.com' (on example.com in ~/web/)
File: error/503.html - size 1906
File: error/502.html - size 1881
File: error/500.html - size 1851
File: error/405.html - size 1810
File: error/404.html - size 1806
File: error/403.html - size 1809
File: error/401.html - size 1806
File: error/400.html - size 1792
File: stats/.htaccess - size 128
File: robots.txt - size 14
File: index.html - size 1861
File: favicon.ico - size 7358
File: .htaccess - size 26
Directory: error/
Directory: stats/
sitecopy: Fetch completed successfully.

然后跑

sitecopy --synch example.com

从远程副本更新本地站点。

sitecopy: Synchronizing site `example.com' (on example.com in ~/web/)
Creating error/: done.
Creating stats/: done.
Downloading error/503.html: [.] done.
Downloading error/502.html: [.] done.
Downloading error/500.html: [.] done.
Downloading error/405.html: [.] done.
Downloading error/404.html: [.] done.
Downloading error/403.html: [.] done.
Downloading error/401.html: [.] done.
Downloading error/400.html: [.] done.
Downloading stats/.htaccess: [.] done.
Downloading robots.txt: [.] done.
Downloading index.html: [.] done.
Downloading favicon.ico: [.] done.
Downloading .htaccess: [.] done.
sitecopy: Synchronize completed successfully.

4.3新的远程站点,现有的本地副本

如果本地副本存在,但是您有一个空的远程站点,请运行

sitecopy --init example.com

首先初始化网站。将example.com替换为您在.sitecopyrc文件中使用的网站的名称。

[email protected]:~$sitecopy --init example.com
sitecopy: Initializing site `example.com' (on example.com in ~/web/)
sitecopy: All the files and directories are marked as NOT updated remotely.

然后运行:

sitecopy --update example.com

将本地副本上传到远程站点:

[email protected]:~$sitecopy --update example.com
sitecopy: Updating site `example.com' (on example.com in ~/web/)
Creating stats/: done.
Creating data/: done.
Creating error/: done.
Uploading stats/.htaccess: [.] done.
Uploading data/index.html: [.] done.
Uploading error/403.html: [.] done.
Uploading error/401.html: [.] done.
Uploading error/404.html: [.] done.
Uploading error/503.html: [.] done.
Uploading error/400.html: [.] done.
Uploading error/502.html: [.] done.
Uploading error/405.html: [.] done.
Uploading error/500.html: [.] done.
Uploading index.html: [.] done.
Uploading robots.txt: [.] done.
Uploading .htaccess: [.] done.
Uploading favicon.ico: [.] done.
sitecopy: Update completed successfully.

5使用sitecopy

之后,使用站点拷贝确实非常容易。您可以使用本地副本以及更新,创建和删除文件。第一步,但可选步骤是运行

sitecopy example.com

找出哪些文件已在本地更改(将example.com替换为您在.sitecopyrc文件中使用的站点名称):

[email protected]:~$sitecopy example.com
sitecopy: Showing changes to site `example.com' (on example.com in ~/web/)
* These items have been added since the last update:
info.php
sitecopy: The remote site needs updating (1 item to update).

要将您的远程网站与本地副本同步(即,将新的和更改的文件上传到远程服务器,并删除已在本地删除的远程服务器上的文件),只需运行

sitecopy --update example.com
[email protected]:~$sitecopy --update example.com
sitecopy: Updating site `example.com' (on example.com in ~/web/)
Uploading info.php: [] done.
sitecopy: Update completed successfully.

而已尽情享受sitecopy

6个链接

  • sitecopy:http://www.manyfish.co.uk/sitecopy/
  • Ubuntu:http://www.ubuntu.com/

资讯来源:由0x资讯编译自HOWTOFORGE,版权归作者所有,未经许可,不得转载
你可能还喜欢