手机版
你好,游客 登录 注册
背景:
阅读新闻

使用rsync归档收集Tomcat日志

[日期:2017-08-27] 来源:Linux社区  作者:jim123 [字体: ]

随着业务的不断的增加,使得多台的Tomcat的日志不断剧增,以前有利用bzip2压缩历史数据的脚本压缩过,所以历史日志格式都是统一的,所以打算把部分历史日志数据收集下来,再做具体分析,选选取一台磁盘比较大的服务器用rsync来做日志中心服务器用于收集日志,需要的可以参看:http://www.linuxidc.com/Linux/2017-08/146524.htm 。于是就写了一个脚本在不同的服务器上用于历史日志数据的归档,实现也很简单,如下:

#!/bin/bash
#rsync_logs.sh
#writer jim
#Used for historical log collection
#Need to use rsync you must install rsync
#00 00 01 * * /usr/local/scripts/rsync_logs.sh
#history
#2017.08.26
one_month_ago=$(date -d '-1 month' +%Y-%m)
tomcat_dir="/data/tomcat"
######rsync服务器相关配置变量####
port=873
rsyncd_user="root"
rsyncd_host="172.16.1.170"
DEST_name="backup"
password_file="/etc/.rsync.passwd"
##################################
rpm -qa | grep rsync
if [ $? -ne 0 ];then
    yum -y install rsync
fi
 
for i in $(ls $tomcat_dir)
do
    cd ${tomcat_dir}/${i}/logs
    for n in $(ls *${one_month_ago}*.bz2)
    do
        mv $n "${i}_${n}"
        #由于有多个Tomcat所以需要对历史压缩的日志数据改名
        rsync -vzrLtopg --progress --port=${port} "${i}_${n}" --password-file=${password_file} ${rsyncd_user}@${rsyncd_host}::${DEST_name} && rm -rf "${i}_${n}"
    done
done

CentOS 6.5 rsync+inotify实现数据实时同步备份 http://www.linuxidc.com/Linux/2016-11/137655.htm

rsync+inotify实现数据的实时同步 http://www.linuxidc.com/Linux/2017-01/139778.htm

rsync+inotify实现服务器之间文件实时同步详解  http://www.linuxidc.com/Linux/2016-11/137659.htm

Rsync结合Inotify 实时同步配置  http://www.linuxidc.com/Linux/2017-02/140877.htm

RSync实现数据备份  http://www.linuxidc.com/Linux/2017-06/144913.htm

rsync+inotify实现数据的实时备份  http://www.linuxidc.com/Linux/2016-11/137630.htm

rsync+inotify实现数据自动同步  http://www.linuxidc.com/Linux/2017-03/141717.htm

使用rsync实现数据实时同步备份  http://www.linuxidc.com/Linux/2017-05/143462.htm

Rsync 的详细介绍请点这里
Rsync 的下载地址请点这里

本文永久更新链接地址http://www.linuxidc.com/Linux/2017-08/146525.htm

linux
相关资讯       Tomcat日志  rsync归档 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款