歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> rsync日常維護

rsync日常維護

日期:2017/2/27 15:58:53   编辑:Linux教程
rsync是unix/linux下同步文件的一個高效算法,它能同步更新兩處計算機的文件與目錄,並適當利用查找文件中的不同塊以減少數據傳輸。rsync中一項與其他大部分類似程序或協定中所未見的重要特性是鏡像是只對有變更的部分進行傳送。rsync可拷貝/顯示目錄屬性,以及拷貝文件,並可選擇性的壓縮以及遞歸拷貝,同步速度快。

環境
主機
192.168.0.30 any.egolife.com
提供數據庫服務,並部署rman增量備份
使用inotify和rsync實時同步rman備份到備機,為rsync客戶端

備機
192.168.0.29 anybak.egolife.com
部署數據庫,配置與主機相同,但不提供數據庫服務,僅在主機宕機時進行rman異機恢復
部署rsync服務,為rsync服務端

以下是使用rsync的維護記錄。

第一次同步異常
查看某一系統主機和備機,發現2012-8-7的備份未進行同步,查看日志rsync連接異常,並手動進行測試。

rsync服務端輸出日志如下

[root@anybak rmanbak]# tail -f /var/log/rsyncd.log
2012/08/08 09:18:05 [9301] params.c:Parameter() - Ignoring badly formed line in configuration file: ignore errors
2012/08/08 09:18:05 [9301] name lookup failed for 192.168.0.30: Temporary failure in name resolution
2012/08/08 09:18:05 [9301] connect from UNKNOWN (192.168.0.30)
2012/08/08 09:18:05 [9301] rsync to anbak from oracle@unknown (192.168.0.30)
2012/08/08 09:18:05 [9301] rmanbak/
2012/08/08 09:18:28 [9301] inflate (token) returned -5
2012/08/08 09:18:28 [9301] rsync error: error in rsync protocol data stream (code 12) at token.c(478) [receiver=2.6.8]
2012/08/08 09:18:28 [9301] rsync: connection unexpectedly closed (2097 bytes received so far) [generator]
2012/08/08 09:18:28 [9301] rsync error: error in rsync protocol data stream (code 12) at io.c(463) [generator=2.6.8]

1.ignore errors
查看/etc/rsyncd.conf,配置了ignore errors,注釋掉即可;ignore errors 可以忽略掉一些無關的IO錯誤。

2.name lookup failed for 192.168.0.30: Temporary failure in name resolution
rsync 啟用了DNS反向解析,查詢不到時,可能需要花很長時間。
在/etc/hosts文件中,添加192.168.0.30 any.egolife.com 配置重新啟動rynsc服務和客戶端腳本,即可正常同步

第二次同步異常

查看某一系統主機和備機,發現2012-9-25的備份未進行同步。

rsync客戶端日志
inflate (token) returned -5
rsync: connection unexpectedly closed (229751 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(463) [sender=2.6.8]

rsync服務端日志
[root@anybak ~]# tail -f /var/log/rsyncd.log
2012/09/25 16:57:27 [8694] connect from any.egolife.com (192.168.0.30)
2012/09/25 16:57:27 [8694] rsync to anybak from [email protected] (192.168.0.30)
2012/09/25 16:57:27 [8694] rmanbak/
2012/09/25 16:57:50 [8694] inflate (token) returned -5
2012/09/25 16:57:50 [8694] rsync error: error in rsync protocol data stream (code 12) at token.c(478) [receiver=2.6.8]
2012/09/25 16:57:50 [8694] rsync: connection unexpectedly closed (2096 bytes received so far) [generator]
2012/09/25 16:57:50 [8694] rsync error: error in rsync protocol data stream (code 12) at io.c(463) [generator=2.6.8]

還是出現了上次出現過的異常。在網上搜索後,發現可能是rsync 2.6.8的bug,因傳輸的文件太多太大,此時需要升級rsync版本。

查看當前rsync版本
[root@any rmanbak]# rpm -qa | grep rsync
rsync-2.6.8-3.1

[root@any rmanbak]# mount 192.168.1.100:/media/centos/5.7_64/1 /media/
[root@any rmanbak]# rpm -ihv /media/CentOS/rsync-3.0.6-4.el5.x86_64.rpm
warning: /media/CentOS/rsync-3.0.6-4.el5.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID e8562897
Preparing... ########################################### [100%]
1:rsync ########################################### [100%]
升級版本之後,仍有錯誤信息。

rsync客戶端日志
rsync: writefd_unbuffered failed to write 4 bytes to socket [sender]: Connection reset by peer (104)
inflate (token) returned -5
rsync error: error in rsync protocol data stream (code 12) at token.c(604) [receiver=3.0.6]
rsync: connection unexpectedly closed (229747 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(600) [sender=3.0.6]

rsync服務端日志
2012/09/25 17:29:21 [9026] connect from any.egolife.com (192.168.0.30)
2012/09/25 17:29:21 [9026] rsync to anybak from [email protected] (192.168.0.30)
2012/09/25 17:29:21 [9026] receiving file list
2012/09/25 17:29:21 [9026] rmanbak/
2012/09/25 17:29:44 [9026] inflate (token) returned -5
2012/09/25 17:29:44 [9026] rsync error: error in rsync protocol data stream (code 12) at token.c(604) [receiver=3.0.6]
2012/09/25 17:29:44 [9026] rsync: connection unexpectedly closed (2017 bytes received so far) [generator]
2012/09/25 17:29:44 [9026] rsync error: error in rsync protocol data stream (code 12) at io.c(600) [generator=3.0.6]
升級之後,可能還是傳輸的文件太大所導致的。

根據網上搜索到的文檔,在rsync命令中加入參數 --no-iconv,重啟後,客戶端日志信息如下:
sending incremental file list
rmanbak/
rmanbak/20120917_inc0_tfnlf4ok_1_1.bkp
1052737280 22% 47.78MB/s 0:01:13
rsync: writefd_unbuffered failed to write 4 bytes to socket [sender]: Connection reset by peer (104)
inflate (token) returned -5
rsync error: error in rsync protocol data stream (code 12) at token.c(604) [receiver=3.0.6]
rsync: connection unexpectedly closed (229747 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(600) [sender=3.0.6]
根據以上提示,文件20120917_inc0_tfnlf4ok_1_1.bkp太大,導致傳輸異常。

查看該文件大小
[root@any rmanbak]# ll -h 20120917_inc0_tfnlf4ok_1_1.bkp
-rw-r----- 1 oracle oinstall 4.4G Sep 17 22:21 20120917_inc0_tfnlf4ok_1_1.bkp
這裡需要調整rman備份片的大小,限制在500M,實際最大能夠正常傳輸多大的文件尚未明確。
在rman中設置備份集中備份片的大小
[root@any rmanbak]# su - oracle
[root@any rmanbak]# rman target/
RMAN> CONFIGURE CHANNEL DEVICE TYPE DISK MAXPIECESIZE 500M;

new RMAN configuration parameters:
CONFIGURE CHANNEL DEVICE TYPE DISK MAXPIECESIZE 500 M;
new RMAN configuration parameters are successfully stored
不過以上設置對手動分配過channel的備份腳本無效,此時可以在分配通道的腳本中手動指定每個備份片的大小
run{
sql 'alter system archive log current';
allocate channel cha_inc0 type disk maxpiecesize=500M;
backup
incremental level 0
format '/apps/rmanbak/data/%T_inc0_%U.bkp'
tag 'weekly inc0 backup'
database plus archivelog delete input;
release channel cha_inc0;
}
將未同步的文件使用scp命令手動同步到備機,再進行小文件(大不予500M)的同步測試。

另外,因主機和備機停機過(2012-09-24 17:08),而rsync的實時同步備份只有監測的路徑下文件結構發生變更時才會觸發遠程同步,這樣累計起來需要同步的文件太多(2012-9-24 正好周一,rman每周一晚十點都會進行數據庫全備,因此產生的備份文件很多),也可能導致rsync同步失敗。

主機日志
[root@any ~]# uptime
20:37:04 up 1 day, 3:31, 1 user, load average: 0.07, 0.02, 0.11

[root@any ~]# last | more
root pts/1 dev.egolife.com Tue Sep 25 20:36 still logged in
root pts/1 dev.egolife.com Tue Sep 25 12:46 - 20:28 (07:42)
root pts/2 dev.egolife.com Tue Sep 25 09:06 - 20:28 (11:22)
root pts/1 dev.egolife.com Tue Sep 25 08:55 - 10:04 (01:09)
oracle pts/1 :0.0 Tue Sep 25 08:32 - 08:33 (00:00)
oracle :0 Tue Sep 25 08:31 - 08:33 (00:01)
oracle :0 Tue Sep 25 08:31 - 08:31 (00:00)
reboot system boot 2.6.18-194.el5 Mon Sep 24 17:08 (1+03:28)

備機日志
[root@anybak ~]# date
Tue Sep 25 20:30:25 CST 2012
[root@anybak ~]# uptime
20:30:27 up 1 day, 3:32, 1 user, load average: 0.00, 0.00, 0.00
[root@anybak ~]# last | more
root pts/1 dev.egolife.com Tue Sep 25 20:30 still logged in
root pts/2 192.128.1.100 Tue Sep 25 16:58 - 19:58 (03:00)
root pts/1 192.138.1.100 Tue Sep 25 12:37 - 20:21 (07:43)
reboot system boot 2.6.18-194.el5 Mon Sep 24 16:59 (1+03:31)
腳本
rsync.sh
#!/bin/sh
#abstract:
#rsync auto sync script
#2012-06-11 [email protected] first_release
#variables
current_date=$(date +%Y%m%d_%H%M%S)
rman_path=/apps/rmanbak
log_file=/var/log/rsync.log

#rsync
rsync_server=192.168.0.29
rsync_user=oracle
rsync_pwd=/etc/rsync_client.pwd
rsync_module=anybak
#rsync_client password check
if [ ! -e ${rsync_pwd} ]; then
echo "rsync client password file does not exist!"
exit 0
fi

#inotify function
inotify_fun(){
/usr/bin/inotifywait -mrq --timefmt '%d/%m/%y-%H:%M' --format '%T%w%f' \
-e modify,delete,create,move ${rman_path} | while read file
do
/usr/bin/rsync -vrtzopg --progress --delete --password-file=${rsync_pwd} ${rman_path} ${rsync_user}@${rsync_server}::${rsync_module}
done
}

#inotify
inotify_fun >> ${log_file} 2<&1 &
轉自:http://www.dylanninin.com/blog/2012/10/rsync-maintenance-info.html
Copyright © Linux教程網 All Rights Reserved