8

When I read man zfs for zfs receive I see

     -F      Force a rollback of the file system to the most recent snap-
             shot before performing the receive operation. If receiving an
             incremental replication stream (for example, one generated by
             "zfs send -R -Fi -iI"), destroy snapshots and file systems
             that do not exist on the sending side.

but I don't quite understand what -F actually will do.

If I zfs receive tank/pool then the received snapshot is rolled back on the destination side file system, which is what I want.

In which situations do I want to use -F?

3 Answers 3

13

The -F switch comes in handy if you have messed with the destination dataset after it has been received. Once you do any changes to it (including doing something as innocent as a directory listing as this would change atimes), it is no longer in the state it was in after the initial transfer. Trying to run a plain zfs receive from an incremental data stream created by the other side's zfs send -i tank/dataset@old tank/dataset@new would result in an error. In this case you have two options on the receiver side:

  • you could either revert to the last snapshot manually using zfs rollback
  • or provide the -F switch to zfs receive to let it handle that for you automatically

Of course, it might be a destructive operation, so you have to understand what it is doing before using it. But if all you are doing is copying snapshots over to a non-live "backup" destination where no other data is written to you might miss, it should be safe.

2
  • 1
    One thing I might add to this answer is the "-F" option I believe has the side effect of removing any snapshots on the target that no longer exist on the source. If you do a rollback, instead of using "-F" option, you can keep the snapshots on the target that no longer exist on the source.
    – Josh
    May 29, 2013 at 16:16
  • @Josh while the documentation seems to suggest so, I have not yet seen this to be the case. At least on Solaris 11, target snapshots are not removed if they do not exist on source when using the -i option to zfs send. I believe the information about other snapshots possibly present on the source is not even part of the stream zfs send -i is producing.
    – the-wabbit
    Jun 26, 2013 at 13:22
2

Others are the experts here on ZFS, I'll simply post this in case you haven't seen it.

Using this option might be necessary when the file system is modified between the time a rollback occurs and the receive is initiated.

From: Solaris - New zfds receive -F option

0

It's seven years later now, but I eventually can add something. Below the accepted answer, there is a discussion about whether or not zfs receive -F removes snapshots which don't exist in the source from the target.

From man zfs (debian buster with ZFS on Linux, vanilla and up-to-date at the time of this writing), in the section about zfs receive:

-F Force a rollback of the file system to the most recent snapshot before performing the receive operation. If receiving an incremental replication stream (for example, one generated by zfs send -R [-i|-I]), destroy snapshots and file systems that do not exist on the sending side.

According to this, if -F has given to zfs receive, snapshots are removed at the target if they are not present in the source if and only if -R has been specified by the sending side. In this case, not only snapshots, but also file systems are removed at the target if they don't exist at the source.

As an additional remark, if the stream received is a full stream (in contrast to an incremental one), a new file system is created at the target. This is equivalent to destroying the file system at the target first it it exists, and to re-create it, which of course also will remove all existing snapshots and descendant file systems.

From the very same passage in man zfs:

Creates a snapshot whose contents are as specified in the stream provided on standard input. If a full stream is received, then a new file system is created as well. Streams are created using the zfs send subcommand, which by default creates a full stream.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .