分享

统信UOS系统losf找回丢失文件

李白 2021-11-9 09:15:31 发表于 已解决 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 0 2748
losf找回丢失文件的两个前提条件:1.知道文件名 2.运行过这个文件
   假如由于误操作将/var/log/messages文件删除掉了,那么这时要将/var/log/messages文件恢复的方法如下:首先使用lsof来查看当前是否有进程打开/var/logmessages文件,如下:

  # lsof |grep /var/log/messages

  COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

  syslogd 14572 root 1w REG 253,0 5584 1737237 /var/log/messages

  #rm –f /var/log/messages

  # lsof |grep /var/log/messages

  COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

  syslogd 14572 root 1w REG 253,0 5584 1737237 /var/log/messages (deleted)

  从上面的信息可以看到 PID 14572(syslogd)打开文件的文件描述符为 1。同时还可以看到/var/log/messages已经标记被删除了。因此我们可以在 /proc/14572/fd/1 (fd下的每个以数字命名的文件表示进程对应的文件描述符)中查看相应的信息,如下:

  # tail -n 10 /proc/14572/fd/1

  Feb 4 20:02:25 host191 kernel: klogd 1.4.1, log source = /proc/kmsg started.

  Feb 4 20:02:45 host191 root: aaa

  Feb 4 20:05:07 host191 dhclient: DHCPREQUEST on eth0 to 192.168.0.254 port 67

  Feb 4 20:05:07 host191 dhclient: DHCPACK from 192.168.0.254

  Feb 4 20:05:07 host191 dhclient: bound to 192.168.0.191 -- renewal in 718 seconds.

  Feb 4 20:15:50 host191 syslogd 1.4.1: restart.

  Feb 4 20:15:50 host191 kernel: klogd 1.4.1, log source = /proc/kmsg started.

  Feb 4 20:17:05 host191 dhclient: DHCPREQUEST on eth0 to 192.168.0.254 port 67

  Feb 4 20:17:05 host191 dhclient: DHCPACK from 192.168.0.254

  Feb 4 20:17:05 host191 dhclient: bound to 192.168.0.191 -- renewal in 804 seconds.# cat /proc/14572/fd/1 》 /var/log/messages

       cat  /proc/14572/fd/1 > /var/log/message

版权说明:论坛帖子主题均由合作第三方提供并上传,若内容存在侵权,请进行举报

没找到任何评论,期待你打破沉寂

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

联系在线客服