Find/Cpio Data Between Partitions

Besides the Dump/Restore method mentioned here, I’ve found the commands find and cpio an equally effective combo when used to obtain true clones of data directories.

In the below example, the source partition is mounted at /srcDir, and the destination partition device is /dev/targetPart. We will create two scratch directories at /var/tmp: srcDir, and targetDir; and mount both source and target partitions here.

We will use the mount_nullfs file system as opposed to the traditional loopback file system. From man 8 mount_nullfs:

The mount_nullfs file system differs from a traditional loopback file system in two respects: it is implemented using a stackable layers techniques, and its “null-node�?s stack above all lower-layer vnodes, not just over directory vnodes.

# mkdir /var/tmp/srcDir && mount_nullfs /srcDir /var/tmp/srcDir

# mkdir /var/tmp/targetDir && mount /dev/targetPart /var/tmp/targetDir

# cd /var/tmp/srcDir

# find . | cpio -pdum /var/tmp/targetDir

# cd - && umount /var/tmp/targetDir && umount /var/tmp/srcDir

# rmdir /var/tmp/{srcDir,targetDir}