Strony

wtorek, 20 maja 2008

hardlinks in linux - maybe a way to backup?

take a look:
marti@illusion ~/test_dir $ ls -al
total 8228
drwxr-xr-x 2 marti marti 4096 May 20 13:57 .
drwxr-x--- 15 marti marti 4096 May 20 13:56 ..
-rw-r--r-- 1 marti marti 8397824 May 20 13:58 pliczek


make some hardlinks:
ln pliczek plik1
ln pliczek plik2
ln pliczek plik3

marti@illusion ~/test_dir $ ls -ila
total 32876
5144802 drwxr-xr-x 2 marti marti 4096 May 20 14:01 .
5029890 drwxr-x--- 15 marti marti 4096 May 20 13:56 ..
5144803 -rw-r--r-- 4 marti marti 8397824 May 20 13:58 pliczek
5144803 -rw-r--r-- 4 marti marti 8397824 May 20 13:58 plik1
5144803 -rw-r--r-- 4 marti marti 8397824 May 20 13:58 plik2
5144803 -rw-r--r-- 4 marti marti 8397824 May 20 13:58 plik3
marti@illusion ~/test_dir $ du .
8220 .


it means that - links does not consume disk space, and... after rm of oryginal file:
marti@illusion ~/test_dir $ rm pliczek
marti@illusion ~/test_dir $ ls -ail
total 24660
5144802 drwxr-xr-x 2 marti marti 4096 May 20 15:20 .
5029890 drwxr-x--- 15 marti marti 4096 May 20 13:56 ..
5144803 -rw-r--r-- 3 marti marti 8397824 May 20 13:58 plik1
5144803 -rw-r--r-- 3 marti marti 8397824 May 20 13:58 plik2
5144803 -rw-r--r-- 3 marti marti 8397824 May 20 13:58 plik3


files still exist and they still have same size:
marti@illusion ~/test_dir $ du -s .
8220 .


one strange thing is as expected, "ls" reports 24660 blocks in use, seeing each of the new hard linked files as new data. But... notice what "du" reports, since it actually looks deeper into the file system

way of backup - make hardlink to every file or desired file in another place (note that hardlinks can be done only in one partition), if you wan't to find files which has more then one hardlink just execute:
find / ! -links 1 -type f


OK - note2 (thx to xoff) - you can only be safe in way of deleting the file... not modification, and it is the chipest way of backup - that not occupy additional disk space.

[ad#ad-1]

0 komentarze: