LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 06-07-2009, 02:21 PM   #1
JoeyB
LQ Newbie
 
Registered: Aug 2004
Posts: 20

Rep: Reputation: 0
How can I confirm hard links aren't broken


Hello All,

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?

Thanks everyone!
 
Old 06-07-2009, 02:33 PM   #2
GlennsPref
Senior Member
 
Registered: Apr 2004
Location: Brisbane, Australia
Distribution: Devuan
Posts: 3,657
Blog Entries: 33

Rep: Reputation: 283Reputation: 283Reputation: 283
Hi, symlinks might be what you're after to check those links.

Quote:
symlinks --help
symlinks: scan/change symbolic links - v1.2 - by Mark Lord

Usage: symlinks [-crsv] dirlist

Flags: -c == change absolute/messy links to relative
-d == delete dangling links
-r == recurse into subdirs
-s == shorten lengthy links
-v == verbose (show all symlinks)
I have not tried it with hardlinks(?) ln -s (static linking), but generally I use it this way.

symlinks -crsv /(directory)

you might use -d

regards Glenn
 
Old 06-07-2009, 03:15 PM   #3
choogendyk
Senior Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197

Rep: Reputation: 105Reputation: 105
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.
 
Old 06-07-2009, 03:50 PM   #4
JoeyB
LQ Newbie
 
Registered: Aug 2004
Posts: 20

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by choogendyk View Post
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.

Thanks!
 
Old 06-07-2009, 04:05 PM   #5
JoeyB
LQ Newbie
 
Registered: Aug 2004
Posts: 20

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by choogendyk View Post
Hard links is the correct way to do rsync incremental backups.

The file system tracks the number of links to an inode and only eliminates the inode when the last link is eliminated.
Maybe this would have been a better way to ask.. if the inode gets erased do the hard links also get removed?
 
Old 06-08-2009, 07:18 AM   #6
choogendyk
Senior Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197

Rep: Reputation: 105Reputation: 105
Quote:
Originally Posted by JoeyB View Post
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
technical question about hard links v soft links 7stud Linux - Newbie 2 02-23-2007 06:57 PM
links (hard links and soft links..) sachitha Programming 1 08-10-2005 12:10 PM
Broken simbolic links ale_murakami Amigo 2 05-20-2005 06:06 AM
Broken links? danthehat Linux - Newbie 4 02-03-2005 03:06 PM
Konqueror and broken links lachlan Linux - Software 0 07-29-2002 09:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration