利用rsync備份生產應用(二)
概述
上節主要是針對rsync服務端進行的配置和詳解,本節主要針對在客戶端上的rsync配置進行講解。
rsync用法
本地到本地
語法:rsync [OPTION...] SRC... [DEST]
用法示例一:將/home/kl/ss目錄裏的內容同步到/home/kl/ss_new目錄中
[[email protected] ~]$ ls -l 總用量 16 drwxr-xr-x. 4 root root 4096 7月 19 12:23 newss drwxr-xr-x. 4 kl kl 4096 7月 19 12:23 ss drwxrwxr-x. 2 kl kl 40968月 2 10:37 ss_new drwxrwxr-t. 2 kl kl 4096 7月 21 13:18 test [[email protected]-datanode1 ~]$ rsync -azvP ss/ ss_new/ sending incremental file list ./ auditd 3580 100% 0.00kB/s 0:00:00 (xfer#1, to-check=68/70) blk-availability 1343 100% 1.28MB/s 0:00:00 (xfer#2, to-check=67/70) crond2826 100% 2.70MB/s 0:00:00 (xfer#3, to-check=66/70) functions 25419 100% 4.04MB/s 0:00:00 (xfer#4, to-check=65/70) halt 5985 100% 730.59kB/s 0:00:00 (xfer#5, to-check=64/70) ............ ............ ss/udev-post 2294 100% 31.11kB/s 0:00:00 (xfer#66, to-check=1/70) ss/newss/ sent 119700 bytes received 1281bytes 241962.00 bytes/sec total size is 332288 speedup is 2.75 [[email protected]-datanode1 ~]$ ls -l ss_new/ 總用量 236 -rwxr-xr-x. 1 kl kl 3580 7月 19 12:03 auditd -rwxr-xr-x. 1 kl kl 1343 7月 19 12:03 blk-availability -rwxr-xr-x. 1 kl kl 2826 7月 19 12:03 crond -rwxr-xr-x. 1 kl kl 25419 7月 19 12:03 functions -rwxr-xr-x. 1 kl kl 5985 7月 19 12:03 halt ................
用法示例二:只接源目錄表示列出源目錄裏面的文件內容,這個時候DEST參數是省略不使用的
[[email protected] ~]$ rsync ss/ drwxr-xr-x 4096 2017/07/19 12:23:20 . -rwxr-xr-x 3580 2017/07/19 12:03:52 auditd -rwxr-xr-x 1343 2017/07/19 12:03:52 blk-availability -rwxr-xr-x 2826 2017/07/19 12:03:52 crond -rwxr-xr-x 25419 2017/07/19 12:03:52 functions -rwxr-xr-x 5985 2017/07/19 12:03:52 halt -rwxr-xr-x 11169 2017/07/19 12:03:52 ip6tables -rwxr-xr-x 11048 2017/07/19 12:03:52 iptables -rwxr-xr-x 9980 2017/07/19 12:03:52 jexec -rwxr-xr-x 20634 2017/07/19 12:03:52 kdump -rwxr-xr-x 652 2017/07/19 12:03:52 killall -rwxr-xr-x 2137 2017/07/19 12:03:52 lvm2-lvmetad -rwxr-xr-x 3045 2017/07/19 12:03:52 lvm2-monitor -rwxr-xr-x 2571 2017/07/19 12:03:52 mdmonitor -rwxr-xr-x 2200 2017/07/19 12:03:52 messagebus -rwxr-xr-x 2989 2017/07/19 12:03:52 netconsole -rwxr-xr-x 5309 2017/07/19 12:03:52 netfs -rwxr-xr-x 6406 2017/07/19 12:03:52 network -rwxr-xr-x 3570 2017/07/19 12:03:52 nfs-rdma -rwxr-xr-x 1923 2017/07/19 12:03:52 ntpd ...................
服務端同步到本地(Pull)
這種方式也分為SSH和RSYNC兩種同步方式
通過SSH方式進行同步
語法:rsync [OPTION...] [USER@]HOST:SRC... [DEST]
實際案例:
我有兩臺主機cdh-datanode1和cdh-datanode2,現在我想同步cdh-datanode2上/root目錄下所有的內容到cdh-datanode1的/home/kl/test目錄下
在這裏SRC就表示cdh-datanode2 上的/root,DEST就表示cdh-datanode1上的/home/kl/test.所以記住一點,你要進行同步的目錄文件所在的設備是作為SRC的
[[email protected] test]$ rsync -azvP [email protected]:/root/ /home/kl/test/ The authenticity of host ‘cdh-datanode2 (192.168.100.102)‘ can‘t be established. RSA key fingerprint is SHA256:BOi8rknsSr1IzI7fqGyWUGbAdp5hz/rmf0nnQ/DYKO4. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added ‘cdh-datanode2,192.168.100.102‘ (RSA) to the list of known hosts. [email protected]-datanode2‘s password: bash: rsync: command not found rsync: connection unexpectedly closed (0 bytes received so far) [receiver] rsync error: remote command not found (code 127) at io.c(600) [receiver=3.0.6] [[email protected]-datanode1 test]$ rs rsvg rsvg-convert rsvg-view rsync rsyslogd [[email protected]-datanode1 test]$ rsync -azvP [email protected]:/root/ /home/kl/test/ [email protected]-datanode2‘s password: receiving incremental file list ./ .Xauthority 59 100% 57.62kB/s 0:00:00 (xfer#1, to-check=41/43) .bash_history 1095 100% 1.04MB/s 0:00:00 (xfer#2, to-check=40/43) .bash_logout 18 100% 17.58kB/s 0:00:00 (xfer#3, to-check=39/43) .bash_profile 176 100% 85.94kB/s 0:00:00 (xfer#4, to-check=38/43) .bashrc 176 100% 85.94kB/s 0:00:00 (xfer#5, to-check=37/43) .cshrc 100 100% 24.41kB/s 0:00:00 (xfer#6, to-check=36/43) .tcshrc 129 100% 31.49kB/s 0:00:00 (xfer#7, to-check=35/43) .viminfo 670 100% 130.86kB/s 0:00:00 (xfer#8, to-check=34/43) anaconda-ks.cfg 1096 100% 178.39kB/s 0:00:00 (xfer#9, to-check=33/43) id_rsa.pub 399 100% 55.66kB/s 0:00:00 (xfer#10, to-check=32/43) install.log 14625 100% 1.07MB/s 0:00:00 (xfer#11, to-check=31/43) install.log.syslog 3482 100% 242.89kB/s 0:00:00 (xfer#12, to-check=30/43) jdk-7u80-linux-x64.rpm 138090286 100% 5.83MB/s 0:00:22 (xfer#13, to-check=29/43) salt-rhel6_v201603.zip 12734065 100% 5.56MB/s 0:00:02 (xfer#14, to-check=28/43) .ssh/ .ssh/authorized_keys 399 100% 2.06kB/s 0:00:00 (xfer#15, to-check=25/43) .ssh/known_hosts 397 100% 2.04kB/s 0:00:00 (xfer#16, to-check=24/43) salt-rhel6_v201603/ salt-rhel6_v201603/PyYAML-3.11-1.el6.x86_64.rpm 155352 100% 692.74kB/s 0:00:00 (xfer#17, to-check=23/43) salt-rhel6_v201603/install_saltstack.sh 2634 100% 11.64kB/s 0:00:00 (xfer#18, to-check=22/43) salt-rhel6_v201603/libyaml-0.1.3-4.el6.x86_64.rpm 52624 100% 223.44kB/s 0:00:00 (xfer#19, to-check=21/43) salt-rhel6_v201603/openpgm-5.2.122-2.el6.x86_64.rpm 169716 100% 611.58kB/s 0:00:00 (xfer#20, to-check=20/43) salt-rhel6_v201603/python-babel-0.9.4-5.1.el6.noarch.rpm 1493972 100% 2.38MB/s 0:00:00 (xfer#21, to-check=19/43) salt-rhel6_v201603/python-backports-1.0-5.el6.x86_64.rpm 5024 100% 8.14kB/s 0:00:00 (xfer#22, to-check=18/43) salt-rhel6_v201603/python-backports-ssl_match_hostname-3.4.0.2-2.el6.noarch.rpm 11416 100% 18.40kB/s 0:00:00 (xfer#23, to-check=17/43) salt-rhel6_v201603/python-chardet-2.2.1-1.el6.noarch.rpm 234768 100% 349.49kB/s 0:00:00 (xfer#24, to-check=16/43) salt-rhel6_v201603/python-crypto-2.6.1-2.el6.x86_64.rpm 512828 100% 633.93kB/s 0:00:00 (xfer#25, to-check=15/43) salt-rhel6_v201603/python-futures-3.0.3-1.el6.noarch.rpm 27028 100% 33.28kB/s 0:00:00 (xfer#26, to-check=14/43) salt-rhel6_v201603/python-jinja2-2.7.3-1.el6.noarch.rpm 531148 100% 608.09kB/s 0:00:00 (xfer#27, to-check=13/43) salt-rhel6_v201603/python-markupsafe-0.11-10.el6.x86_64.rpm 24296 100% 27.69kB/s 0:00:00 (xfer#28, to-check=12/43) salt-rhel6_v201603/python-msgpack-0.4.6-1.el6.x86_64.rpm 69704 100% 78.42kB/s 0:00:00 (xfer#29, to-check=11/43) salt-rhel6_v201603/python-ordereddict-1.1-2.el6.noarch.rpm 7244 100% 8.09kB/s 0:00:00 (xfer#30, to-check=10/43) salt-rhel6_v201603/python-requests-2.6.0-3.el6.noarch.rpm 96960 100% 106.15kB/s 0:00:00 (xfer#31, to-check=9/43) salt-rhel6_v201603/python-six-1.9.0-2.el6.noarch.rpm 28500 100% 30.96kB/s 0:00:00 (xfer#32, to-check=8/43) salt-rhel6_v201603/python-tornado-4.2.1-1.el6.x86_64.rpm 676864 100% 640.50kB/s 0:00:01 (xfer#33, to-check=7/43) salt-rhel6_v201603/python-urllib3-1.10.2-1.el6.noarch.rpm 102716 100% 1.81MB/s 0:00:00 (xfer#34, to-check=6/43) salt-rhel6_v201603/python-zmq-14.5.0-2.el6.x86_64.rpm 490712 100% 2.98MB/s 0:00:00 (xfer#35, to-check=5/43) salt-rhel6_v201603/salt-2016.3.0-1.el6.noarch.rpm 6543724 100% 3.99MB/s 0:00:01 (xfer#36, to-check=4/43) salt-rhel6_v201603/salt-master-2016.3.0-1.el6.noarch.rpm 1440128 100% 1.57MB/s 0:00:00 (xfer#37, to-check=3/43) salt-rhel6_v201603/salt-minion-2016.3.0-1.el6.noarch.rpm 31984 100% 35.53kB/s 0:00:00 (xfer#38, to-check=2/43) salt-rhel6_v201603/yum-utils-1.1.30-30.el6.noarch.rpm 112332 100% 122.57kB/s 0:00:00 (xfer#39, to-check=1/43) salt-rhel6_v201603/zeromq-4.0.5-4.el6.x86_64.rpm 581800 100% 551.62kB/s 0:00:01 (xfer#40, to-check=0/43) sent 782 bytes received 162931774 bytes 4722682.78 bytes/sec total size is 164250646 speedup is 1.01
上面第一次進行rsync同步SRC到DEST的時候出錯了,經過排錯發現是因為SRC設備上未安裝rsync可執行程序的,在SRC設備上安裝好後再次執行就好了。
通過RSYNC DEAMON進行同步
語法:
rsync [OPTION...] [USER@]HOST::SRC... [DEST]
rsync [OPTION...] rsync://[USER@]HOST[:PORT]/SRC... [DEST]
案例見”利用rsync備份生產應用(一)” 小節”從備份服務器下載文件(pull)”,這裏需要註意的是SRC裏面指代的路徑開頭是在rsync服務器配置文件中的模塊的名字,有不清楚的詳看”利用rsync備份生產應用(一)”
本地同步到服務端(Push)
這種方式也分為SSH和RSYNC兩種同步方式
通過SSH方式進行同步
語法:rsync [OPTION...] SRC... [USER@]HOST:DEST
實際案例:
我有兩臺主機cdh-datanode1和cdh-datanode2,現在我想同步cdh-datanode1上/home/kl/test目錄下所有的內容到cdh-datanode2的/root目錄下
[[email protected] test]$ rsync -azvP /home/kl/test/ [email protected]:/root/ [email protected]-datanode2‘s password: sending incremental file list ./ .viminfo 670 100% 0.00kB/s 0:00:00 (xfer#1, to-check=34/43) .ssh/ salt-rhel6_v201603/ sent 2064 bytes received 171 bytes 406.36 bytes/sec total size is 164250646 speedup is 73490.22 [[email protected]-datanode1 test]$
通過RSYNC DEAMON進行同步
語法:
rsync [OPTION...] SRC... [USER@]HOST::DEST
rsync [OPTION...] SRC... rsync://[USER@]HOST[:PORT]/DEST
案例見”利用rsync備份生產應用(一)” 小節”備份文件到備份服務器(push)”,這裏需要註意的是DEST裏面指代的路徑開頭是在rsync服務器配置文件中的模塊的名字,有不清楚的詳看”利用rsync備份生產應用(一)”
利用rsync備份生產應用(二)