Lsof files opened by the recovery process

Source: Internet
Author: User

How it works: Process each open file generates a file handle FD to identify a file, the process open file if not released, you can recover deleted files by file handle FD
Note: The appropriate recovery process has been to open a file, such as a log file, if the profile process is started to read immediately release the handle of the file is not recoverable in this way, and if the open file is deleted, and the service is restarted, the service is restarted this file handle will be released, Through the lsof way is also unable to recover;
Installation: Yum Install Lsof-y

  • To view the process of opening a/var/log/messages file
    Here the process of opening the/var/log/messages file is Rsyslog, the process PID is 925, the main root,4 represents the file fd,w is the write state

    [[email protected] ~]# lsof | grep messagesrsyslogd   925         root    4w      REG              253,0    194666   35851428 /var/log/messagesin:imjour  925  963    root    4w      REG              253,0    194666   35851428 /var/log/messagesrs:main    925  964    root    4w      REG              253,0    194666   35851428 /var/log/messages
  • Delete the file

    rm -rf /var/log/messages
  • Review the process for opening the/var/log/messages file again (deleted)

    [[email protected] ~]# lsof | grep messagesrsyslogd   925         root    4w      REG              253,0    195350   35851428 /var/log/messages (deleted)in:imjour  925  963    root    4w      REG              253,0    195350   35851428 /var/log/messages (deleted)rs:main    925  964    root    4w      REG              253,0    195350   35851428 /var/log/messages (deleted)
  • View process's, file handle

    [[email protected] ~]# ll /proc/925/fd/4 l-wx------ 1 root root 64 May 11 00:37 /proc/925/fd/4 -> /var/log/messages (deleted)
  • Restore based on file handle

    cp /proc/925/fd/4 /var/log/messages

Lsof files opened by the recovery process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.