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