728x90
반응형

개요

로컬에 fluentd에 의해 efs에 적재되는 로그들에 대해 압축하여 s3로 Upload하는 작업이다. (tmi:efs보다 s3가 비용저렴하다)

aws role 관련 문제에 의해 aws mv가 안 먹히는 부분으로 cp로 진행 하였으며, 모든 복사가 끝나면 삭제 되도록 되어 있다. 적재 되는 로그 상위 폴더의 Naming이 불규칙적이기 때문에 순서로 커트 하였다.

#!/bin/bash

s3Path=s3://test-logs.s3.test.com/fluentd/

/usr/bin/find /test/efs/ -name '*.log' -not -name 'buffer.*' -mtime +0 -exec gzip -9 {} +;
/usr/bin/find /test/efs/ -name '*.log.*' -not -name 'buffer.*' -mtime +0 -exec gzip -9 {} +;

uploadList=(`/usr/bin/find /test/efs -name '*.gz' -not -name 'buffer.*' | cut -f4,5 -d '/'`)
uploadFile=(`/usr/bin/find /test/efs -name '*.gz' -not -name 'buffer.*'`)

/usr/bin/touch /usr/share/script/logUpload.log
/usr/bin/chown -R test. /usr/share/script/logUpload.log

for u in "${!uploadFile[@]}"; do
        /usr/bin/sudo -u test /usr/bin/aws s3 cp ${uploadFile[$u]} s3://test-logs.s3.test.com/fluentd/${uploadList[$u]} >> /usr/share/script/logUpload.log
done

catLog=`cat /usr/share/script/logUpload.log | grep 'upload' | wc -l`

if [ ${catLog} -gt 0 ]
then
   /usr/bin/rm -f ${uploadFile[@]}
   /usr/bin/rm -f /usr/share/script/logUpload.log
else
  echo "not found log" >> /usr/share/script/logUpload.log
fi
728x90
300x250

+ Recent posts