Backing up and restoring over a network

I've recently updated some hardware since the existing stuff is starting to act poorly, like not restarting reliably etc. I purchased an eee machine wich doesn't have a DVD player and has a laptop SATA HD (bigger too!) and so on. However, I really just want to migrate the existing server to the new hardware, and not reinstall, and configure. So, that's the background.

I decided I would copy the HD over the network since I have a good connection and the time isn't of essence, and maybe I can leave the old one running while it does this. I considered rsync, but I'm not sure what it would do with 'special' files, and I know that cpio is pretty good about that. After some exploring I found some similar examples but nothing that describes what I needed specifically in a step by step way.

Step 1

download and install an OS... (you probably do not have to install the OS, but that's what I did)

I use fedora an awful lot, and it's done well for me. So, I downloaded a fedora 15 live CD iso. I have a ConnectPro 8GB flash drive. They are small and fast enough for me. Make sure it is has a dos boot partition and a fat32 format to install the live iso on the USB. You can find details about that elsewhere. However, make it a minimal install. Create say 1 root partition (/) that's 10 GB and install the whole thing there. Don't go crazy and do the VM partitions, etc, because the tools don't handle those partitions very well yet, and booting from them isn't particularly easy at times.

Step 2

create a set of partitions that match the other machine. Size isn't important other than the new partitions should be able to hold all the data that the source partitions do. In my case, I have 2 partitions... a root / partition and a /home partition on the original machine.

Step 3

mount the new partition on the new machine. for example

mkdir /mnt/newp
mount /dev/sda3 /mnt/newp
cd /mnt/newp/
exciting!

Step 4

start listening for the data on the new machine...

make sure iptables isn't blocking incoming traffic. In my case, the network is closed, so turning it off is ok.

/etc/init.d/iptables stop

the command is this:

cd /mnt/newp
nc -l 2222 | gunzip | cpio -idum

Step 5

start sending the data from the old machine to the new machine's IP (change 192.168.x.x to your machine's IP)

su -
cd /
find . -xdev -print0 | cpio -o0 | gzip -1 | nc 192.168.x.x 2222

When it is done, both machines disconnect automatically.

repeat for home by going into the partition on your new machine and listening, and doing this on the old machine:

cd /home/
find . -xdev -print0 | cpio -o0 | gzip -1 | nc 192.168.x.x 2222

notes:

  • If your source is ext3, make sure your destination is ext3 - mixing ext3 & 4 is not so good if you are trying to boot with it and your old system doesn't recognize the format for booting.
  • Files over 2-4GB won't transfer using cpio. For those, you will need a different way to copy them.

Step 6

make the new machine bootable on the new partition that's just been copied and loaded.

on the new machine you need to get your grub.conf up to speed and write a new one to the partition table. There is a couple of ways of doing this. Here's one.

  • label your file system: tune2fs -L newp /dev/sda3
  • use that label in the grub.conf to id the filesystem

I added something like this at the bottom:

title newp (2.6.18-92.1.18.el5)
        root (hd0,1)
        kernel /boot/vmlinuz-2.6.18-92.1.18.el5 ro root=LABEL=newp
        initrd /boot/initrd-2.6.18-92.1.18.el5.img

match your hd0,x to be the right device offset and your label should match now too.

update the fstab on the newp partition, you will need to mount the drives in the right place, after all.

fix the grub on the newp partition

  • and run grub-install
mount /dev/sda2 /mnt/newp
cd /mnt/newp
cp /boot/grub/grub.conf boot/grub/

mount -o bind /proc proc
mount -o bind /dev dev
mount -o bind /sys sys

chroot .
cp /proc/mounts /etc/mtab
grub-install --recheck /dev/sda
grub-install /dev/sda

Step 6-A

I also had to create a new initrd for booting with the new system. This isn't always necessary, but for me I had to do this:
/sbin/mkinitrd --without-dmraid -v -f /boot/initrd-2.6.18-92.1.18.el5.img 2.6.18-92.1.18.el5
And since my old OS was 32-bit instead of 64, I downloaded a live CD iso and built the initrd with that version instead of fedora 15 64 bit. Interesting that it worked differently. However, once done, it booted correctly and all is well.

Step 7

reboot and enjoy.

I also booted this first using qemu... which is a handy way to make sure things start up ok before they go live and you can make some corrections (if I missed something above - or doesn't quite match what you are doing)

qemu -hda /dev/sda

Disclaimer: This can cause data destruction. Be very careful, and have backups of your stuff. My target machine is new in my example, and losing data on it wasn't an issue. However, if you get things backwards, it can be bad news.

Add new comment

Filtered HTML

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <span> <img>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.