-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup_log.sh
45 lines (35 loc) · 1.02 KB
/
backup_log.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
#jdy logs backup
#Author: [email protected]
set -e
hostname=$(hostname)
prt_path=xxxxxxx
subbix_path=storage/logs
bak_path=/data/bak_log
today=`date +%Y-%m-%d`
for prt_name in -service -core -module
do
log_path=$prt_path/$prt_name/$subbix_path
echo "`date`: backup $prt_name log file begin..."
cd $log_path
# tar log file
find . -name "*.log" | grep -v $today | awk '{printf "tar zcf %s.tgz %s \n", $0,$0}' | bash
# remove origin log file
find . -name "*.log*.tgz" | grep -v $today | awk '{printf "rm -f %s \n",$0}' | sed 's/.tgz//g' | bash
target_path=$bak_path/$hostname/$prt_name
if [ ! -d $target_path ];
then
mkdir -p $target_path
fi
tar_file=$(find . -name "*.tgz" | wc -l)
if [ $tar_file -eq 0 ];
then
echo "$prt_name tgz log file not found"
else
# copy tgz file to target dir
cp *.tgz $target_path
# remove tgz log file
rm -f *.tgz
fi
echo "`date`: backup $prt_name log file end..."
done