shell备份与启动

备份backup.sh

#! /bin/bash
JAR_NAME=$1
BACK_PATH=/root/back-project/bootdo/
BACK_DIR=`date +%Y%m%d`
BACK_PATH_DIR=${BACK_PATH}${BACK_DIR}
i=1
if [ ! -d "$BACK_PATH_DIR" ];then
 mkdir ${BACK_PATH_DIR}
else
 while [ -d "${BACK_PATH_DIR}"-"${i}" ]
 do
  i=$(($i+1))
 done
 BACK_PATH_DIR=${BACK_PATH_DIR}"-"${i}
 mkdir ${BACK_PATH_DIR}
fi
echo "创建备份目录完成 ${BACK_PATH_DIR}"
cd target
cp $JAR_NAME $BACK_PATH_DIR
echo ${JAR_NAME}"备份完成"

启动

#! /bin/sh
PORT=8080
JAR_NAME=$1
pid=`netstat -apn | grep $PORT | awk '{print $7}' | cut -d/ -f 1`

if [ -n "$pid" ];then
 echo "$PID号进程尝试终止"
 kill -9 $pid
 echo "$PID端口进程终止成功"
 cd target
 echo "开始启动$PORT端口"
 nohup java -jar $JAR_NAME &
fi


if [ ! -n "$pid" ];then
 cd target
 echo "开始启动$PORT端口"
 nohup java -jar $JAR_NAME &
fi

你可能感兴趣的:(shell备份与启动)