docker 的日志定时备份,定时删除

[root@dc-uat-13 ~]# cat rm_logs.sh 
#!/bin/bash
time=`date +%F`

#docker 的所有服务
server=(goreport limited logservice cost baseservice rhscm purchaseuser orderservice reserve1.0 eagles historycaseapi medical appconfig grpcappconfig scm couponservice filestorage pin purchaseadmin vueadmin consult message reserve_test reservation sdt goodsservice payservice doctortool utilityapi logistic)

for name in ${server[*]}
do

#过滤docker 的log日志路径
a=`docker inspect $name | grep '"LogPath":'  | awk '{print $2}'`
b=`echo ${a:1:-2}`
#在删除日之前先备份到其他地方去
mkdir -p /win/dockerlogs/${name}  2>  /dev/null
cp  $b     /win/dockerlogs/${name}/${time}_${name}.log
#删除容器的日志
echo ' ' > $b  &&  echo "删除 $name 日志成功"

#备份日志一个星期
find /win/dockerlogs/${name} cd $path1  && find .  -mtime +7 -type f   -exec rm -rf {} \;
done

你可能感兴趣的:(docker)