环境:
1 service iptables stop
chkconfig iptables off
2 setenforce=0
/etc/selinux/config
SELINUX=disabled
=====================rsync===========================
1 创建
1 vim /etc/rsyncd.conf
config_______________start
##rsyncd.conf start##
uid = rsync
gid = rsync
use chroot = no
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[oldboy]
path = /oldboy/
ignore errors
read only = false
list = false
hosts allow = 192.168.0.0/24
hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password
#rsync_config_______________end
1.1 dos2unix /etc/rsyncd.conf
2 mkdir -p /oldboy
3 useradd rsync -s /sbin/nologin -M
4 chown -R rsync.rsync /oldboy
5 echo "rsync_backup:oldboy" >> /etc/rsync.password (服务器需要帐号密码)
6 chmod 600 /etc/rsync.password
7 rsync --daemon
8 ps -ef | grep rsync
#lsof -i tcp:873
#netstat -lntup|grep 873
8.1 pkill rsync
客户端
1 echo oldboy > /etc/rsync.password (客户端只需要密码)
2 chmod 600 /etc/rsync.password
扩展
cd /var/www
tar zcvf html_$(date +%F).tar.gz ./html
rsync -zvzP html_2013.9.13.tar.gz [email protected]::oldboy --password-file=/etc/rsync.password
telent 192.168.0.141 873
ctrl+] 推出
===================inotify==============================
1.指定目录
#mkdir /home/oldboy/tools -p
#cd /home/oldboy/tools
客户端
1 # ls -l /proc/sys/fs/inotify/
2 # wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
4 # tar zxf inotify-tools-3.14.tar.gz
5 # cd inotify-tools-3.14
6 [root@NFS-B-client inotify-tools-3.14]#./configure --prefix=/usr/local/inotify-tools-3.14
7 [root@NFS-B-client inotify-tools-3.14]#make && make install
9 mkdir /server/scripts/2014-3-11/ -p
10 cd /server/scripts/2014-3-11
11 vim inotify.sh
#!/bin/bash
host01=192.168.0.145
src=/tmp
dst=oldboy
user=rsync_backup
rsync_passfile=/etc/rsync.password
inotify_home=/usr/local/inotify-tools-3.14
#judge
if [ ! -e "$src" ] \
|| [ ! -e "${rsync_passfile}" ] \
|| [ ! -e "${inotify_home}/bin/inotifywait" ] \
|| [ ! -e "/usr/bin/rsync" ];
then
echo "Check File and Folder"
exit 9
fi
${inotify_home}/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e close_write,delete,create,attrib $src \
| while read file
do
# rsync -avzP --delete --timeout=100 --password-file=${rsync_passfile} $src $user@$host01::$dst >/dev/null 2>&1
cd $src && rsync -aruz -R --delete ./ --timeout=100 $user@$host01::$dst --password-file=${rsync_passfile} >/dev/null 2>&1
done
exit 0
12 # sh inotify.sh &