1、問(wèn)題現(xiàn)象
VI編輯后 Acess、Modify、Change和Birth Time都會(huì)變

image.png
其原因是 vi后,文件的inode會(huì)發(fā)生變化

image.png
這種情況如果發(fā)生在日志文件上,就會(huì)出現(xiàn)新日志不會(huì)記錄到日志文件,而且日志空間還會(huì)繼續(xù)上漲

image.png
2、inode為什么會(huì)變?
缺省情況下,backupcopy=auto,一般是no,也就是會(huì)寫(xiě)一個(gè)新文件
'backupcopy' 'bkc' string (Vi default for Unix: "yes", otherwise: "auto")
global or local to buffer |global-local|
{not in Vi}
When writing a file and a backup is made, this option tells how it's
done. This is a comma separated list of words.
The main values are:
"yes" make a copy of the file and overwrite the original one
"no" rename the file and write a new one
"auto" one of the previous, what works best
Extra values that can be combined with the ones above are:
"breaksymlink" always break symlinks when writing
"breakhardlink" always break hardlinks when writing
3、如何讓inode不變
- 在vi中設(shè)置 :set backupcopy=yes
- 在vimrc (全局或者文件中設(shè)置)
- 給文件創(chuàng)建硬鏈接
4、已經(jīng)vi編輯過(guò)的日志如何找回
- 通過(guò)cp /proc/xxxx/fd/xxxx xxx 找回丟失的日志
- 找回后重啟應(yīng)用,日志會(huì)定位到新的文件