Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Ive been working on a script for backups where I run rsync using hard links. In that I want to make sure I dont screw anything up since I have to count on the backups.
I'm using rsync -aP --link-dest=/backup/current $FILES /backup/backup-$date
This means the LAST backup physically has everything and I can loose the previous backups and thats ok RIGHT?
Based on the above I compare backup1 and create backup2 then symbolic link current to backup2 This all works as expected, but here are my questions.
if I have 5 backups and I delete #5 by accident, then I link current to backup #4 will the next backup get the missing files or will I have a false sense of having all the files and have missing data (thinking that 4 is linking to 5 and 5 has physical file)?
Secondly lets say I want to get a copy of a folder which is backed up, if I copy the content will I actually copy the real files or only the hard link references?
Finally while all related, if I have a folder full of HARD links, when the file is missing per say ( erased ) does the hard link also go away?
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197
Rep:
Hard links is the correct way to do rsync incremental backups.
Hard links are totally different from symlinks. They are basically just directory entries pointing to the same inode and can only exist on the same partition. Symlinks provide a path to get to the file/directory that they link to. They can be across partitions and can be broken (the link points to something that no longer exists). Hard links cannot be broken unless there is a serious fault in the file system (assuming by broken you mean losing the file that a link connects to). The file system tracks the number of links to an inode and only eliminates the inode when the last link is eliminated.
If you do an `ls -i` you can see the inodes. If you do an `ls -l` the number of hard links to a file or directory are shown in the second column.
cp typically will make copies of the files that the hard links point to. You should look at `man cp`, or the man page for any other copy or backup utility you use, to see which options relate to links. There are options that control how both symlinks and hard links are treated. You can also use the -i and -l options on ls to see how it has been done.
So, if you delete one of your backups, you will lose those files that were unique to that backup. Say you have backup #4, change file A, take backup #5, change file A again, take backup #6, and then lose backup #5. You will then lose the version of file A that was uniquely on backup #5.
Hard links is the correct way to do rsync incremental backups.
So, if you delete one of your backups, you will lose those files that were unique to that backup. Say you have backup #4, change file A, take backup #5, change file A again, take backup #6, and then lose backup #5. You will then lose the version of file A that was uniquely on backup #5.
Thanks choogendyk,
I understand the above with #4, #5, #6 however my question was lets say you backed up all 3 and the file never changed. According to what we are doing it would then have a hard link to 6 from 4 and to 6 from 5 right? What happens if you loose 6? do the references pointing to 6 disapear, or do they link to nothing, my tests are not making me feel like I understand whats happening.
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197
Rep:
Quote:
Originally Posted by JoeyB
Thanks choogendyk,
I understand the above with #4, #5, #6 however my question was lets say you backed up all 3 and the file never changed. According to what we are doing it would then have a hard link to 6 from 4 and to 6 from 5 right? What happens if you loose 6? do the references pointing to 6 disapear, or do they link to nothing, my tests are not making me feel like I understand whats happening.
Thanks!
If the file never changed, then you have multiple hard links to the same inode. If you lose backup #6, the inode is not removed because there are still hard links to it. You've only lost the hard link on #6 which is part of the record of the state of the system at the point that backup #6 was taken.
But, let's be clear about what you mean by losing backup #6. If you mean it was accidentally deleted, then what I have said above applies. If you mean that you are having hard disk problems and losing data because of that and having to do fsck to get the drive to mount, then all bets are off. Note again that with hard links we're talking about stuff that is on the same partition. So, if you lose the partition, you've lost it all. If you are concerned about that, then you need redundant backups, raid6, whatever.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.