#!/bin/bash
##############################################################
File Name: Rsync.sh
Version: V1.0
Author: Da Kai
#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
#rsyncconfigend
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
原文地址:http://blog.51cto.com/13132636/2063061