dockerlog.shdocker
#!/bin/bash logs=`find /var/lib/docker/containers/ -name *-json.log` d1=`date "+%Y%m%d%H"` d2=`date -d -5hour "+%Y%m%d%H"` path1=/home/logs/elk/$d1/ path2=/home/logs/elk/$d2/ mkdir -p $path1 for docker_log in $logs do cp $docker_log $path1 echo " " > $docker_log done rm -rf $path2 echo 'success'
日誌保存在/home/elk/ 目錄下json
/var/lib/docker/containers/ 是docker下全部容器的日誌目錄bash
crontab -espa
59 * * * * bash /root/scripts/dockerlog.sh