rsync 遠程備份的功能
rsync常用選項:
-v: 詳細資訊輸出
-z: 傳輸時進行壓縮 --compress-level=NUM可按級別壓縮
-a: 歸檔模式傳輸并保持檔案屬性相當于-rtopgDL
-r : 遞回模式
-t : 保持檔案的時間屬性
-o: 保持檔案屬主屬性
-p: 保持檔案權限屬性
-g: 保持檔案屬組屬性
-D: 保持設備檔案資訊
-l : 保持檔案軟鏈接
-e: 使用指定協議
–include=PATTERN: 指定排除不需要傳輸的檔案
–exclude-from=file: 從檔案中讀取需要排除的內容
-bwlimit=KBPS: 限速限制I / O帶寬; 每秒KBytes
–delete: 洗掉源目錄中不存在的檔案使目標目錄和源目錄一致,慎用
crontab 周期計劃任務
* * * * *
分 時 日 月 周
準備兩臺虛擬機測驗
192.168.27.137 備份源
192.168.27.138 備份端

關掉防火墻 setenforce
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
備份源操作
安裝rsync
[root@localhost ~]# yum -y install rsync
修改組態檔
[root@localhost ~]# vim /etc/rsyncd.conf
uid = nobody
gid = nobody
use chroot = yes
port 873
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
hosts allow = 192.168.27.0/24
[wwwroot]
path = /opt/aaa
comment = Document Root of www.51xit.top
read only =no
dont comperss = *.gz *.bz2 *.tgz *.zip *.rar *.z
auth users =tom
secrets file = /etc/rsyncd_users.db
[root@localhost ~]# mkdir /opt/aaa
設定賬戶 密碼
[root@localhost ~]# vim /etc/rsyncd_users.db
tom:123
加權限
[root@localhost ~]# chmod 600 /etc/rsyncd_users.db
啟動rsync 查看埠
root@localhost ~]# rsync --daemon
[root@localhost ~]# netstat -nlput |grep 873
tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 13360/rsync
tcp6 0 0 :::873 :::* LISTEN 13360/rsync
備份端操作
安裝rsync
[root@localhost ~]# yum -y install rsync
備份端只需設定用戶密碼
[root@localhost ~]# vim /etc/server.pass
123
加權限
[root@localhost ~]# chmod 600 /etc/server.pass
設定定時任務 每分鐘執行一次
[root@localhost ~]# crontab -e
* * * * * rsync -az --password-file=/etc/server.pass tom@192.168.27.137::wwwroot /root/
[root@localhost ~]# crontab -l
* * * * * rsync -az --password-file=/etc/server.pass tom@192.168.27.137::wwwroot /root/
測驗
在備份端的創建個測驗
[root@localhost aaa]# cd /opt/aaa/
[root@localhost aaa]# touch a
在備份源等1分鐘查看 是否同步
[root@localhost ~]# ls
a
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/208014.html
標籤:AI
