{"id":1351,"date":"2014-01-16T20:07:08","date_gmt":"2014-01-16T11:07:08","guid":{"rendered":"http:\/\/kazu.tv\/blog\/?p=1351"},"modified":"2014-01-16T03:08:24","modified_gmt":"2014-01-15T18:08:24","slug":"logrotate-copytruncate-file-size","status":"publish","type":"post","link":"https:\/\/kazu.tv\/blog\/2014\/01\/16\/logrotate-copytruncate-file-size\/","title":{"rendered":"logrotate\u3067copytruncate\u3057\u3066\u3082\u30b5\u30a4\u30ba\u304c\u5927\u304d\u3044\u307e\u307e"},"content":{"rendered":"<p>logrotate\u306b\u306f\u8272\u3093\u306a\u30aa\u30d7\u30b7\u30e7\u30f3\u304c\u3042\u308b\u3002\uff08logrotate\u304c\u4f55\u3092\u3059\u308b\u30c4\u30fc\u30eb\u304b\u306f\u30b0\u30b0\u3063\u3066\u4e0b\u3055\u3044\uff09\u3002\u305d\u306e\u3046\u3061\u306e1\u3064\u306b copytruncate \u3068\u3044\u3046\u3082\u306e\u304c\u3042\u308b\u3002\u52d5\u4f5c\u3068\u3057\u3066\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002<\/p>\n<ul>\n<li>\u5bfe\u8c61\u30ed\u30b0\u304ca.log\u3060\u3068\u3059\u308b\u3068\u3001\u305d\u308c\u3092 a.log.0 \u3042\u308b\u3044\u306f a.log-yyyymmdd\u306b\u30b3\u30d4\u30fc<\/li>\n<li>a.log\u3092truncate \uff08\u5185\u90e8\u7684\u306b\u306f cp \/dev\/null \/path\/to\/a.log \u307f\u305f\u3044\u306a\u51e6\u7406\uff09<\/li>\n<\/ul>\n<h2>\u30ed\u30b0\u30fb\u30d5\u30a1\u30a4\u30eb\u306e\u30b5\u30a4\u30ba\u304c\u5927\u304d\u3044\u307e\u307e\u306b\u306a\u308b\u554f\u984c<\/h2>\n<p>\u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u540d\u306f a.log \u3068\u3059\u308b\u3002logrotate \u306e\u8a2d\u5b9a\u3067 copytruncate \u306b\u306a\u3063\u3066\u3044\u308b\u3068\u3059\u308b\u3068\u3001\u30ed\u30fc\u30c6\u30fc\u30c8\u306e\u969b\u306b\u3001\u524d\u8ff0\u306e\u901a\u308a a.log \u304c a.log.0 \u306b\u30b3\u30d4\u30fc\u3055\u308c\u308b\u3002a.log \u304c 100KB\u3060\u3068\u3059\u308b\u3068\u3001a.log.0 \u306f100KB\u3067\u3001\u305d\u306e\u5f8c a.log \u306f truncate \u3055\u308c\u3066 0\u30d0\u30a4\u30c8\u306b\u306a\u308b\u306f\u305a\u3002<\/p>\n<p>\u3060\u304c\u3001\u4ee5\u4e0b\u306e\u69d8\u306a\u73fe\u8c61\u304c\u8d77\u3053\u308b\u5834\u5408\u304c\u3042\u308b\u3002<\/p>\n<ul>\n<li>a.log \u304c a.log-0 \u306b\u30b3\u30d4\u30fc\u3055\u308c\u308b (a.log-0 \u306e\u30b5\u30a4\u30ba\u306f100KB)\u3002<\/li>\n<li>a.log \u304c truncate \u3055\u308c\u308b\u3002<\/li>\n<li>a.log \u306e\u30b5\u30a4\u30ba\u304c 100KB\u306b\u623b\u308b\u3002<\/li>\n<\/ul>\n<p>a.log \u306e\u6700\u521d\u306e100KB\u306fNULL byte\uff08\\0\uff09\u3067\u57cb\u3081\u3089\u308c\u3001\u305d\u306e\u5f8c\u304b\u3089\u30ed\u30b0\u304c\u66f8\u304d\u8fbc\u307e\u308c\u308b\u3002<\/p>\n<p>\u60f3\u50cf\u304c\u3064\u304f\u3068\u601d\u3046\u3051\u3069\u3001\u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u306b\u66f8\u304d\u8fbc\u3080\u30d7\u30ed\u30bb\u30b9\u304c\u4fdd\u6301\u3057\u3066\u3044\u308b\u30d5\u30a1\u30a4\u30eb\u30dd\u30a4\u30f3\u30bf\u30fc\u304c100KB\u306e\u4f4d\u7f6e\u306e\u307e\u307e\u306e\u5834\u5408\u3001a.log \u304c truncate \u3055\u308c\u3066\u30b5\u30a4\u30ba\u304c0\u306b\u306a\u3063\u3066\u3082\u3001\u305d\u306e\u5f8c\u306e\u30ed\u30b0\u66f8\u304d\u8fbc\u307f\u3067100KB\u306e\u4f4d\u7f6e\u306b\u66f8\u304d\u8fbc\u307e\u308c\u3001\u7d50\u679c\u3068\u3057\u3066\u6700\u521d\u306e100KB\u304cNULL\u3067\u57cb\u3081\u3089\u308c\u308b\u3002<\/p>\n<h2>\u539f\u56e0\u3001\u89e3\u6c7a\u65b9\u6cd5<\/h2>\n<p>\u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u304f\u969b\u306b O_APPEND \u30aa\u30d7\u30b7\u30e7\u30f3\u304c\u4ed8\u3044\u3066\u3044\u306a\u3044\u5834\u5408\u306b\u3053\u3046\u3057\u305f\u73fe\u8c61\u304c\u8d77\u3053\u308b\u3002\u30b7\u30a7\u30eb\uff08sh \u3084 bash\uff09\u306e\u5834\u5408\u3001<\/p>\n<pre class=\"brush: bash;\">$ command &gt; a.log<\/pre>\n<p>\u306e\u5834\u5408\u3001O_APPEND \u7121\u3057\u3067\u30d5\u30a1\u30a4\u30eb\u304c\u958b\u304b\u308c\u308b\u306e\u3067\u3001\u4e0a\u306e\u3088\u3046\u306a\u73fe\u8c61\u304c\u767a\u751f\u3059\u308b\u3002\u305d\u308c\u306b\u5bfe\u3057\u3066\u3001\u4ee5\u4e0b\u306e\u5834\u5408\u306b\u306f\u554f\u984c\u304c\u767a\u751f\u3057\u306a\u3044\u3002<\/p>\n<pre class=\"brush: bash;\">$ command &gt;&gt; a.log<\/pre>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u304b\u3089\u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u306b\u30ed\u30b0\u3092\u66f8\u304d\u8fbc\u3080\u969b\u306b &gt; \u3067\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3092\u3057\u3066\u3044\u308b\u5834\u5408\u3001logrotate \u306e copytruncate \u3067\u4e0a\u306e\u3088\u3046\u306a\u554f\u984c\u304c\u767a\u751f\u3059\u308b\u306e\u3067\u3001 &gt;&gt; \u3092\u4f7f\u3046\u3088\u3046\u306b\u3059\u308b\u3068\u826f\u3044\u3002<\/p>\n<p>\u306a\u3093\u3067 &gt; \u3068 &gt;&gt; \u3067\u6319\u52d5\u304c\u9055\u3046\u304b\u306f\u3001\u6b74\u53f2\u7684\u80cc\u666f\u3089\u3057\u3044\u3002<\/p>\n<h2>\u53c2\u8003<\/h2>\n<p>\u30b0\u30b0\u3063\u3066\u898b\u3064\u3051\u305f<a href=\"http:\/\/serverfault.com\/questions\/510469\/null-bytes-in-a-file-created-by-2-rotated-with-logrotate\" target=\"_blank\">\u3053\u306e\u30da\u30fc\u30b8<\/a>\u3068<a href=\"https:\/\/groups.google.com\/forum\/#!topic\/comp.unix.solaris\/Zc7ysjMGprQ\" target=\"_blank\">\u3053\u306e\u30da\u30fc\u30b8<\/a>\u304c\u53c2\u8003\u306b\u306a\u3063\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>logrotate\u306b\u306f\u8272\u3093\u306a\u30aa\u30d7\u30b7\u30e7\u30f3\u304c\u3042\u308b\u3002\uff08logrotate\u304c\u4f55\u3092\u3059\u308b\u30c4\u30fc\u30eb\u304b\u306f\u30b0\u30b0\u3063\u3066\u4e0b\u3055\u3044\uff09\u3002\u305d\u306e\u3046\u3061\u306e1\u3064\u306b copytruncate \u3068\u3044\u3046\u3082\u306e\u304c\u3042\u308b\u3002\u52d5\u4f5c\u3068\u3057\u3066\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002 \u5bfe\u8c61\u30ed\u30b0\u304ca.log\u3060\u3068\u3059\u308b&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[32],"tags":[],"class_list":["post-1351","post","type-post","status-publish","format-standard","hentry","category-linux-unix"],"_links":{"self":[{"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/posts\/1351","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/comments?post=1351"}],"version-history":[{"count":1,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/posts\/1351\/revisions"}],"predecessor-version":[{"id":1352,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/posts\/1351\/revisions\/1352"}],"wp:attachment":[{"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/media?parent=1351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/categories?post=1351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/tags?post=1351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}