#!/bin/bash # [[ $EUID -ne 0 ]] && echo 'root needed!' && exit 0 rsync_start () { local tag=1 echo "请输入待同步目录所在服务器的IP:" read resync_ip echo "请输入服务端接收数据的目录绝对路径:【可多个目录,多目录之间空格隔开!】" read sync_to [ -z "$sync_to" ] && \ echo '接收数据目录不能为空!' && \ exit 1 [ -d $sync_to ] || mkdir -p $sync_to getent passwd rsync || \ useradd -s /sbin/nologin -M rsync rpm -q rsync &> /dev/null || \ yum install -y -d0 -e0 rsync echo "rsyncs:4ESZ5rdx" > /etc/rsyncd.secret chmod 600 /etc/rsyncd.secret chown -R rsync.rsync $sync_to [ -f /etc/rsyncd.conf ] && \ /bin/cp /etc/rsyncd.conf{,.bak} cat > /etc/rsyncd.conf << EOF uid = rsync gid = rsync port = 873 max connections = 500 use chroot = no timeout = 600 read only = no ignore errors = yes log file = /var/log/rsyncd.log pid file = /var/run/rsyncd.pid lock file = /var/run/rsyncd.lock log format = %t %a %m %f %b auth users = rsyncs secrets file = /etc/rsyncd.secret list = no EOF for i in ${sync_to[@]} do echo -e "[backup$tag]\npath = $i\ncomment = restore sync files" >> /etc/rsyncd.conf let tag++ done unset tag # iptables -vnL | grep -iE "accept|873" | grep -q $resync_ip || \ # iptables -I INPUT -s $resync_ip -p tcp -m state --state NEW --dport 873 -j ACCEPT pgrep rsync &> /dev/null && pkill rsync && sleep 0.5 rsync --daemon --config=/etc/rsyncd.conf } sersync_start() { rpm -q rsync &> /dev/null || \ yum install -y -d0 -e0 rsync echo '请输入数据传送的目的ip地址:' read target_ip [ -z "$target_ip" ] && \ echo '目的地址为空!' && exit 1 echo '请输入要同步的目录绝对路径:' read dir_sync [ -z "$dir_sync" ] && \ echo '目录路径为空!' && exit 1 echo '请输入同步目的服务器的rsync对应模块【默认:backup1】' read -t 30 model_name model_name=${model_name:-backup1} [ -d /usr/local/sersync ] && rm -rf /usr/local/sersync cd /opt && \ wget https://9133w.cn/sources/sersync.tgz && \ tar xf sersync.tgz -C /usr/local/ && \ rm -f sersync.tgz && \ mv /usr/local/{GNU-Linux-x86,sersync} && \ cd /usr/local/sersync && \ mkdir logs conf bin && \ mv sersync2 ./bin && \ mv confxml.xml ./conf && \ echo 'export PATH=$PATH:/usr/local/sersync/bin' >> /etc/profile && \ source /etc/profile echo '4ESZ5rdx' > /etc/rsync.password && \ chmod 600 /etc/rsync.password cat > /usr/local/sersync/conf/confxml.xml << EOF