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}

Dump/Restore Data Between Partitions

Here’s a script I created to backup and restore data between partitions on OpenBSD:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/sh
newfs /dev/ad1s1a
newfs /dev/ad1s1e
newfs /dev/ad1s1f
mount /dev/ad1s1a /backup/root
mount /dev/ad1s1e /backup/var
mount /dev/ad1s1f /backup/usr
( dump -0f - / ) | ( cd /backup/root ; restore -rf - )
( dump -0f - /var ) | ( cd /backup/var ; restore -rf - )
( dump -0f - /usr ) | ( cd /backup/usr ; restore -rf - )
umount /backup/root
umount /backup/var
umount /backup/usr
tunefs -n enable /dev/ad1s1a
tunefs -n enable /dev/ad1s1e
tunefs -n enable /dev/ad1s1f