In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Let's first introduce the tomcat application file backup script.
#! / bin/bash#Back up the entire tomcat8080-dist to the / backup directorybackuppath=/mnt/tomcat8080-dist/webapps/backpath=/backup/backup-tomcat8080-dist/action=/backup/backup-tomcat8080-dist/APPNAME=distBACKUPNAME1=distBACKUPNAME2=spongod-module-adminBACKUPNAME3=spongod-module-interfacefor i in 1,2 3do echo "" > > / backup/log/backup.logdoneecho "this backup start!" > > / backup/log/backup.log#echo "- STRAT BACKUP TIME: `date'+% Y% m% dmurf% H% M``" > > / backup/log//backup.logif [[- n $backpath]] & & [[- n $backuppath]] Then echo "- STARTUP BACKUP TIME: `date'+% YMMI% MMI% dMue% HMI% M` -" > > / backup/log/backup.log cd / mnt/tomcat8080-dist/ 2 > > / backup/log/backup.log time= `date'+% YMMI% MMI% dMMI% HMI% 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 SUCCESSFUL -" > > / backup/log/backup.log echo "- BACKUP END TIME is: `date'+% Ymuri% mmi% dmi% HMI% 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'+% Ymuri% mmi% dmi% HMI% M``-"> > / backup/log/BackupFailed.log fifi#Delete files from three days awayecho" > > / backup/log/delete-backup.logecho "start deleted file" > > / backup/log/delete -backup.logfind $action-mtime + 3-type f | xargs rm-fif [$?-eq 0] Then echo "- File deleted successfully-" > > / backup/log/delete-backup.logelse echo "- File deletion failed-" > > / backup/log/delete-backup.log echo "> > / backup/log/delete-backup.logfi
Here is an introduction to tomcat's log backup script.
This is a python script. By default, the tomcat log is saved for 15 days, and we can modify it manually.
#! / usr/bin/env python#-*- coding:utf-8-*-import os,datetime,shutil TimelogRootPath = "/ data/webservers" backupRootPath = "/ data/logs/backup/tomcat" delNDayBefore = 15def getYestoday (): now = datetime.datetime.now () delta = datetime.timedelta (days=-1) yestoday = now + delta yestodayStr = yestoday.strftime ('% Y% m% d') return yestodayStrdef 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 = 3600240n # n days ago return currTime-deltTimedef 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 ()
Summary
The above is the sample code of the tomcat application file backup script and log backup script introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to the website!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.