我整个下午都在研究rsync。我已经设置了一个rsync服务器,但我不知道如何使用它。
我有两台机器:66和12。66是服务器,我想将66的数据备份到12,所以我使用rsync。
我做了以下事情:
66年:
sudo apt-get install xinetd
sudo vim /etc/xinetd.d/rsync
service rsync
{
disable = no
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
sudo nano /etc/rsyncd.conf
max connections = 2
log file = /var/log/rsync.log
timeout = 300
[wwwroot]
comment = Public Share
path = /home/wwwroot
read only = no
list = yes
uid = nobody
gid = nogroup
auth userusers = user
secrets file = /home/rsync.secrets
sudo /etc/init.d/xinetd restart
12:
rsync -v [email protected]::wwwroot /home/young001/backup --password-file=/home/rsync.pass
它告诉我们:
skipping directory .
sent 4 bytes received 6 bytes 2.86 bytes/sec
total size is 0 speedup is 0.00
日志是:
2013/06/12 03:18:18 [30477] name lookup failed for 125.221.225.12: Name or service not known
2013/06/12 03:18:18 [30477] connect from UNKNOWN (125.221.225.12)
2013/06/12 10:18:18 [30477] rsync on ctp/ from young001@UNKNOWN (125.221.225.12)
2013/06/12 10:18:18 [30477] building file list
2013/06/12 10:18:18 [30477] skipping directory .
2013/06/12 10:18:18 [30477] sent 98 bytes received 54 bytes total size 0
2013/06/12 03:19:59 [30484] name lookup failed for 125.221.225.12: Name or service not known
2013/06/12 03:19:59 [30484] connect from UNKNOWN (125.221.225.12)
2013/06/12 10:19:59 [30484] rsync on ctp/ from young001@UNKNOWN (125.221.225.12)
2013/06/12 10:19:59 [30484] building file list
2013/06/12 10:19:59 [30484] skipping directory .
2013/06/12 10:19:59 [30484] sent 98 bytes received 54 bytes total size 0
似乎告诉该目录是空的,但我不知道哪个目录是空的。
/home/young001/backup 是一个空目录,而 /home/wwwroot 不是一个空目录。
我想将 wwwroot 同步到备份,那么我哪里做错了?
答案1
在12
盒子(从服务器提取备份的盒子)上使用以下命令:
rsync -av [email protected]::wwwroot /home/young001/backup --password-file=/home/rsync.pass
该-a
选项是 rsync 存档模式:旨在递归到目录并保留几乎所有内容。检查 rsync 人。
Rsync 默认不递归复制目录,您必须使用-a
或-r
选项。
答案2
1.这会将远程目录同步到本地目录
sudo rsync -r -a -v [email protected]:/path/to/remote/directory/ /path/to/local/directory/ 2>&1
2.这会将本地目录同步到远程目录
sudo rsync -r -a -v /path/to/local/directory/ [email protected]:/path/to/remote/directory/ 2>&1
中2>&1
,1
表示标准输出( stdout
)。表示2
标准误差 ( stderr
)。
因此,2>&1
表示将标准错误发送到标准输出也被重定向的位置。因为它被发送到,/dev/null
所以要求完全忽略任何输出。这样,如果出现错误,您就可以看到错误是什么。
--delete : delete files that don't exist on sender (system)
-v : Verbose (try -vv for more detailed information)
-e "ssh options" : specify the ssh as remote shell
-a : archive mode
-r : recurse into directories
-z : compress file data
欲了解更多信息rsync
用这个。