歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> Linux系統下的數據鏡像備份工具——Rsync

Linux系統下的數據鏡像備份工具——Rsync

日期:2017/3/1 13:51:18   编辑:關於Linux

1、什麼是rsync

rsync,remote synchronize顧名思意就知道它是一款實現遠程同步功能的軟件,它在同步文件的同時,可以保持原來文件的權限、時間、軟硬鏈接等附加信息。 rsync是用“rsync 算法”提供了一個客戶機和遠程文件服務器的文件同步的快速方法,而且可以通過ssh方式來傳輸文件,這樣其保密性也非常好,另外它還是免費的軟件。

  rsync 包括如下的一些特性:

  能更新整個目錄和樹和文件系統;
  有選擇性的保持符號鏈鏈、硬鏈接、文件屬於、權限、設備以及時間等;
  對於安裝來說,無任何特殊權限要求;
  對於多個文件來說,內部流水線減少文件等待的延時;
  能用rsh、ssh 或直接端口做為傳輸入端口;
  支持匿名rsync 同步文件,是理想的鏡像工具;

2、rsync的安裝,通用方式:yum install rsync

3、rsync服務器的配置文件

cat /etc/rsyncd/rsync.conf 
# Distributed under the terms of the GNU General Public License v2
# Minimal configuration file for rsync daemon
# See rsync(1) and rsyncd.conf(5) man pages for help
# This line is required by the /etc/init.d/rsyncd script

pid file = /var/run/rsync.pid
port = 873
#address = 192.168.1.171
#uid = nobody
#gid = nobody
uid = root
gid = root
use chroot = yes
read only = no

#limit access to private LANs
hosts allow=*
#hosts deny=*
max connections = 5
motd file = /etc/rsyncd/rsync.motd

#This will give you a separate log file
#log file = /var/log/rsync.log
#This will log every file transferred - up to 85,000+ per user, per sync
#transfer logging = yes

log format = %t %a %m %f %b
syslog facility = local3
timeout = 300

[data]
path = /data1
list=yes
ignore errors
auth users = root
secrets file = /etc/rsyncd/rsync.secrets
comment = rsync data1 dir
#exclude = beinan/ samba/

[garbagekrc]
path = /data1/garbagekrc
list=yes
ignore errors
auth users = root
secrets file = /etc/rsyncd/rsync.secrets
comment = rsync garbagekrc dir

用戶密碼文件:

cat /etc/rsyncd/rsync.secrets 
root:test123

其中用戶名必須是服務器上已經存在的用戶
4、啟動rsync服務:/usr/bin/rsync --daemon --config=/etc/rsyncd/rsync.conf

5、備份文件到服務器:

rsync -az --password-file=rsync.password jsoncpp/* root@IP::data/mydata/

其中:password-file可以指定密碼。

6、rsync也可以從服務器上拉文件到本地。結合crontab可以實現定時同步的功能。

7、更多用法請:man rsync。

Copyright © Linux教程網 All Rights Reserved