#!/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
Rsync 的详细介绍:请点这里
Rsync 的下载地址:请点这里