1、问题现象
VI编辑后 Acess、Modify、Change和Birth Time都会变
其原因是 vi后,文件的inode会发生变化
这种情况如果发生在日志文件上,就会出现新日志不会记录到日志文件,而且日志空间还会继续上涨
2、inode为什么会变?
缺省情况下,backupcopy=auto,一般是no,也就是会写一个新文件
'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中设置 :set backupcopy=yes
- 在vimrc (全局或者文件中设置)
- 给文件创建硬链接
4、已经vi编辑过的日志如何找回
- 通过cp /proc/xxxx/fd/xxxx xxx 找回丢失的日志
- 找回后重启应用,日志会定位到新的文件