Cloning FFS Partitions with Dump and Restore
Source and Destination
Linux tools tools have been irritating me lately. I've read a number of times that the GNU dump for ext2 is unreliable because of the write-back cache used in the Linux kernel, and as far as I know there is no dump or dump equivalent that works with any of the journaling file systems.
Marc Espie noted in this interview the philosophy of OpenBSD is to "Evolve the OS, not Revolutionize it." The problem with many of the innovations of the GNU world is that historical functionality is often neglected.
Anyway...
# mount /dev/sd0a on / type ffs (local) /dev/sd0d on /var type ffs (local) /dev/sd0g on /usr type ffs (local) /dev/sd0e on /home type ffs (local) kernfs on /kern type kernfs (local)
For this exersize I'm going to mirror everything on a second hard drive. First make sure that you're working with new file systes using newfs on each partition that you want to copy to, then mount the destinations:
# mkdir /mnt/drive2 # mount /dev/sd1a /mnt/drive2 # cd /mnt/drive2 # mkdir var usr home # mount /dev/sd1d var # mount /dev/sd1e home # mount /dev/sd1g usr
Level 0 Dump
Don't forget to mount the destination first! It can be an NFS mount. The -f option writes the output to the file - which is stdout.
cd /mnt/drive2 && dump -0 -f - / | restore -r -f - cd /mnt/drive2/var && dump -0 -f - /var | restore -r -f - cd /mnt/drive2/home && dump -0 -f - /home | restore -r -f - cd /mnt/drive2/usr && dump -0 -f - /usr | restore -r -f -
Because the file system is copied sequentially, without blank space like dd this is probably the fastest way to copy one file system to another.
Remote Backup
Since dump/restore works with pipes, you can use ssh or nc to send a backup to a large drive on a remote system as well:
/sbin/dump -0af - /home | gzip -2 | \
ssh -c blowfish archive@backup.teisprint.net "gzip -dc | dd of=~/am2800--nb0_home"
If you want to run this from cron create a key with a blank password:
$ ssh-keygen -t dsa
And copy it to the remote users's .ssh/authorized_keys file.
References
Cloning entire PCs over the network by Gerrit Renker
Replicating a Linux System - Yet Another Method by Ben Okopnik
Why's and When's of Backup and Restore by Gerhard Mourani