远程同步项目并实现重启备份

远程同步脚本

#!/bin/bash
if [ "$1" == "" ];then
    echo "请输入你要进行的操作:{backup start stop restart rsync}"
elif ([ "$1" != "start" ] && [ "$1" != "stop" ] && [ "$1" != "restart" ] && [ "$1" != "backup" ] && [ "$1" != "rsync" ]);then
    echo "请输入你要进行的操作:{backup start stop restart}"
elif([ "$1" == "rsync" ]);then
      /usr/bin/rsync  -avzogP --stats --progress  --include="webapps"  --exclude="/*"  --password-file=/usr/local/rsync/backup.secrets /usr/local/tomcat/ [email protected]::webapps
else
     #echo "/home/www/tomcat_test $1" > /usr/local/tomcat/a
    echo "/home/www/tomcat_m_20021 $1" > /usr/local/tomcat/a
    /usr/bin/rsync   -avzogP --stats --progress  --password-file=/usr/local/rsync/backup.secrets --include='a' --exclude='/*'  /usr/local/tomcat/ [email protected]::rsync
fi

服务端重启备份脚本

#!/bin/sh
#kill tomcat pid
Command_file="/usr/local/tomcat/a"
Project_name=`cat $Command_file |awk '{print $1}'`
Command=`cat $Command_file |awk '{print $2}'`
echo $Command
if  [ -n "$Command" ];then 
case "$Command" in
start)
              export JAVA_HOME=/usr/local/java/jdk1.6.0_23
               cd $Project_name
                rm -rf work/*
                $Project_name/bin/startup.sh
                `/bin/cat /dev/null >$Command_file`
                  echo "启动成功!"
                ;;
        stop)
                pidlist=`ps -ef|grep $Project_name|grep -v "grep" |grep -v "tomcat_restart.sh" |awk '{print $2}'`
                echo "tomcat Id list :$pidlist"
                 kill -9 $pidlist
                 echo "KILL $pidlist:"
                 echo "service stop success" 
                `/bin/cat /dev/null >$Command_file`
                 echo "stop success ! "
       ;;
        restart)
                export JAVA_HOME=/usr/local/java/jdk1.6.0_23
                pidlist=`ps -ef|grep $Project_name|grep -v "grep" |grep -v "tomcat_restart.sh" |awk '{print $2}'`
          echo "tomcat Id list :$pidlist"
                kill -9 $pidlist
                echo "KILL $pidlist:"
                echo "service stop success"
                echo "start tomcat"
             cd $Project_name
               rm -rf work/*
          cd bin
               ./startup.sh 
                `/bin/cat /dev/null >$Command_file`
                echo "重启成功!"
                ;;
        backup) 
             cd $Project_name
             `/bin/find  -type d  -name "webapps_[0-9]*" -mtime +10 | xargs rm -fr`
             my_Back="webapps_backup"
             datetime=`date "+%m-%d-%H-%M"` 
             echo $datetime             
             echo $my_Back
             if [ ! -d "$my_Back" ]; then
                `/bin/mkdir $my_Back`
             fi
            /bin/mv webapps  $my_Back/webapps_$datetime
            `/bin/cat /dev/null >$Command_file`
             echo "备份成功!“
             ;;
        *)
                echo "Usage: $0 {start|stop|restart}"
                cat /dev/null >$Command_file
                exit 1
        esac
        exit 0
fi


你可能感兴趣的:(远程同步项目并实现重启备份)