功能介绍

1、一键配置rsync

2、不支持多模块或者多用户

3、-a一切随机

4、不加-a需要手动输入账号密码

5、进度条只是好看,并不代表真的进度


#!/bin/bash
usersuiji=`uuidgen | cut -c 1-10`
passwdsuiji=`uuidgen | cut -c 1-10`
jindutiao () {
COUNTER=0
_R=0     
_C=`tput cols`
_PROCEC=`tput cols`
tput cup $_C $_R
printf "["
while [ $COUNTER -lt 100 ]
do          
    COUNTER=`expr $COUNTER + 1`
    sleep 0.1
    printf "=>"
    _R=`expr $_R + 1`
    _C=`expr $_C + 1`
    tput cup $_PROCEC 101
    printf "]%d%%" $COUNTER
    tput cup $_C $_R
done
printf "\n"
}
if [ "$1" == "-a" ];then
echo "全自动配置中.........."
jindutiao
#第一步配置rsync配置文件
cat >/etc/rsyncd.conf<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
ignore errors
[$usersuiji]
comment = "backup dir by oldboy"
read only = false
list = false
hosts allow = 172.16.1.0/24
hosts deny = 0.0.0.0/32
auth users = $usersuiji
secrets file = /etc/rsync.password
path = $usersuiji
EOF
#第二步,创建一个傀儡用户执行rsync
useradd -s /sbin/nologin -M rsync >>/dev/null
#第三步,创建存储对方传来的数据的目录
cd / && mkdir $usersuiji
#第四步更改文件权限
chown -R rsync.rsync $usersuiji
#第五步创建密码文件及密码
echo $usersuiji:$passwdsuiji >/etc/rsync.password
#第六步修改密码配置文件的权限
chmod 600 /etc/rsync.password
#第七步启动rsync
rsync --daemon
echo "账号为:$usersuiji"
echo "密码为: $passwdsuiji"
echo "备份目录为:/$usersuiji"
echo "模块为:$usersuiji"
elif [ "$1" == ""  ];then
echo  "配置中"
read -p "请设置你的用户:" user
read -p "请设置你的密码:" passwd
read -p "请输入你的模块:" mokuai
cd /
read -p "请输入你的备份目录:" dir
#第一步配置rsync配置文件
cat >/etc/rsyncd.conf<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
ignore errors
[$mokuai]
comment = "backup dir by oldboy"
read only = false
list = false
hosts allow = 172.16.1.0/24
hosts deny = 0.0.0.0/32
auth users = $user
secrets file = /etc/rsync.password
path = $dir
EOF
#第二步,创建一个傀儡用户执行rsync
useradd -s /sbin/nologin -M rsync >>/dev/null
#第三步,创建存储对方传来的数据的目录
cd / && mkdir $dir
#第四步更改文件权限
chown -R rsync.rsync $dir
#第五步创建密码文件及密码
echo $user:$passw >/etc/rsync.password
#第六步修改密码配置文件的权限
chmod 600 /etc/rsync.password
#第七步启动rsync
rsync --daemon
else
echo "规范你的输入"
fi