티스토리 뷰

출처 , 원문 : http://blog.naver.com/hclee93/100000598878


rm으로 삭제한 파일 복구하기



 

리눅스에서의 파일 삭제는 신중을 기해야 한다. 왜냐면 삭제된 파일은 복구 할 수 없기 때문이다. 이것이 정석이였습니다.  
 
물론 rm 의 소프트링크나 다른 삭제 프로그램으로 대체하는 프로그램들도 있습니다만 rm 자체의 복구는 없다고 알고 있으신 분들이 대부분 일 겁니다.  
 
해답은  
 
debugfs 라는 명령어 입니다. (man page 참조)  
 
실제 사용예를 들어 설명하겠습니다.  
 
가정1) /home/pds/portsentry.tar.gz 라는 파일이 있음.  
가정2) /home 파티션은 hda8 입니다. (df -h 로 확인)  
가정3) rm -f /home/pds/portsentry.tar.gz 명령으로 지웠음.  
가정4) root 로 작업.  
 
복구 절차.  
 
1. #debugfs /dev/hda8  
 
=> 설명 : hda8 파티션에 대해서 검사를 한다.  
 
2. debugfs:  
 
=> 대기상태를 뜻함. 이곳에서 lsdel 을 입력하고 엔터.  
계속...  
 
debugfs: lsdel  
99 deleted inodes found.  
Inode Owner Mode Size Blocks Time deleted  
108123 0 100644 239 1/ 1 Thu Jan 3 01:25:33 2002  
18417 0 100644 426625 420/ 420 Thu Jan 3 01:26:34 2002  
45007 0 100644 343 1/ 1 Thu Jan 3 01:29:59 2002  
28691 0 100400 879 1/ 1 Thu Jan 3 01:38:29 2002  
18394 0 40755 0 1/ 1 Thu Jan 3 01:58:54 2002  
..  
.  
14356 0 100644 2325 3/ 3 Fri Jan 25 16:13:24 2002  
61239 0 100644 43034 44/ 44 Fri Jan 25 16:13:31 2002  
debugfs:  
 
위와 같은 상태로 나오고 다시 대기상태로 됩니다. 실제로는 너무 많이 나오더군요.. (내가 그렇게 많이 지웠었나? '.'a)  
 
이제 이 목록중에서 하나를 선택해서 살려야 합니다. 다행히도 살리고자 하는 파일은 가장 최근에 지운 파일이므로 가장 아래쪽에 있는 것이겠죠.  
 
debugfs: dump <61239> /home/debugfs/portsentry.tar.gz  
 
=> Inode 값을 <> 안에 적어줍니다. 뒤에는 복구할 파일 이름을 적어주시면 됩니다.  
=> 복구할 파일은 다른 디렉토리로 지정해 주시는게 좋습니다. 별 상관은 없지만...  
 
#cd /home/debugfs  
#tar -zxvf portsentry.tar.gz // 정상적으로 압축이 풀리더군요.  
 
=> 아주 훌륭하게 복구가 되었더군요. ^^v  
 
임의로 portsentry.tar.gz 를 지워서 테스트를 한 것입니다.  
 
debugfs: 상태에서 사용할 수 있는 명령어는 help 를 쳐보면 알 수 있습니다.  
끝내는 것은 q, quit 입니다.  
 
 
 
아래는 debugfs: 에서 사용가능한 명령어들 입니다.  
---------------------------------------------------------------------  
 
Available debugfs requests:  
 
show_debugfs_params, params  
Show debugfs parameters  
open_filesys, open Open a filesystem  
close_filesys, close Close the filesystem  
feature, features Set/print superblock features  
dirty_filesys, dirty Mark the filesystem as dirty  
init_filesys Initalize a filesystem (DESTROYS DATA)  
show_super_stats, stats Show superblock statistics  
ncheck Do inode->name translation  
icheck Do block->inode translation  
change_root_directory, chroot  
Change root directory  
change_working_directory, cd  
Change working directory  
list_directory, ls List directory  
show_inode_info, stat Show inode information  
link, ln Create directory link  
unlink Delete a directory link  
mkdir Create a directory  
rmdir Remove a directory  
rm Remove a file (unlink and kill_file, if appropriate)  
kill_file Deallocate an inode and its blocks  
clri Clear an inode's contents  
freei Clear an inode's in-use flag  
seti Set an inode's in-use flag  
testi Test an inode's in-use flag  
freeb Clear a block's in-use flag  
setb Set a block's in-use flag  
testb Test a block's in-use flag  
modify_inode, mi Modify an inode by structure  
find_free_block, ffb Find free block(s)  
find_free_inode, ffi Find free inode(s)  
print_working_directory, pwd  
Print current working directory  
expand_dir, expand Expand directory  
mknod Create a special file  
list_deleted_inodes, lsdel  
List deleted inodes  
write Copy a file from your native filesystem  
dump_inode, dump Dump an inode out to a file  
cat Dump an inode out to stdout  
lcd Change the current directory on your native  
filesystem  
rdump Recursively dump a directory to the native filesystem  
help Display info on command or topic.  
list_requests, lr, ? List available commands.  
quit, q Leave the subsystem  


'웹개발 > Linux' 카테고리의 다른 글

find + xargs + ls 명령어 몇가지 활용  (2) 2014.02.26
FIND 명령어 사용법  (0) 2014.02.26
KeepAlive 란 ?  (0) 2014.01.22
NGINX 란 ?  (0) 2014.01.22
로그 시스템 (System Log ) 연구  (0) 2014.01.13
댓글
D-DAY
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함