时间:2021-05-19
下面先给大家介绍tomcat应用文件备份脚本
#!/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%d-%H%M'`" >>/backup/log//backup.logif [[ -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 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下面给大家介绍tomcat的日志备份脚本
这个是python脚本,默认对tomcat日志保存15天,我们自己可以手动修改的
#!/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 = 3600*24*n # n天前 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()总结
以上所述是小编给大家介绍的tomcat应用文件备份脚本及日志备份脚本的示例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
以下脚本主要备份的日志文件为tomcat的catalina.out、localhost_access_log.yyyy-mm-dd.log日志和项目的日志文件,
一、增量备份脚本0级备份脚本:红色部分为自定义的备份文件放置的目录复制代码代码如下:#script.:BackupFull.sh#creater:xyh#dat
目录开门见山示例步骤1、备份语句2、bat脚本3、bat脚本添加导出语句开门见山1、备份的语句能执行2、创建一个检单bat脚本能执行3、把备份的语句放到bat脚
一、写备份并清除老日志Shell脚本:复制代码代码如下:#!/bin/sh#backupeoslog#authorrhao#date2008-12-27#定义环
在脚本中可设置需要备份的数据库表清单,并且会将备份文件通过gzip压缩。需要注意的是,这段脚本仅适用数据一致性要求不高的环境。复制代码代码如下:#!/bin/b