搭建backup服务器rsyncdaemon服务模式之二rsync客户端配置

本文中rsync客户端有两个网卡:网卡1连接外网,ip地址和掩码为10.0.0.31/24;网卡2连接内网,ip地址和掩码为172.16.1.31/24

搭建backup服务器rsyncdaemon服务模式之二rsync客户端配置

1.检查客户端是否有rsync服务:

[root@oldboy ~]# rsync --version
rsync  version 3.0.6  protocol version 30
Copyright (C) 1996-2009 by Andrew Tridgell, Wayne Davison, and others.
Web site: http://rsync.samba.org/
Capabilities:
    64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,
    socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace,
    append, ACLs, xattrs, iconv, symtimes

rsync comes with ABSOLUTELY NO WARRANTY.  This is free software, and you
are welcome to redistribute it under certain conditions.  See the GNU
General Public Licence for details.
[root@oldboy ~]# rpm -qa rsync
rsync-3.0.6-12.el6.x86_64

2.客户端编辑/etc/rsync.password留下密码oldboy

[root@oldboy ~]# echo "oldboy" >/etc/rsync.password
[root@oldboy ~]# cat /etc/rsync.password 
oldboy

因为有密码所以是600全新

[root@oldboy ~]# chmod 600 /etc/rsync.password
[root@oldboy ~]# ll /etc/rsync.password 
-rw------- 1 root root 0 Aug  3 00:43 /etc/rsync.password

3.创建backup目录,目的:打包,推送,删除。本地临时备份目录

[root@oldboy ~]# mkdir -p /backup
[root@oldboy ~]# cd /backup
[root@oldboy backup]# touch stu{01..100}

[root@oldboy backup]# ls
stu001  stu011  stu021  stu031  stu041  stu051  stu061  stu071  stu081  stu091
stu002  stu012  stu022  stu032  stu042  stu052  stu062  stu072  stu082  stu092
stu003  stu013  stu023  stu033  stu043  stu053  stu063  stu073  stu083  stu093
stu004  stu014  stu024  stu034  stu044  stu054  stu064  stu074  stu084  stu094
stu005  stu015  stu025  stu035  stu045  stu055  stu065  stu075  stu085  stu095
stu006  stu016  stu026  stu036  stu046  stu056  stu066  stu076  stu086  stu096
stu007  stu017  stu027  stu037  stu047  stu057  stu067  stu077  stu087  stu097
stu008  stu018  stu028  stu038  stu048  stu058  stu068  stu078  stu088  stu098
stu009  stu019  stu029  stu039  stu049  stu059  stu069  stu079  stu089  stu099
stu010  stu020  stu030  stu040  stu050  stu060  stu070  stu080  stu090  stu100

4.推送到服务器端

根据: https://www.samba.org/ftp/rsync/rsync.html

SYNOPSIS


Local:  rsync [OPTION...] SRC... [DEST]

Access via remote shell:
  Pull: rsync [OPTION...] [USER@]HOST:SRC... [DEST]
  Push: rsync [OPTION...] SRC... [USER@]HOST:DEST

Access via rsync daemon:
  Pull: rsync [OPTION...] [USER@]HOST::SRC... [DEST]
        rsync [OPTION...] rsync://[USER@]HOST[:PORT]/SRC... [DEST]
  Push: rsync [OPTION...] SRC... [USER@]HOST::DEST
        rsync [OPTION...] SRC... rsync://[USER@]HOST[:PORT]/DEST


把本机的/backup/目录下面的stu01-stu100这100个文件推送到rsync服务端172.16.1.41中,两个命令都是推送到服务端,每个命令172.16.1.41后面的backup代表模块意思。

[root@oldboy ~]# rsync -avz /backup/ rsync_backup@172.16.1.41::backup/ --password-file=/etc/rsync.password

[root@oldboy backup]# rsync -avz /backup/ rsync://rsync_backup@172.16.1.41/backup/ --password-file=/etc/rsync.password

推送成功会提示:

sent 5733 bytes  received 1911 bytes  15288.00 bytes/sec
total size is 0  speedup is 0.00

推送完后,到服务端172.16.1.41的/backup目录下面查看是否有推送的文件。


rsync客户端

1.生成连接服务器需要的密码文件

echo "oldboy" >/etc/rsync.password

cat /etc/rsync.password

2.为密码文件配置权限

chmod 600 /etc/rsync.password

ls -l /etc/rsync.password

3.同步文件。ip地址代表rsync服务端ip,举例如下所示:

推送:

rsync -avz /tmp/ rsync_backup@10.0.0.8::oldboy --password-file=/etc/rsync.password

rsync -avz /tmp rsync://rsync_backup@10.0.0.8/backup/ --password-file=/etc/rsync.password

拉取:

rsync -avz rsync_backup@10.0.0.8::oldboy /tmp/ --password-file=/etc/rsync.password

rsync -avz rsync://rsync_backup@10.0.0.8/backup/ /tmp --password-file=/etc/rsync.password

提示:上述ip地址后面的backup为模块名,不是路径

本文转自sandshell博客51CTO博客,原文链接http://blog.51cto.com/sandshell/1953172如需转载请自行联系原作者


sandshell

上一篇:阿里云企业邮箱 在Foxmail 7.0上POP3/IMAP协议设置方法


下一篇:SUSE_FTP服务搭建