Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to make a bare-bone backup system with the most basic tools available on openSUSE 11.3 (in this case: bash, fdisk, tar & grub legacy)

Here's the workflow for my scripts:

backup.sh:

  1. (Run from external system, e.g. LiveCD)
  2. make an fdisk script ($fscript) from fdisk -l's output [works]
  3. mount the partitions from the system's fstab [works]
  4. tar the crucial stuff in file.tgz [works]

restore.sh:

  1. (Run from external system, e.g. LiveCD)
  2. run fdisk $dest < $fscript to restore partitioning [works]
  3. format and mount partitions from system's fstab [fails]
  4. extract from file.tgz [works when mounting manually]
  5. restore grub [fails]

I have recently noticed that openSUSE (though I'm sure it has nothing to do with the distro) has different output in /etc/fstab and /boot/grub/menu.lst, more precisely the partition name is for example "/dev/disk/by-id/numbers-brandname-morenumbers-part2" instead of "/dev/sda2" -- but it basically is a simple symlink.

My questions about this:

  • what is the point of such symlinks, especially if we're restoring on a different disk?
  • is there a way to cleanly prevent the creation of those symlinks and use the "true" /dev/sdx everywhere instead?
  • if the previous is no, do you know a way to replace those symlinks on the fly in a text file? I tried this script but only works if the file starts with the symlink description (case of fstab, not menu.lst):

    ### search and replace /dev/disk/by-id/... to /dev/sdx
    while read oldVolume rest; do # get first element, ignore rest of line
        if [[ "$oldVolume" =~ ^/dev/disk/by-id/.*(-part[0-9]*$)? ]]; then
            newVolume=$(readlink $oldVolume) # replace pointer by pointee, returns "../../sdx"
            echo /dev/${newVolume##*/} $rest >> TMP # format to "/dev/sdx", write line
        else
            echo $oldVolume $rest >> TMP # nothing to do
        fi
    done < $file
    mv -f TMP $file # save changes
    

I've had trouble finding a solution to this on google so I was hoping some of the members here could help me.

Thank you.

share|improve this question
add comment

1 Answer

The symlinks exists so you can reference the devices by a unique name (combination of manufacturer, model and serial number). This is especially useful if your disks change device names if you boot up with a flash drive installed.

I have often used these symlinks to solve problems with ZFS and disks that move device nodes (specially USB disks).

Using the symlinks it doesn't matter in what order disks are detected or connected.

You shouldn't be backing up /dev anyway - there's nothing in there that is useful for a backup.

share|improve this answer
1  
Use the --exclude or --exclude-from options of the tar command to list exclusions.OR use the -xdev option of find to avoid crossing file system boundaries. –  Chris Nava Mar 2 '11 at 16:49
    
I understand that /dev is not required to backup, and I am familiar with the --exclude argument. My true problem is that the symlinks in fstab and menu.lst aren't usable when I restore to a blank disk, because the symlinks do not exist at that moment (we're on a LiveCD during restoring). So simply reading the original fstab will fail the mounts I'm trying to do. I could mount every partition manually but I would like to automate this by using /dev/sdx. The same problem goes for grub which also has by-id symlinks written in it. –  SK. Mar 2 '11 at 17:02
    
Just don't restore the tar file over the existing filesystem. Extract to a temporary location and then move the things you want to keep back to their correct location. –  Chris Nava Mar 14 '11 at 4:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.