ZFS How to understand the meaning of ZFS Replication?

Hello everyone,

I still can't understand the purpose of ZFS replication. Although I know how to send and receive snapshot streams, how do I use them later?

For example, if the source host is lost, I am not sure that the target host that receives the snapshot streams can replace the source host to achieve failover. Or restore a new host that is identical to the source host through the target host. Is my understanding wrong?

Here are a few points to clarify, such as:
1. The two hosts have only two partitions, freebsd-boot and freebsd-zfs.
2. Only one pool on freebsd-zfs.
 
Once again a question which can't be directly answered because it heavily depends on your own situation and setup. Some people use send/receive to replicate the entire server so that it can be used as a hot spare of some sort while others merely use it to maintain external backups, which by themselves are also important.

As with most things on Unix environments there really is no "best" solution here, it heavily depends on your needs, your environment and how you want to do things.

For example; I never bother with replicating anything at all. I simply dump a stream to a remote host and store it as an image file (this also reduces the required storage space). Basically a fully automated task: backups are made & send and a cron job on the backup host clears the storage of older files.
However, my external backups are only meant for worst case scenarios where I'd have to rebuild an entire server, for regular backup needs I simply rely on .zfs/snapshots which is available on every ZFS filesystem.

But that also brings us to the most important aspect of systems administration, the classic saying: "What works for me doesn't have to work for you".
 
If the host fail, install FreeBSD again and send the ZFS stream from the backup server to it.

How to do it?

Because a full stream cannot be sent to an existing file system, a new file system has to be created in the existing pool or a new pool has to be created and then receive it. Also, the existing file system should not be renamed and then replaced with the new file system because it is probably being used by the processes. Here is my confused place.

If this is the case, then it will be different from the host before the loss. I want to restore it to a state that is exactly the same as before it was lost, including the file system structure without the extra pool or file system, like this:

Code:
zroot                 /zroot
zroot/ROOT             none
zroot/ROOT/default    /
zroot/tmp             /tmp
zroot/usr              /usr
zroot/usr/home        /usr/home
zroot/usr/ports        /usr/ports
zroot/usr/src          /usr/src
zroot/var              /var
zroot/var/audit        /var/audit
zroot/var/crash        /var/crash
zroot/var/log          /var/log
zroot/var/mail         /var/mail
zroot/var/tmp          /var/tmp

I don't know if my statement is clear enough for my purpose.
 
Because a full stream cannot be sent to an existing file system, a new file system has to be created in the existing pool or a new pool has to be created and then receive it. Also, the existing file system should not be renamed and then replaced with the new file system because it is probably being used by the processes. Here is my confused place.

No. It does, otherwise the advantage of this practice would be very reduced.

What usually give a error is when using zfs send | zfs recv on pools with different names, then you just need to force it. I do not remeber the flag from the top of my head but IIRC the error message tell that.

[EDIT]

You also need to know that almost all system actually is in zroot/ROOT/default ( assuming it is the default layout ). zroot/usr is not even mounted and it is in there for boot environments support. zroot/var/* I think is actualy mounted ( my layout is not default ), and I suppose zroot/usr/home is also mounted ( mine is a separated pool/disk ).

So unless you do care for stuff on /var, you actually just need to stream zroot/ROOT/default ( and eventually another boot environment you have ) and zroot/usr/home.

To get the details about each dataset use zfs get all dataset, but the size used by each dataset usually is a good indicative if it is actually being used or not.
 
Because a full stream cannot be sent to an existing file system, a new file system has to be created in the existing pool or a new pool has to be created and then receive it.
Actually that's not entirely true. You can specify arguments for the receive operation; indicating a filesystem, volume or snapshot which can effectively allow you to receive a full stream and add it as a snapshot beneath an existing filesystem.

You can even do this:
Code:
         -o origin=snapshot
                 Forces the stream to be received as a clone of the given
                 snapshot.  If the stream is a full send stream, this will
                 create the filesystem described by the stream as a clone of
                 the specified snapshot. Which snapshot was specified will not
                 affect the success or failure of the receive, as long as the
                 snapshot does exist.  If the stream is an incremental send
                 stream, all the normal verification will be performed.
 
No. It does, otherwise the advantage of this practice would be very reduced.

What usually give a error is when using zfs send | zfs recv on pools with different names, then you just need to force it. I do not remeber the flag from the top of my head but IIRC the error message tell that.

Can it be done?

Assuming that both hosts have only one zroot pool, can host2 be restored to a copy of host1 through this command with additional parameters?

zfs send -Rv zroot@snap | ssh host2.example.com zfs recv -dvF zroot

The only active pool for zroot pool host 2, I think it will block this operation. Am I misunderstood the purpose of zfs send and zfs receive?
 
sdf

I don't see anything wrong with that command but would be better if you detail what you are willing to accomplish. Another important information is: zfs just send filesystems and not entire pools.

If your layout is not continuous, like the default, using send just with the pool name will not work to replicated the whole thing.

If you are with the default layout, you should do like I pointed in Thread 400279 to replicate what you want.
 
sdf

I don't see anything wrong with that command but would be better if you detail what you are willing to accomplish. Another important information is: zfs just send filesystems and not entire pools.
My goal is to restore the source host or a new server to the state before the source host was corrupted by another host that has received the snapshots when the source host is damaged.

Or use zfs send and zfs recv to turn another host into an exact copy of this host.
 
Back
Top