91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》
  • 首頁 > 
  • 教程 > 
  • 服務器 > 
  • tomcat應用文件備份腳本及日志備份腳本的示例代碼

tomcat應用文件備份腳本及日志備份腳本的示例代碼

發布時間:2020-09-29 06:01:30 來源:腳本之家 閱讀:297 作者:熊抱 欄目:服務器

下面先給大家介紹tomcat應用文件備份腳本

#!/bin/bash
#Back up the entire tomcat8080-dist to the /backup directory
backuppath=/mnt/tomcat8080-dist/webapps/
backpath=/backup/backup-tomcat8080-dist/
action=/backup/backup-tomcat8080-dist/
APPNAME=dist
BACKUPNAME1=dist
BACKUPNAME2=spongod-module-admin
BACKUPNAME3=spongod-module-interface
for i in 1,2,3
do
    echo "" >>/backup/log/backup.log
done
echo "this backup start!" >>/backup/log/backup.log
#echo "----STRAT BACKUP TIME:`date '+%Y%m%d-%H%M'`" >>/backup/log//backup.log
if [[ -n $backpath ]] && [[ -n $backuppath ]];then
    echo "--------STARTUP BACKUP TIME:`date '+%Y-%m-%d-%H-%M'`-------" >>/backup/log/backup.log
    cd /mnt/tomcat8080-dist/ 2>> /backup/log/backup.log
    time=`date '+%Y-%m-%d-%H-%M'`
    tar czf /backup/backup-tomcat8080-dist/$APPNAME-$time\.tar.gz webapps/$BACKUPNAME1/ webapps/$BACKUPNAME2/ webapps/$BACKUPNAME3/ 2>>/backup/log/BackupFailed.log
    if [ $? -eq 0 ];then
        echo -e "----\033[32m BACKUP SUCCESSFUL\033[0m-----------------------" >>/backup/log/backup.log
        echo "--------BACKUP END TIME is:`date '+%Y-%m-%d-%H-%M'`--------" >>/backup/log/backup.log
        echo "This backup ends" >>/backup/log/backup.log
        for i in 1,2,3
        do
            echo "" >>/backup/log/backup.log
        done
    else
        echo -e "----\033[31m Backup failed, please try again \033[0m -------------" >>/backup/log/BackupFailed.log
        echo "--------Failed Time:`date '+%Y-%m-%d-%H-%M'`-----------" >>/backup/log/BackupFailed.log
    fi
fi
#Delete files from three days away
echo "" >>/backup/log/delete-backup.log
echo "start deleted file" >>/backup/log/delete-backup.log
find $action -mtime +3 -type f |xargs rm -f
if [ $? -eq 0 ];then
    echo "----------File deleted successfully--------------" >>/backup/log/delete-backup.log
else
    echo "----------File deletion failed-------------------" >>/backup/log/delete-backup.log
    echo "" >>/backup/log/delete-backup.log
fi

下面給大家介紹tomcat的日志備份腳本

這個是python腳本,默認對tomcat日志保存15天,我們自己可以手動修改的

#!/usr/bin/env python
#-*- coding:utf-8 -*-
import os,datetime,shutil,time
logRootPath = "/data/webservers"
backupRootPath = "/data/logs/backup/tomcat"
delNDayBefore = 15
def getYestoday():
  now = datetime.datetime.now()
  delta = datetime.timedelta(days=-1)
  yestoday = now + delta
  yestodayStr = yestoday.strftime('%Y%m%d')
  return yestodayStr
def createDir(path):
  if not os.path.exists(path):
    os.makedirs(path)
def backupLog():
  for path in os.listdir(logRootPath):
    logPath = os.path.join(os.path.join(logRootPath, path), "logs")
    backupPath = os.path.join(backupRootPath, path)
    logFilePath = os.path.join(logPath, "catalina.out")
    targetFileName = "catalina.out." + getYestoday()
    targetFilePath = os.path.join(backupPath, targetFileName)
    createDir(backupPath)
    shutil.copy(logFilePath,targetFilePath)
    os.system("echo '' > %s" % (logFilePath))
def getNDayTime(n):
  currTime = time.time()
  deltTime = 3600*24*n # n天前
  return currTime - deltTime
def delLog():
  fileInfos = os.walk(backupRootPath)
  beforeTime = getNDayTime(delNDayBefore)
  for path,d,filelist in fileInfos:
    for filename in filelist:
      filePath = os.path.join(path, filename)
      modifyTime = os.stat(filePath).st_mtime
      print(filePath,":",modifyTime,"-",beforeTime,"-",modifyTime < beforeTime)
      if modifyTime < beforeTime:
        print("remove file %s" % (filePath))
        os.remove(filePath)
def do():
  backupLog()
  delLog()
if __name__ == "__main__":
  do()

總結

以上所述是小編給大家介紹的tomcat應用文件備份腳本及日志備份腳本的示例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對億速云網站的支持!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

河西区| 乌鲁木齐市| 吐鲁番市| 儋州市| 隆德县| 紫阳县| 聂荣县| 大悟县| 五台县| 彭山县| 哈尔滨市| 湟中县| 蒙阴县| 正宁县| 铁岭县| 凤山县| 新和县| 塘沽区| 岢岚县| 砀山县| 宁国市| 曲阜市| 大荔县| 垫江县| 商丘市| 宁化县| 客服| 惠州市| 临泉县| 精河县| 丹江口市| 沈阳市| 镇康县| 扬中市| 鹤庆县| 汪清县| 花莲县| 瓦房店市| 田东县| 高平市| 赣榆县|