How to recover deleted Apache Log

Scenario: The server is running Apache and by mistake one of the log files gets deleted. How, we can recover it?

Currently, Apache server is working perfectly:

Login/Switch to as root user:

Move to the httpd in log directory:

cd /var/log/httpd

Delete the log file:

rm -f access_log

So the log file has been deleted,now find the process number for main apache procees that owned by root:

ps aux | grep httpd

In this case, the pid for the main apache process is 1784.

Now lets list the file descriptors:

ls -lsa /proc/1784/fd

Stop the apache service:

service httpd stop

Now copy the access log file that is marked as deleted (In this case it is 7) into the log directory:

cp /proc/1784/fd/7 /var/log/httpd/access_log

Start the apache service again:

service httpd start

Access the webpage again from your server:

Verify the log file:

tail -f /var/log/httpd/access_log

It’s working 🙂

Hope this will help you!

Please Remember me in your prayers!

One response to “How to recover deleted Apache Log

  1. sachin 100 not out January 14, 2016 at 6:34 pm

    Don’t stop the service httpd you will get an error “stat no file found”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: