3.1. sync 命令

3.1.1. 介绍
3.1.2. A Simple Example
3.1.3. Rsync over SSH

实话实说:我现在主要是用 unison ,已经基本上不用 sync 命令了。因为我更看中 unison 的双向同步,以及 unison 对上次同步状态的保持,同步速度快。

2002年写的 sync 命令介绍,还是留着吧,有时候也需要单向数据备份吧。

3.1.1. 介绍

Rsync is a tool for archiving and file transfer that employs a clever algorithm to minimize data transfers. If two files are almost identical, only the differences will be transported over the network.

Rsync 适合进行双机备份。

3.1.2. A Simple Example

The following command, will sync local directory, public-html, to the remote server 10.0.0.x. i.e., copy date from local client to remote server.

$ rsync -a public_html/ 10.0.0.x:public_html

The following command, will sync directory, public-html, from the remote server 10.0.0.x to the local client. i.e., copy data from remote server to local client.

$ rsync -a 10.0.0.x:public_html/ public_html

考虑到安全性,和实现自动登陆以有利于自动同步数据,参见下节介绍的 Rsync over SSH 和 Passwordless SSH Authentication。

3.1.3. Rsync over SSH

One of the best feature of rsync is that it works over multiple transport protocols. By default, rsync uses rsh to do its work, but since rsh is deprecated in the Queen's Physics Department, we will use the secure shell (ssh) as the underlying transport mechanism, thus providing for secure, encrypted file transfers.

$ rsync -av public_html/ -e ssh 10.0.0.x:public_html

A more complicate sample:

$ /usr/bin/rsync -e ssh -avzp --exclude "*.journal" --exclude "dnscache/" --exclude "dnscachex/" \
	--delete /home remotehost:/var/backups/mycomputer/ 

Archive and mirror /home onto the remotehost's /var/backups/mycomputer directory and keep all the permissions. Note that *.journal are the journal files on ext3 partitions and don't need to be copied and the --delete flag can be omitted in case you want to keep old file that have been deleted archived on the remotehost side permenently.