一,服务端配置

 #!/bin/sh
#########################################################
#by:kingle #
#use: configuraion rsync #
#version:1.0 #
#########################################################
. /etc/init.d/functions
BackPath=/backup
Passwd=
Name=rsync_backup
IP=10.0.0.0/
Port=`losf |wc -l`
Rev=`tail -l /etc/rc.local`
rsync_conf(){
cat >/etc/rsyncd.conf<<EOF
uid = rsync
gid = rsync
use chroot = no
max connections =
timeout =
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = no
list = no
hosts allow =10.0.0.0/
auth users = rsync_backup
secrets file =/etc/rsync.password
[backup]
path = $BackPath
EOF
if [ -f /etc/rsync.conf ];then
echo "rsync is configuration successing!"
else
echo "please to help!!"
fi
}
rsync_user(){
id rsync &>/dec/null
if [ $? -ne ];then
useradd -s /sbin/nologin -M rsync
else
echo "hava user!!"
fi }
rsync_C_file(){
mkdir $BackPath -p
chown -R rsync.rsync $BackPath
echo "$Name:$Passwd" >/etc/rsync.password
chmod /etc/rsync.password
if [ $Port -eq ]; then
echo "rsync starting"
else
rsync --daemon
fi
if [ $Rev -eq "rsync --daemon" ]; then
echo "rev ok"
else
echo "rsync --daemon" >>/etc/rc.local
fi
}
main (){
rsync_conf
rsync_user
rsync_C_file
}
main

二,客户端配置

 #!/bin/sh
#########################################################
#by:kingle #
#use: configuraion rsync #
#version:1.0 #
######################################################### echo "123456" > /etc/rsync.password
chmod /etc/rsync.password
mkdir /backup -p

三,测试

  在/backup/目录下创建文件

  rsync -avzP /backup/ [email protected]::backup --password-file=/etc/rsync.password

  查看服务端是否存在

  全网备份脚本rsync-LMLPHP

四,全网备份脚本

 #!/bin/sh
#########################################################
#by:kingle #
#use: configuraion rsync #
#version:1.0 #
#########################################################
#!/bin/sh
. /etc/init.d/functions
Backup_Dir=/backup
Passwd=
Passwd_File=/etc/rsync.password
IP=`hostname -I|awk '{print $2}'`
Remote_IP=10.0.0.201
Create_dir(){
[ ! -d ${Backup_Dir}/$IP ] && mkdir -p ${Backup_Dir}/$IP
echo "$Passwd" >$Passwd_File && chmod $Passwd_File
}
Backup_File(){
cd / &&\
tar zchf ${Backup_Dir}/$IP/sysconfig_$(date +%F).tar.gz var/spool/cron/root etc/rc.local server/scripts etc/sysconfig/iptables
}
Push_date(){
find ${Backup_Dir}/$IP/ -type f -name "*.tar.gz"|xargs md5sum >${Backup_Dir}/$IP/zhiwen_$(date +%F).txt
rsync -az ${Backup_Dir}/$IP "rsync_backup"@${Remote_IP}::backup --password-file=${Passwd_File}
if [ $? -eq ];then
action "backup" /bin/true
else
action "backup" /bin/false
fi
find ${Backup_Dir}/$IP -type f -name "*.tar.gz" -mtime +|xargs rm -f
if [ $? -eq ];then
action "rm" /bin/true
else
action "rm" /bin/false
fi
}
main(){
Create_dir
Backup_File
Push_date
}
main

nfs 全网分发,全网执行

05-14 07:46