-
Notifications
You must be signed in to change notification settings - Fork 0
/
demoshell.sh
100 lines (85 loc) · 1.76 KB
/
demoshell.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env bash
set -e
workspacepath=/media/xp/3bdfbcd7-1703-41ed-87e1-c00c764037a8/workspace
ehrlogpath=$workspacepath/xplorer_logs
ehplogpath=$workspacepath/ehp_data_20190909/ehp_data_v3/ehpv3log
logfile=$ehrlogpath/map_manager.INFO
datetime=0
logbackpath=$1
function init_backup_dir(){
if test ! -z $logbackpath
then
if test -d $logbackpath
then
mv $logbackpath bak_$logbackpath
fi
mkdir $logbackpath -p
cd $logbackpath
logbackpath=`pwd`
else
logbackpath=.
fi
}
function do_ehrlog_backup(){
if test -e $logfile -o -L $logfile
then
logsdir=`stat -L $logfile | grep -i Modify | awk '{print $2 $3}' | cut -d "." -f1 | sed -e 's/-//g' -e 's/://g'`
if test -d $logsdir
then
rm -rf $logsdir
fi
mkdir $logsdir
chmod 777 $logsdir -R
cp $logfile $logsdir
datetime=$logsdir
logbackpath=$logbackpath/$logsdir
fi
}
function do_ehplog_backup(){
if test ! -d $ehplogpath
then
echo "ehpv3log dir doesn't exist!"
exit 1
else
minus=2000000000
path=""
isfind=0
for i in `ls $ehplogpath`
do
logsdir=`stat $ehplogpath/$i | grep -i Modify | awk '{print $2 $3}' | cut -d "." -f1 | sed -e 's/-//g' -e 's/://g'`
if test $logsdir = $datetime
then
isfind=1
cp $ehplogpath/$i $logbackpath -R
break
fi
tempdir=`echo $i | sed -e 's/-//g;s/h//g;s/m//g;s/s//g'`
if test $tempdir = $datetime
then
isfind=1
cp $ehplogpath/$i $logbackpath -R
break
fi
tempminus=$[$logsdir-$datetime]
if test $tempminus -lt 0
then
tempminus=$[0 - $tempminus]
fi
if test $tempminus -lt $minus
then
minus=$tempminus
path=$ehplogpath/$i
fi
done
if test $isfind -ne 1
then
cp $path $logbackpath -R
fi
fi
}
function main(){
init_backup_dir
do_ehrlog_backup
do_ehplog_backup
}
main