一鍵搭建Rsync服務端

#!/bin/bash
##############################################################
# File Name: Rsync.sh
# Version: V1.0
# Author: Da Kai
# Organization: http://dakaige517.blog.51cto.com
# Created Time : 2017-06-25 13:06:27
# Description:This is a shell script to install the rsync service
##############################################################
. /etc/init.d/functions
function install_check(){
rpm -qa rsync
if [ $? -eq 0 ]
  then 
    action "Rsync is installed" /bin/true
  else
    echo "Rsync is not installed" 
    yum install rsync -y
fi
    
}
function install(){
if [ -f /etc/rsyncd.conf ]
  then
    echo "/etc/rsyncd.conf is exist."
  else
    cat >/etc/rsyncd.conf<<EOF
######rsync_config_______________start
#created by oldboy 15:01 2007-6-25
#QQ 1151887353 blog:http://dakaige517.blog.51cto.com
##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  
[backup]  
path = /backup/ 
ignore errors 
read only = false 
list = false 
hosts allow = 172.16.1.0/24 
#hosts deny = 0.0.0.0/32 
auth users = rsync_backup 
secrets file = /etc/rsync.password  
#rsync_config_______________end
EOF
fi
 awk -F: '{print $1}' /etc/passwd|grep rsync
if [ $? -eq 0 ]
  then 
    echo "rsync is exist"
  else
    useradd rsync -s /sbin/nologin -M
fi
if [ -d /backup ]
  then
    echo "/backup is exist."
  else
    mkdir -p /backup
    chown rsync.rsync /backup
fi
if [ -f /etc/rsync.password ]
  then
    echo "/etc/rsync.password is exist."
  else
    echo "rsync_backup:123456" >/etc/rsync.password
     chmod 600 /etc/rsync.password
fi
rsync --daemon
if [ $? -eq 0 ]
  then
    action "Rsync service is successfully to start." /bin/true
    echo 'rsync --daemon' >>/etc/rc.local
  else
    action "Rsync service is failed to start" /bin/false
fi
 ps -ef|grep "rsync --daemon"
if [ $? -eq 0 ]
  then
    action "Rsync service is running." /bin/true
  else
    action "Rsync service is not running." /bin/false
 fi
   
}
function add_modul(){
        echo -e "Usage:\n[backup]\npath = /backup/"
        echo "-------添加模塊---------"
        read -p "請添加模塊名稱: " name
        read -p "請添加模塊相對應的位置(目錄)path = " directory
mkdir -p $directory
        cat >>/etc/rsyncd.conf<<EOF
$name
path = $directory
EOF
        echo "----- 模塊添加成功---- -"
}
install_check
install
add_modul
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章