zfs

ZFS send single snapshot including descendent file systems


Is there a way to send a single snapshot including descendant file systems? 'zfs send' only sends the the top level file system even if the snapshot was created using '-r'. 'zfs send -R' sends the descendant file systems but includes all the previous snapshots, which for disaster recovery purposes consumes unnecessary space if the previous snapshots are not needed in the disaster recovery pool.

cat /sys/module/zfs/version 0.8.3-1ubuntu12.5


Solution

  • I perfectly understand your use case. Although I for one am usually faced with the oppositie situation where I have a remote backup pool from which I want to restore the latest snapshot on a local system.

    In any case, while you cannot achieve what you want in a direct way, you can reach the desired state. The idea is to prune your recovery set so that it only has the latest snapshot. You start by sending an initial snapshot:

    host# zfs snapshot -r tank/data@initial_snapshot
    host# zfs send -R tank/data@initial_snapshot | \
     ssh recovery-host zfs recv tank/data
    

    This will send all descending file systems, and will send the initial_snapshot and all those created before it. If you thus had created any snapshots prior, you can delete them:

    recovery-host# zfs list -H -o name -t snapshot tank/data | head -n -1 \
     | xargs -r -n 1 zfs destroy -r -v
    

    Then you send incremental updates and prune,

    host# zfs snapshot -r tank/data@${LATEST_LOCAL_SNAPSHOT}
    host# zfs send -R -i tank/data@${LATEST_REMOTE_SNAPSHOT} \
     tank/data@${LATEST_LOCAL_SNAPSHOT} | ssh recovery-host zfs recv tank/data
    recovery-host# zfs list -H -o name -t snapshot tank/data | head -n -1 \
     | xargs -r -n 1 zfs destroy -r -v
    

    assuming that LATEST_LOCAL_SNAPSHOT and LATEST_REMOTE_SNAPSHOT are appropriately set.

    Please mind that this is a minimal seatbelt-less example. You should care about whether your send-receives are successful. If accidently reach the state where your recovery pool does not have any snapshots that match your source, you can no longer send increments and will thus need to start anew.