1058  
查询码:00000027
某文件备份至nginx目录脚本
作者: wyasw 于 2020年03月29日 发布在分类 / Linux / 常用shell脚本 下,并于 2020年03月29日 编辑
shell

某文件备份至nginx目录脚本

1.1 说明:

此脚本本来生活某大佬写的升级某程序的升级脚本,现在被我改为数据备份至 nginx 的脚本。

#! /bin/bash

export PATH=/usr/bin:/bin:/usr/sbin:/sbin

log_file='/var/log/back_bcb_data.log'

echo "===========================" >> $log_file

echo "backup start:  $(date +"%Y-%m-%d %H:%M.%S")" >> $log_file

if $(systemctl -q is-active tmcore.service 2>/dev/null) ; then

  echo "stop tmcore." >> $log_file

  systemctl stop tmcore.service

fi

tendermint_pid=$(ps -futmcore|grep 'tendermint'|awk '$0 !~/grep/ {print $2}'|sed -e 's/\n/ /')

if [ "${tendermint_pid:-}" != "" ]; then

    echo "kill old process. ${tendermint_pid}" >> $log_file

    kill -9 ${tendermint_pid}

fi

if $(systemctl -q is-active bcbchain.service 2>/dev/null) ; then

  echo "stop bcbchain." >> $log_file

  systemctl stop bcbchain.service

fi

if [ -d "/home/tmcore/data" ] ; then

  echo "Start backing up tmcore data." >> $log_file

  cd /home/tmcore/ && tar -zcf tmcore_data_$(date +%Y%m%d).tar.gz data

  rm /home/deploy/nginx/html/down/tmcore_data*.tar.gz -f

  mv /home/tmcore/tmcore_data_$(date +%Y%m%d).tar.gz /home/deploy/nginx/html/down/

  echo "$? (0:no errors)" >> $log_file

 else

  echo "Tmcore directory does not exist." >> $log_file

fi

if [ -d "/home/bcbchain/.appstate.sb" ] ; then

  echo "Start backing up bcbchain data." >> $log_file

  cd /home/bcbchain/ && tar -zcf bcbchain_appstate.db_$(date +%Y%m%d).tar.gz data

  rm /home/deploy/nginx/html/down/bcbchain_appstate.db*.tar.gz -f

  mv /home/tmcore/bcbchain_appstate.db$(date +%Y%m%d).tar.gz /home/deploy/nginx/html/down/

  echo "$? (0:no errors)" >> $log_file

 else

  echo "Bcbchain directory does not exist." >> $log_file

fi

echo "backup stop:  $(date +"%Y-%m-%d %H:%M.%S")" >> $log_file

systemctl start tmcore.service

systemctl start bcbchain.service

echo "Start tmcore and bcbchain."  >> $log_file

#retVal=0

#if [ -d "/home/tmcore/data" ] ; then

#  echo Old data exists, Do you want to remove all?

#  options=("yes" "no")

#  select opt in "${options[@]}" ; do

#  case ${opt} in

#    "yes")

#      echo yes, remove old data

#      rm -rf /home/tmcore /etc/tmcore/config /etc/tmcore/data

#      retVal=0

#      break

#      ;;

#    "no")

#      echo keep old data.

#      retVal=1

#      break

#      ;;

#    *) echo invalid option, reselect;;

#    esac

#  done

#fi

#mkdir -p /etc/tmcore /home/tmcore/{data,log} /usr/local/tmcore/bin

#mkdir -p /etc/systemd/system/tmcore.service.d/

#getent group tmcore  >/dev/null 2>&1 || groupadd -r tmcore

#getent passwd tmcore  >/dev/null 2>&1 || useradd -r -g tmcore \

#    -d /etc/tmcore -s /sbin/nologin -c "BlockChain.net tendermint core System User" tmcore

#cp jq tendermint run.sh rutaller.bash tendermint-forks* /usr/local/tmcore/bin

#cp *.json         /etc/tmcore

#cp tmcore.service /usr/lib/systemd/system

#cp override.conf  /etc/systemd/system/tmcore.service.d

#touch /var/spool/cron/root

#sed -i '/rutaller.bash/d' /var/spool/cron/root

#echo "* * * * * /usr/local/tmcore/bin/rutaller.bash > /dev/null" >> /var/spool/cron/root

#chown -R tmcore:tmcore /etc/tmcore

#chown -R tmcore:tmcore /home/tmcore/data

#chown tmcore:tmcore /home/tmcore/log

#chown tmcore:tmcore /home/tmcore

#chmod 644 /usr/lib/systemd/system/tmcore.service

#chmod 755 /etc/tmcore /usr/local/tmcore /usr/local/tmcore/bin /usr/local/tmcore/bin/*

#systemctl daemon-reload

#echo ""

#echo "Congratulation !!! you got it."

#echo ""

#exit ${retVal}



 推荐知识

 历史版本

修改日期 修改人 备注
2020-03-29 21:10:18[当前版本] wyasw 创建版本

  目录
    文艺知识分享平台 -V 4.9.5 -wcp
    京公网安备100012199188号 京ICP备2021030911号