1. 程式人生 > >Linux下rsync 數據鏡像備份 client / server 模式

Linux下rsync 數據鏡像備份 client / server 模式

根據 ima 在服務器 list sta secret 密碼文件 serve c89

Linux下rsync 數據鏡像備份


rsync特性:

可以鏡像保存整個目錄樹和文件系統
可以增量同步數據,文件傳輸效率高,因而同步時間很短。
可以保持原有文件的權限、時間等屬性。
加密傳輸數據,保證了數據的安全性

兩種模式:

client / server
client / client


安裝rsync

yum install rsync

查看rsync版本

rpm -qa rsync
rsync-3.1.2-4.el7.x86_64

查看rsync安裝位置

rpm -ql rsync

技術分享圖片


在服務器端:
編輯rsync配置文件

vim /etc/rsyncd

內容如下

uid = nobody

gid = nobody
use chroot = no
max connections = 10
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log

[rsync_module_1]
path = /rsync_data_1
comment = rsync_data for sharing to client server
ignore errors
read only = true
list = false
uid = root
gid = root
auth users = rsync_bak
secrets file = /etc/rsync_server.pass

技術分享圖片

按照配置文件內容,創建/etc/rsync_server.pass 文件,且權限為600
內容

rsync_bak:rsyncpwd
chmod 600 /etc/rsync_server.pass

技術分享圖片

根據配置文件創建相應的目錄

mkdir -p /rsync_data_1

啟動rsync服務和驗證

/usr/bin/rsync --daemon
ps -ef | grep rsync
lsof -c rsync
netstat -antlp | grep rsync

技術分享圖片

技術分享圖片


客戶端

確保安裝了rsync組件
創建客戶端rsync的密碼文件,其密碼和服務器端一致,且文件權限為600

vim /etc/rsync_client.pass

cat /etc/rsync_client.pass
rsyncpwd
chmod 600 /etc/rsync_client.pass

客戶端指定/創建rsync的目錄

mkdir -p /rsync_data

從服務器端拉取數據

/usr/bin/rsync -vzrtopg --delete --progress [email protected]::rsync_module_1 /rsync_data --password-file=/etc/rsync_client.pass

驗證是否成功從服務器端拉取到數據

ll /rsync_data/

技術分享圖片


註意:無論客戶端對數據怎麽樣操作,只要進行了數據同步操作,始終保持服務器端的數據

Linux下rsync 數據鏡像備份 client / server 模式