linux 自動化一鍵配置rsync
阿新 • • 發佈:2017-05-07
linux rsync配置 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<<EOF
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<<EOF
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
功能介紹
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`
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<<EOF
uid = rsync
gid = rsync
use chroot = no
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
#第二步,創建一個傀儡用戶執行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<<EOF
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
linux 自動化一鍵配置rsync