본문 바로가기

리눅스

[리눅스] 리눅스에서 삭제된 파일의 디스크 공간을 복구하는 방법

반응형

리눅스에서 삭제된 파일의 디스크 공간을 복구하는 방법

아파치 에러 로그(error_log 3.2G 사용)

$ df -h | egrep -v 'tmpfs'
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   98G  7.0G   91G   8% /
/dev/sda1               1014M  196M  819M  20% /boot

$ du -sh /var/log/httpd/
4.1G    /var/log/httpd/

$ ls -alh /var/log/httpd/ | grep -v grep | grep error_log
-rw-r--r--  1 root root 3.2G  5월 30 21:47 error_log
-rw-r--r--  1 root root 1.7K  5월 30 21:46 ssl_error_log

아파치 에러 로그 삭제

$ rm -f /var/log/httpd/error_log

$ df -h | egrep -v 'tmpfs'
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   98G  6.1G   92G   7% /
/dev/sda1               1014M  196M  819M  20% /boot

$ du -sh /var/log/httpd/
8.3M    /var/log/httpd/

$ ls -alh /var/log/httpd/ | grep error_log
-rw-r--r--  1 root root 1.7K  5월 30 21:46 ssl_error_log

lsof 삭제된 파일 확인

- lsof -nP +L1

- lsof -nP | grep '(deleted)'

$ lsof -nP +L1
COMMAND  PID   USER   FD   TYPE DEVICE   SIZE/OFF NLINK   NODE NAME
httpd   4060   root    2w   REG  253,0 3355443100     0 837515 /var/log/httpd/error_log (deleted)
httpd   4061 apache    2w   REG  253,0 3355443100     0 837515 /var/log/httpd/error_log (deleted)
httpd   4062 apache    2w   REG  253,0 3355443100     0 837515 /var/log/httpd/error_log (deleted)
httpd   4063 apache    2w   REG  253,0 3355443100     0 837515 /var/log/httpd/error_log (deleted)
httpd   4064 apache    2w   REG  253,0 3355443100     0 837515 /var/log/httpd/error_log (deleted)
httpd   4065 apache    2w   REG  253,0 3355443100     0 837515 /var/log/httpd/error_log (deleted)

(or)
$ lsof -nP | grep '(deleted)'
httpd     4060                root    2w      REG              253,0 3355443100     837515 /var/log/httpd/error_log (deleted)
httpd     4061              apache    2w      REG              253,0 3355443100     837515 /var/log/httpd/error_log (deleted)
httpd     4062              apache    2w      REG              253,0 3355443100     837515 /var/log/httpd/error_log (deleted)
httpd     4063              apache    2w      REG              253,0 3355443100     837515 /var/log/httpd/error_log (deleted)
httpd     4064              apache    2w      REG              253,0 3355443100     837515 /var/log/httpd/error_log (deleted)
httpd     4065              apache    2w      REG              253,0 3355443100     837515 /var/log/httpd/error_log (deleted)

/proc에서 열린 fd(file descriptor)를 찾기

$ file /proc/4060/fd/2      
/proc/4060/fd/2: broken symbolic link to `/var/log/httpd/error_log (deleted)'

$ ls -al /proc/4060/fd/2
l-wx------ 1 root root 64  5월 30 21:46 /proc/4060/fd/2 -> /var/log/httpd/error_log (deleted)

파일 크기 자르기

- truncate -s 0 /proc/{PID}/fd/{FD}

- echo > /proc/{PID}/fd/{FD}

$ truncate -s 0 /proc/4060/fd/2 

(or) $ echo > /proc/4060/fd/2 

파일 시스템 용량 확인

$ df -h | grep -v tmpfs
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   98G  3.0G   95G   4% /
/dev/sda1               1014M  196M  819M  20% /boot

 

 

728x90
반응형