DDR爱好者之家 Design By 杰米
下面先给大家介绍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 [ $"----\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 [ $"----------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应用文件备份脚本及日志备份脚本的示例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
DDR爱好者之家 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
DDR爱好者之家 Design By 杰米
暂无评论...
更新日志
2024年11月25日
2024年11月25日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]