로그 삭제를 위해서 find 후 exec로 하는 rm 명령어를 이용하거나 백업을 위해서 cp/rscyn 명령어는 상당히 부하를 일으킨다.

따라서, 기존에는 cpu를 낮추는 리눅스 tool 을 이용하곤 했었다.

 

 

회사의 똑똑한 분을 통해서 알게 된 아주 좋을 툴..  그 이름 trucate

(64비트 운영체제 하에서 로그를 엄청나게 쌓고 삭제하는 경우에 아주 유용함)

 

truncate man 페이지

http://man.cx/truncate

http://www.kernel.org/doc/man-pages/online/pages/man2/ftruncate.2.html

 

옵션 s를 이용하면 싸이즈만큼 삭제가능하다. 따라서 cpu를 많이 사용하지 않게 해 준다.

−s, −−size=SIZE

use this SIZE

 

자세한 내용은 아래 내용을 참조

http://www.depesz.com/2010/04/04/how-to-remove-backups/

 

 

#!/bin/bash
# yes I watch Phineas and Ferb on disney, dont ask.
trunc="/truncatenator/truncate"
file=$1
size=`ls -l $file |awk '{print $5}'`
while [ $size -gt 1000000000 ]; do
size=`echo $size-100000000|bc`;
$trunc -c -s -100000000 $file ;
sleep 0.25;
done
rm -f $file
#end

Posted by '김용환'
,