xref: /freebsd/sys/contrib/openzfs/man/man8/zfs-receive.8 (revision af23369a6deaaeb612ab266eb88b8bb8d560c322)
1.\"
2.\" CDDL HEADER START
3.\"
4.\" The contents of this file are subject to the terms of the
5.\" Common Development and Distribution License (the "License").
6.\" You may not use this file except in compliance with the License.
7.\"
8.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9.\" or https://opensource.org/licenses/CDDL-1.0.
10.\" See the License for the specific language governing permissions
11.\" and limitations under the License.
12.\"
13.\" When distributing Covered Code, include this CDDL HEADER in each
14.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15.\" If applicable, add the following below this CDDL HEADER, with the
16.\" fields enclosed by brackets "[]" replaced with your own identifying
17.\" information: Portions Copyright [yyyy] [name of copyright owner]
18.\"
19.\" CDDL HEADER END
20.\"
21.\" Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved.
22.\" Copyright 2011 Joshua M. Clulow <josh@sysmgr.org>
23.\" Copyright (c) 2011, 2019 by Delphix. All rights reserved.
24.\" Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
25.\" Copyright (c) 2014, Joyent, Inc. All rights reserved.
26.\" Copyright (c) 2014 by Adam Stevko. All rights reserved.
27.\" Copyright (c) 2014 Integros [integros.com]
28.\" Copyright 2019 Richard Laager. All rights reserved.
29.\" Copyright 2018 Nexenta Systems, Inc.
30.\" Copyright 2019 Joyent, Inc.
31.\"
32.Dd April 26, 2022
33.Dt ZFS-RECEIVE 8
34.Os
35.
36.Sh NAME
37.Nm zfs-receive
38.Nd create snapshot from backup stream
39.Sh SYNOPSIS
40.Nm zfs
41.Cm receive
42.Op Fl FhMnsuv
43.Op Fl o Sy origin Ns = Ns Ar snapshot
44.Op Fl o Ar property Ns = Ns Ar value
45.Op Fl x Ar property
46.Ar filesystem Ns | Ns Ar volume Ns | Ns Ar snapshot
47.Nm zfs
48.Cm receive
49.Op Fl FhMnsuv
50.Op Fl d Ns | Ns Fl e
51.Op Fl o Sy origin Ns = Ns Ar snapshot
52.Op Fl o Ar property Ns = Ns Ar value
53.Op Fl x Ar property
54.Ar filesystem
55.Nm zfs
56.Cm receive
57.Fl A
58.Ar filesystem Ns | Ns Ar volume
59.
60.Nm
61.Cm receive
62.Fl c
63.Op Fl vn
64.Ar filesystem Ns | Ns Ar snapshot
65.
66.Sh DESCRIPTION
67.Bl -tag -width ""
68.It Xo
69.Nm zfs
70.Cm receive
71.Op Fl FhMnsuv
72.Op Fl o Sy origin Ns = Ns Ar snapshot
73.Op Fl o Ar property Ns = Ns Ar value
74.Op Fl x Ar property
75.Ar filesystem Ns | Ns Ar volume Ns | Ns Ar snapshot
76.Xc
77.It Xo
78.Nm zfs
79.Cm receive
80.Op Fl FhMnsuv
81.Op Fl d Ns | Ns Fl e
82.Op Fl o Sy origin Ns = Ns Ar snapshot
83.Op Fl o Ar property Ns = Ns Ar value
84.Op Fl x Ar property
85.Ar filesystem
86.Xc
87Creates a snapshot whose contents are as specified in the stream provided on
88standard input.
89If a full stream is received, then a new file system is created as well.
90Streams are created using the
91.Nm zfs Cm send
92subcommand, which by default creates a full stream.
93.Nm zfs Cm recv
94can be used as an alias for
95.Nm zfs Cm receive .
96.Pp
97If an incremental stream is received, then the destination file system must
98already exist, and its most recent snapshot must match the incremental stream's
99source.
100For
101.Sy zvols ,
102the destination device link is destroyed and recreated, which means the
103.Sy zvol
104cannot be accessed during the
105.Cm receive
106operation.
107.Pp
108When a snapshot replication package stream that is generated by using the
109.Nm zfs Cm send Fl R
110command is received, any snapshots that do not exist on the sending location are
111destroyed by using the
112.Nm zfs Cm destroy Fl d
113command.
114.Pp
115The ability to send and receive deduplicated send streams has been removed.
116However, a deduplicated send stream created with older software can be converted
117to a regular (non-deduplicated) stream by using the
118.Nm zstream Cm redup
119command.
120.Pp
121If
122.Fl o Em property Ns = Ns Ar value
123or
124.Fl x Em property
125is specified, it applies to the effective value of the property throughout
126the entire subtree of replicated datasets.
127Effective property values will be set
128.Pq Fl o
129or inherited
130.Pq Fl x
131on the topmost in the replicated subtree.
132In descendant datasets, if the
133property is set by the send stream, it will be overridden by forcing the
134property to be inherited from the top‐most file system.
135Received properties are retained in spite of being overridden
136and may be restored with
137.Nm zfs Cm inherit Fl S .
138Specifying
139.Fl o Sy origin Ns = Ns Em snapshot
140is a special case because, even if
141.Sy origin
142is a read-only property and cannot be set, it's allowed to receive the send
143stream as a clone of the given snapshot.
144.Pp
145Raw encrypted send streams (created with
146.Nm zfs Cm send Fl w )
147may only be received as is, and cannot be re-encrypted, decrypted, or
148recompressed by the receive process.
149Unencrypted streams can be received as
150encrypted datasets, either through inheritance or by specifying encryption
151parameters with the
152.Fl o
153options.
154Note that the
155.Sy keylocation
156property cannot be overridden to
157.Sy prompt
158during a receive.
159This is because the receive process itself is already using
160the standard input for the send stream.
161Instead, the property can be overridden after the receive completes.
162.Pp
163The added security provided by raw sends adds some restrictions to the send
164and receive process.
165ZFS will not allow a mix of raw receives and non-raw receives.
166Specifically, any raw incremental receives that are attempted after
167a non-raw receive will fail.
168Non-raw receives do not have this restriction and,
169therefore, are always possible.
170Because of this, it is best practice to always
171use either raw sends for their security benefits or non-raw sends for their
172flexibility when working with encrypted datasets, but not a combination.
173.Pp
174The reason for this restriction stems from the inherent restrictions of the
175AEAD ciphers that ZFS uses to encrypt data.
176When using ZFS native encryption,
177each block of data is encrypted against a randomly generated number known as
178the "initialization vector" (IV), which is stored in the filesystem metadata.
179This number is required by the encryption algorithms whenever the data is to
180be decrypted.
181Together, all of the IVs provided for all of the blocks in a
182given snapshot are collectively called an "IV set".
183When ZFS performs a raw send, the IV set is transferred from the source
184to the destination in the send stream.
185When ZFS performs a non-raw send, the data is decrypted by the source
186system and re-encrypted by the destination system, creating a snapshot with
187effectively the same data, but a different IV set.
188In order for decryption to work after a raw send, ZFS must ensure that
189the IV set used on both the source and destination side match.
190When an incremental raw receive is performed on
191top of an existing snapshot, ZFS will check to confirm that the "from"
192snapshot on both the source and destination were using the same IV set,
193ensuring the new IV set is consistent.
194.Pp
195The name of the snapshot
196.Pq and file system, if a full stream is received
197that this subcommand creates depends on the argument type and the use of the
198.Fl d
199or
200.Fl e
201options.
202.Pp
203If the argument is a snapshot name, the specified
204.Ar snapshot
205is created.
206If the argument is a file system or volume name, a snapshot with the same name
207as the sent snapshot is created within the specified
208.Ar filesystem
209or
210.Ar volume .
211If neither of the
212.Fl d
213or
214.Fl e
215options are specified, the provided target snapshot name is used exactly as
216provided.
217.Pp
218The
219.Fl d
220and
221.Fl e
222options cause the file system name of the target snapshot to be determined by
223appending a portion of the sent snapshot's name to the specified target
224.Ar filesystem .
225If the
226.Fl d
227option is specified, all but the first element of the sent snapshot's file
228system path
229.Pq usually the pool name
230is used and any required intermediate file systems within the specified one are
231created.
232If the
233.Fl e
234option is specified, then only the last element of the sent snapshot's file
235system name
236.Pq i.e. the name of the source file system itself
237is used as the target file system name.
238.Bl -tag -width "-F"
239.It Fl F
240Force a rollback of the file system to the most recent snapshot before
241performing the receive operation.
242If receiving an incremental replication stream
243.Po for example, one generated by
244.Nm zfs Cm send Fl R Op Fl i Ns | Ns Fl I
245.Pc ,
246destroy snapshots and file systems that do not exist on the sending side.
247.It Fl d
248Discard the first element of the sent snapshot's file system name, using the
249remaining elements to determine the name of the target file system for the new
250snapshot as described in the paragraph above.
251.It Fl e
252Discard all but the last element of the sent snapshot's file system name, using
253that element to determine the name of the target file system for the new
254snapshot as described in the paragraph above.
255.It Fl h
256Skip the receive of holds.
257There is no effect if holds are not sent.
258.It Fl M
259Force an unmount of the file system while receiving a snapshot.
260This option is not supported on Linux.
261.It Fl n
262Do not actually receive the stream.
263This can be useful in conjunction with the
264.Fl v
265option to verify the name the receive operation would use.
266.It Fl o Sy origin Ns = Ns Ar snapshot
267Forces the stream to be received as a clone of the given snapshot.
268If the stream is a full send stream, this will create the filesystem
269described by the stream as a clone of the specified snapshot.
270Which snapshot was specified will not affect the success or failure of the
271receive, as long as the snapshot does exist.
272If the stream is an incremental send stream, all the normal verification will be
273performed.
274.It Fl o Em property Ns = Ns Ar value
275Sets the specified property as if the command
276.Nm zfs Cm set Em property Ns = Ns Ar value
277was invoked immediately before the receive.
278When receiving a stream from
279.Nm zfs Cm send Fl R ,
280causes the property to be inherited by all descendant datasets, as through
281.Nm zfs Cm inherit Em property
282was run on any descendant datasets that have this property set on the
283sending system.
284.Pp
285If the send stream was sent with
286.Fl c
287then overriding the
288.Sy compression
289property will have no effect on received data but the
290.Sy compression
291property will be set.
292To have the data recompressed on receive remove the
293.Fl c
294flag from the send stream.
295.Pp
296Any editable property can be set at receive time.
297Set-once properties bound
298to the received data, such as
299.Sy normalization
300and
301.Sy casesensitivity ,
302cannot be set at receive time even when the datasets are newly created by
303.Nm zfs Cm receive .
304Additionally both settable properties
305.Sy version
306and
307.Sy volsize
308cannot be set at receive time.
309.Pp
310The
311.Fl o
312option may be specified multiple times, for different properties.
313An error results if the same property is specified in multiple
314.Fl o
315or
316.Fl x
317options.
318.Pp
319The
320.Fl o
321option may also be used to override encryption properties upon initial receive.
322This allows unencrypted streams to be received as encrypted datasets.
323To cause the received dataset (or root dataset of a recursive stream) to be
324received as an encryption root, specify encryption properties in the same
325manner as is required for
326.Nm zfs Cm create .
327For instance:
328.Dl # Nm zfs Cm send Pa tank/test@snap1 | Nm zfs Cm recv Fl o Sy encryption Ns = Ns Sy on Fl o Sy keyformat Ns = Ns Sy passphrase Fl o Sy keylocation Ns = Ns Pa file:///path/to/keyfile
329.Pp
330Note that
331.Fl o Sy keylocation Ns = Ns Sy prompt
332may not be specified here, since the standard input
333is already being utilized for the send stream.
334Once the receive has completed, you can use
335.Nm zfs Cm set
336to change this setting after the fact.
337Similarly, you can receive a dataset as an encrypted child by specifying
338.Fl x Sy encryption
339to force the property to be inherited.
340Overriding encryption properties (except for
341.Sy keylocation )
342is not possible with raw send streams.
343.It Fl s
344If the receive is interrupted, save the partially received state, rather
345than deleting it.
346Interruption may be due to premature termination of the stream
347.Po e.g. due to network failure or failure of the remote system
348if the stream is being read over a network connection
349.Pc ,
350a checksum error in the stream, termination of the
351.Nm zfs Cm receive
352process, or unclean shutdown of the system.
353.Pp
354The receive can be resumed with a stream generated by
355.Nm zfs Cm send Fl t Ar token ,
356where the
357.Ar token
358is the value of the
359.Sy receive_resume_token
360property of the filesystem or volume which is received into.
361.Pp
362To use this flag, the storage pool must have the
363.Sy extensible_dataset
364feature enabled.
365See
366.Xr zpool-features 7
367for details on ZFS feature flags.
368.It Fl u
369File system that is associated with the received stream is not mounted.
370.It Fl v
371Print verbose information about the stream and the time required to perform the
372receive operation.
373.It Fl x Em property
374Ensures that the effective value of the specified property after the
375receive is unaffected by the value of that property in the send stream (if any),
376as if the property had been excluded from the send stream.
377.Pp
378If the specified property is not present in the send stream, this option does
379nothing.
380.Pp
381If a received property needs to be overridden, the effective value will be
382set or inherited, depending on whether the property is inheritable or not.
383.Pp
384In the case of an incremental update,
385.Fl x
386leaves any existing local setting or explicit inheritance unchanged.
387.Pp
388All
389.Fl o
390restrictions (e.g. set-once) apply equally to
391.Fl x .
392.El
393.It Xo
394.Nm zfs
395.Cm receive
396.Fl A
397.Ar filesystem Ns | Ns Ar volume
398.Xc
399Abort an interrupted
400.Nm zfs Cm receive Fl s ,
401deleting its saved partially received state.
402.It Xo
403.Nm zfs
404.Cm receive
405.Fl c
406.Op Fl vn
407.Ar filesystem Ns | Ns Ar snapshot
408.Xc
409Attempt to correct data corruption in the specified dataset,
410by using the provided stream as the source of healthy data.
411This method of healing can only heal data blocks present in the stream.
412Metadata can not be healed by corrective receive.
413Running a scrub is recommended post-healing to ensure all corruption was
414healed.
415.Pp
416It's important to consider why corruption has happened in the first place
417since if you have slowly failing hardware periodically healing the data
418is not going to save you from data loss later on when the hardware fails
419completely.
420.El
421.
422.Sh EXAMPLES
423.\" These are, respectively, examples 12, 13 from zfs.8
424.\" Make sure to update them bidirectionally
425.Ss Example 1 : No Remotely Replicating ZFS Data
426The following commands send a full stream and then an incremental stream to a
427remote machine, restoring them into
428.Em poolB/received/fs@a
429and
430.Em poolB/received/fs@b ,
431respectively.
432.Em poolB
433must contain the file system
434.Em poolB/received ,
435and must not initially contain
436.Em poolB/received/fs .
437.Bd -literal -compact -offset Ds
438.No # Nm zfs Cm send Ar pool/fs@a |
439.No "   " Nm ssh Ar host Nm zfs Cm receive Ar poolB/received/fs Ns @ Ns Ar a
440.No # Nm zfs Cm send Fl i Ar a pool/fs@b |
441.No "   " Nm ssh Ar host Nm zfs Cm receive Ar poolB/received/fs
442.Ed
443.
444.Ss Example 2 : No Using the Nm zfs Cm receive Fl d No Option
445The following command sends a full stream of
446.Ar poolA/fsA/fsB@snap
447to a remote machine, receiving it into
448.Ar poolB/received/fsA/fsB@snap .
449The
450.Ar fsA/fsB@snap
451portion of the received snapshot's name is determined from the name of the sent
452snapshot.
453.Ar poolB
454must contain the file system
455.Ar poolB/received .
456If
457.Ar poolB/received/fsA
458does not exist, it is created as an empty file system.
459.Bd -literal -compact -offset Ds
460.No # Nm zfs Cm send Ar poolA/fsA/fsB@snap |
461.No "   " Nm ssh Ar host Nm zfs Cm receive Fl d Ar poolB/received
462.Ed
463.
464.Sh SEE ALSO
465.Xr zfs-send 8 ,
466.Xr zstream 8
467