Mailinglist Archive: opensuse (1194 mails)

< Previous Next >
Re: [opensuse] dd - rsync question
  • From: "Brian K. White" <brian@xxxxxxxxx>
  • Date: Sat, 02 Jan 2010 06:45:11 -0500
  • Message-id: <4B3F31C7.403@xxxxxxxxx>
Bob S wrote:
Hello SuSE people,

I did a dd backup on my 11.2. Question is can I update it with rsync, or more important could I restore certain files/directories using rsync?

Bob S

_what_ did you backup with dd? a filesystem? or a partition or whole drive that might have more than one filesystem?

You can loopback mount a filesystem and update it's contents.

For instance if you did just a filesystem:
If your "/" is/was /dev/sda3 and you dd'd it to an external drive:
dd if=/dev/sda3 of=/media/my_external_drive/sda3.dd

You can update it's contents like this:
mkdir /oldsda3
mount -o loop /media/my_external_drive/sda2.dd /oldsda3
rsync -axv --inplace --del /* /oldsda3
umount /oldsda3

The x in the rsync options means don't include other filesystems.
Thats a quick way to exclude several problems at once such as oldsda3 itself and sys proc dev, but it also means any other seperate filesystems you do want, you need to include with separate rsync commands. Or use a single fancier rsync command using --filter or --exclude or --include etc which you are free to figure out yourself.

If you dd'd a whole drive with multiple partitions and multiple filesystems, that takes extra steps and there are are a couple ways.
Ypu can follow this to see how to find out the offsets of the different filesystems within the dd image and use the offset option to mount.
http://www.andremiller.net/content/mounting-hard-disk-image-including-partitions-using-linux

Or you can use losetup and kpartx. I think this is easier and safer because you don't have to figure out the offsets or risk getting them wrong.
losetup first to make a block device that maps to the file.
# losetup -v -f sda.dd
Loop device is /dev/loop0

Now /dev/loop0 is like /dev/sda
a device node that maps to an entire drive.
Now kpartx to create /dev/mapper/* device nodes which map to the various partitions within the "drive"

# kpartx -av /dev/loop0
add map loop0p1 (253:0): 0 97632 linear /dev/loop0 32
add map loop0p2 (253:1): 0 19584 linear /dev/loop0 97664
add map loop0p3 (253:2): 0 931328 linear /dev/loop0 117248

This created:
/dev/mapper/loop0p1
/dev/mapper/loop0p2
/dev/mapper/loop0p3

/dev/mapper/loop0p3 is the 3rd partition in the image, so if that was your "/" then:
Mount it:
mkdir /oldsda3
mount /dev/mapper/loop0p3 /oldsda3

Update it:
rsync -axv --inplace --del /* /oldsda3

Now unmount and unmap everything:
umount /oldsda3
kpartx -dv /dev/loop0
losetup -d /dev/loop0

--
bkw

--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx

< Previous Next >
References