Dump and Restore over SSH

From Devpit
Jump to: navigation, search

The challenge is to do the equivalent of placing a second drive in a PC and doing a dump | restore style FreeBSD clone, but over SSH. Local access is still required, but no hardware will have to be juggled.

A task like this is the perfect use for a live cd. Freesbie makes a FreeBSD live cd, so that is what I will use.

Back up anything you do not want to lose.

Boot freesbie and log in to the prompt as root (no password by default). Execute the following commands. Anything preceeded by a # is a comment.

# Setup networking
# If you use DHCP, you can skip this step (but note what your IP is for later).
killall dhclient
ifconfig fxp0 inet 10.0.0.99 netmask 255.255.255.0
route add default 10.0.0.1

# By default freesbie mounts all of your UFS slices at /mnt/ufs.#.  Unmount.
umount /mnt/ufs.1

# This step will irreversably erase your disk.
newfs -U /dev/ad0s1a # -U if you want soft updates

# Remount.
mount /dev/ad0s1a /mnt/ufs.1/

# Repeat the previous process for all of your slices.

# Enable root access via SSH.
vim /etc/ssh/sshd_config, PermitRootLogin yes
passwd, set root password
kill -HUP `cat /var/run/sshd.pid`

Ok, now ssh to the box where you want to dump from, and su or sudo to the root user. Attempt to ssh as root to the slave machine to make sure it works. For each slice, run the following command:

dump -0aLf - / | ssh 10.0.0.99 "cd /mnt/ufs.1 && cat | restore -rf -"

At this point, you may want to ssh back to the first machine (10.0.0.99) and edit /mnt/ufs.1/etc/rc.conf to set the correct IP and hostname so that it doesn't clobber anything on reboot. Remove the FreeSBIE disk and reboot, and you now have a perfect clone.