Tuesday, July 21, 2015

Hardlinks - usecase


Hard link points to the same data on the storage device.
--
It has same inode.

You can check using:
ls -li  filename*
--

--
To check number of hardlinks present for a file:
ls -l filename
  Here, check third column count.
--

--
No hard link for directory / special device. only for regular files.

Also, files should be on the same file system(remember inode)

(with soft links, it is possible to create for directories/special files as well)
(with soft links, across file system possible)

• A hard link points a name to data on a (storage)device
• A soft link points a name to another name, that points to data on a (storage) device.

while using softlink for directory, your PWD will be softlink.
--

How hardlinks can be used?

Please refer reference mentioned below for complete details.
 ============================================
This is how many modern file system backup programs work.

On day 1 you make an rsync copy of your entire file system:

backup@backup_server> DAY1=`date +%Y%m%d%H%M%S`
backup@backup_server> rsync -av -e ssh earl@192.168.1.20:/home/earl/ /var/backups/$DAY1/


On day 2 you make a hard link copy of the backup, then a fresh rsync:

backup@backup_server> DAY2=`date +%Y%m%d%H%M%S`
backup@backup_server> cp -al /var/backups/$DAY1 /var/backups/$DAY2
backup@backup_server> rsync -av -e ssh --delete earl@192.168.1.20:/home/earl/ /var/backups/$DAY2/


“cp -al” makes a hard link copy of the entire /home/earl/ directory structure from the previous day, then rsync runs against the copy of the tree.

If a file remains unchanged then rsync does nothing — the file remains a hard link. However, if the file’s contents changed, then rsync will create a new copy of the file in the target directory. If a file was deleted from /home/earl then rsync deletes the hard link from that day’s copy.

In this way, the $DAY1 directory has a snapshot of the /home/earl tree as it existed on day 1, and the $DAY2 directory has a snapshot of the /home/earl tree as it existed on day 2, but only the files that changed take up additional disk space. If you need to find a file as it existed at some point in time you can look at that day’s tree. If you need to restore yesterday’s backup you can rsync the tree from yesterday, but you don’t have to store a copy of all of the data from each day, you only use additional disk space for files that changed or were added.
============================================

Ref:
http://earlruby.org/2013/05/creating-differential-backups-with-hard-links-and-rsync/

No comments:

Post a Comment