「Logrotate」の版間の差分

提供: Wikinote
移動: 案内検索
(動作)
(動作)
行10: 行10:
  
 
== 動作 ==
 
== 動作 ==
 +
* create と copytruncate を設定すると、copytruncate が優先される。
  
 
=== compress ===
 
=== compress ===

2011年6月24日 (金) 02:07時点における版

設定

デフォルト

logrotate-3.7.4-8 (CentOS 5.2) の /etc/logrotate.conf の内容は以下。

weekly
rotate 4
create
#compress
include /etc/logrotate.d

動作

  • create と copytruncate を設定すると、copytruncate が優先される。

compress

rotate 4
compress
  1. 古いログから順に rename
  2. log.1 と log.1.gz を open し、gzip 経由で log.1.gz へ write
  3. log.1 を unlink
13534 rename("/tmp/test.log.4.gz", "/tmp/test.log.5.gz") = -1 ENOENT (No such file or directory)
13534 rename("/tmp/test.log.3.gz", "/tmp/test.log.4.gz") = -1 ENOENT (No such file or directory)
13534 rename("/tmp/test.log.2.gz", "/tmp/test.log.3.gz") = -1 ENOENT (No such file or directory)
13534 rename("/tmp/test.log.1.gz", "/tmp/test.log.2.gz") = 0
13534 rename("/tmp/test.log.0.gz", "/tmp/test.log.1.gz") = -1 ENOENT (No such file or directory)
13534 access("/tmp/test.log.5.gz", F_OK) = -1 ENOENT (No such file or directory)
13534 rename("/tmp/test.log", "/tmp/test.log.1") = 0
13534 open("/tmp/test.log.1", O_RDONLY|O_LARGEFILE) = 3
13534 open("/tmp/test.log.1.gz", O_RDWR|O_CREAT|O_TRUNC|O_LARGEFILE, 0100644) = 4
13534 fchmod(4, 0600)                   = 0
13534 fchown32(4, 500, 500)             = 0
13534 fchmod(4, 0100644)                = 0
13534 clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xb7fa7718) = 13535
 ...
13535 execve("/bin/gzip", ["/bin/gzip"], [/* 31 vars */]) = 0
 ...
13535 read(0, "2011\345\271\264  6\346\234\210 24\346\227\245 \351\207\221\346\233\234\346\227\245 00"..., 65536) = 258
13535 read(0, "", 65278)                = 0
13535 write(1, "\37\213\10\0fb\3N\0\0033204|\272s\213\202\202\331\2639\35\nF&\317\246/Ux"..., 82) = 82
 ...
13534 --- SIGCHLD (Child exited) @ 0 (0) ---
13534 unlink("/tmp/test.log.1")         = 0

delaycompress

delaycompress は、compress が設定されている場合のみ有効になる。

rotate 4
compress
delaycompress
  1. まず log.1 と log.1.gz を open し、gzip 経由で log.1.gz へ write
    • この設定だと、log.1.gz は log.2.gz へ rename されているはずなので問題ない
  2. log.1 を unlink
  3. 古いログから順に rename
15991 open("/tmp/test.log.1", O_RDONLY|O_LARGEFILE) = 3
15991 open("/tmp/test.log.1.gz", O_RDWR|O_CREAT|O_TRUNC|O_LARGEFILE, 0100644) = 4
15991 fchmod(4, 0600)                   = 0
15991 fchown32(4, 500, 500)             = 0
15991 fchmod(4, 0100644)                = 0
15991 clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xb7fd8718) = 15992
 ...
15992 execve("/bin/gzip", ["/bin/gzip"], [/* 31 vars */]) = 0
 ...
15992 read(0, "2011\345\271\264  6\346\234\210 24\346\227\245 \351\207\221\346\233\234\346\227\245 01"..., 65536) = 516
15992 read(0, "", 65020)                = 0
15992 write(1, "\37\213\10\0002e\3N\0\0033204|\272s\213\202\202\331\2639\35\nF&\317\246/Ux"..., 106) = 106
15992 exit_group(0)                     = ?
15991 <... wait4 resumed> [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 15992
15991 --- SIGCHLD (Child exited) @ 0 (0) ---
15991 unlink("/tmp/test.log.1")         = 0
15991 rename("/tmp/test.log.4.gz", "/tmp/test.log.5.gz") = -1 ENOENT (No such file or directory)
15991 rename("/tmp/test.log.3.gz", "/tmp/test.log.4.gz") = -1 ENOENT (No such file or directory)
15991 rename("/tmp/test.log.2.gz", "/tmp/test.log.3.gz") = 0
15991 rename("/tmp/test.log.1.gz", "/tmp/test.log.2.gz") = 0
15991 rename("/tmp/test.log.0.gz", "/tmp/test.log.1.gz") = -1 ENOENT (No such file or directory)
15991 access("/tmp/test.log.5.gz", F_OK) = -1 ENOENT (No such file or directory)
15991 rename("/tmp/test.log", "/tmp/test.log.1") = 0

copytruncate

rotate 4
copytruncate
  1. 古いログから順に rename
  2. log と log.1 を open し、log から読んで log.1 へ write
  3. log を ftruncate
rename("/root/stap/test.log.4", "/root/stap/test.log.5") = -1 ENOENT (No such file or directory)
rename("/root/stap/test.log.3", "/root/stap/test.log.4") = -1 ENOENT (No such file or directory)
rename("/root/stap/test.log.2", "/root/stap/test.log.3") = -1 ENOENT (No such file or directory)
rename("/root/stap/test.log.1", "/root/stap/test.log.2") = 0
rename("/root/stap/test.log.0", "/root/stap/test.log.1") = -1 ENOENT (No such file or directory)
access("/root/stap/test.log.5", F_OK)   = -1 ENOENT (No such file or directory)
open("/root/stap/test.log", O_RDWR|O_LARGEFILE) = 3
open("/root/stap/test.log.1", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0100644) = 4
fchmod(4, 0600)                         = 0
fchown32(4, 0, 0)                       = 0
fchmod(4, 0100644)                      = 0
read(3, "1308784634\n1308784635\n1308784636"..., 8192) = 319
write(4, "1308784634\n1308784635\n1308784636"..., 319) = 319
read(3, "", 8192)                       = 0
ftruncate64(3, 0)                       = 0
close(3)                                = 0
close(4)                                = 0

nocopytruncate

rotate 4
nocopytruncate

デフォルトの動作。単に古いログから順に rename するだけ。

rename("/root/stap/test.log.4", "/root/stap/test.log.5") = -1 ENOENT (No such file or directory)
rename("/root/stap/test.log.3", "/root/stap/test.log.4") = -1 ENOENT (No such file or directory)
rename("/root/stap/test.log.2", "/root/stap/test.log.3") = 0
rename("/root/stap/test.log.1", "/root/stap/test.log.2") = 0
rename("/root/stap/test.log.0", "/root/stap/test.log.1") = -1 ENOENT (No such file or directory)
access("/root/stap/test.log.5", F_OK)   = -1 ENOENT (No such file or directory)
rename("/root/stap/test.log", "/root/stap/test.log.1") = 0