xref: /freebsd/sys/contrib/openzfs/man/man8/zfs-destroy.8 (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1*61145dc2SMartin Matuska.\" SPDX-License-Identifier: CDDL-1.0
2eda14cbcSMatt Macy.\"
3eda14cbcSMatt Macy.\" CDDL HEADER START
4eda14cbcSMatt Macy.\"
5eda14cbcSMatt Macy.\" The contents of this file are subject to the terms of the
6eda14cbcSMatt Macy.\" Common Development and Distribution License (the "License").
7eda14cbcSMatt Macy.\" You may not use this file except in compliance with the License.
8eda14cbcSMatt Macy.\"
9eda14cbcSMatt Macy.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10271171e0SMartin Matuska.\" or https://opensource.org/licenses/CDDL-1.0.
11eda14cbcSMatt Macy.\" See the License for the specific language governing permissions
12eda14cbcSMatt Macy.\" and limitations under the License.
13eda14cbcSMatt Macy.\"
14eda14cbcSMatt Macy.\" When distributing Covered Code, include this CDDL HEADER in each
15eda14cbcSMatt Macy.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16eda14cbcSMatt Macy.\" If applicable, add the following below this CDDL HEADER, with the
17eda14cbcSMatt Macy.\" fields enclosed by brackets "[]" replaced with your own identifying
18eda14cbcSMatt Macy.\" information: Portions Copyright [yyyy] [name of copyright owner]
19eda14cbcSMatt Macy.\"
20eda14cbcSMatt Macy.\" CDDL HEADER END
21eda14cbcSMatt Macy.\"
22eda14cbcSMatt Macy.\" Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved.
23eda14cbcSMatt Macy.\" Copyright 2011 Joshua M. Clulow <josh@sysmgr.org>
24eda14cbcSMatt Macy.\" Copyright (c) 2011, 2019 by Delphix. All rights reserved.
25eda14cbcSMatt Macy.\" Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
26eda14cbcSMatt Macy.\" Copyright (c) 2014, Joyent, Inc. All rights reserved.
27eda14cbcSMatt Macy.\" Copyright (c) 2014 by Adam Stevko. All rights reserved.
28eda14cbcSMatt Macy.\" Copyright (c) 2014 Integros [integros.com]
29eda14cbcSMatt Macy.\" Copyright 2019 Richard Laager. All rights reserved.
30eda14cbcSMatt Macy.\" Copyright 2018 Nexenta Systems, Inc.
31eda14cbcSMatt Macy.\" Copyright 2019 Joyent, Inc.
32eda14cbcSMatt Macy.\"
33da5137abSMartin Matuska.Dd March 16, 2022
34eda14cbcSMatt Macy.Dt ZFS-DESTROY 8
35eda14cbcSMatt Macy.Os
3616038816SMartin Matuska.
37eda14cbcSMatt Macy.Sh NAME
387877fdebSMatt Macy.Nm zfs-destroy
3916038816SMartin Matuska.Nd destroy ZFS dataset, snapshots, or bookmark
40eda14cbcSMatt Macy.Sh SYNOPSIS
417877fdebSMatt Macy.Nm zfs
42eda14cbcSMatt Macy.Cm destroy
43eda14cbcSMatt Macy.Op Fl Rfnprv
44eda14cbcSMatt Macy.Ar filesystem Ns | Ns Ar volume
457877fdebSMatt Macy.Nm zfs
46eda14cbcSMatt Macy.Cm destroy
47eda14cbcSMatt Macy.Op Fl Rdnprv
48eda14cbcSMatt Macy.Ar filesystem Ns | Ns Ar volume Ns @ Ns Ar snap Ns
4916038816SMartin Matuska.Oo % Ns Ar snap Ns Oo , Ns Ar snap Ns Oo % Ns Ar snap Oc Oc Oc Ns …
507877fdebSMatt Macy.Nm zfs
51eda14cbcSMatt Macy.Cm destroy
52eda14cbcSMatt Macy.Ar filesystem Ns | Ns Ar volume Ns # Ns Ar bookmark
5316038816SMartin Matuska.
54eda14cbcSMatt Macy.Sh DESCRIPTION
55eda14cbcSMatt Macy.Bl -tag -width ""
56eda14cbcSMatt Macy.It Xo
577877fdebSMatt Macy.Nm zfs
58eda14cbcSMatt Macy.Cm destroy
59eda14cbcSMatt Macy.Op Fl Rfnprv
60eda14cbcSMatt Macy.Ar filesystem Ns | Ns Ar volume
61eda14cbcSMatt Macy.Xc
62eda14cbcSMatt MacyDestroys the given dataset.
63eda14cbcSMatt MacyBy default, the command unshares any file systems that are currently shared,
64eda14cbcSMatt Macyunmounts any file systems that are currently mounted, and refuses to destroy a
65eda14cbcSMatt Macydataset that has active dependents
66eda14cbcSMatt Macy.Pq children or clones .
67eda14cbcSMatt Macy.Bl -tag -width "-R"
68eda14cbcSMatt Macy.It Fl R
69eda14cbcSMatt MacyRecursively destroy all dependents, including cloned file systems outside the
70eda14cbcSMatt Macytarget hierarchy.
71eda14cbcSMatt Macy.It Fl f
7216038816SMartin MatuskaForcibly unmount file systems.
73eda14cbcSMatt MacyThis option has no effect on non-file systems or unmounted file systems.
74eda14cbcSMatt Macy.It Fl n
75eda14cbcSMatt MacyDo a dry-run
76eda14cbcSMatt Macy.Pq Qq No-op
77eda14cbcSMatt Macydeletion.
78eda14cbcSMatt MacyNo data will be deleted.
79eda14cbcSMatt MacyThis is useful in conjunction with the
80eda14cbcSMatt Macy.Fl v
81eda14cbcSMatt Macyor
82eda14cbcSMatt Macy.Fl p
83eda14cbcSMatt Macyflags to determine what data would be deleted.
84eda14cbcSMatt Macy.It Fl p
85eda14cbcSMatt MacyPrint machine-parsable verbose information about the deleted data.
86eda14cbcSMatt Macy.It Fl r
87eda14cbcSMatt MacyRecursively destroy all children.
88eda14cbcSMatt Macy.It Fl v
89eda14cbcSMatt MacyPrint verbose information about the deleted data.
90eda14cbcSMatt Macy.El
91eda14cbcSMatt Macy.Pp
92eda14cbcSMatt MacyExtreme care should be taken when applying either the
93eda14cbcSMatt Macy.Fl r
94eda14cbcSMatt Macyor the
95eda14cbcSMatt Macy.Fl R
96eda14cbcSMatt Macyoptions, as they can destroy large portions of a pool and cause unexpected
97eda14cbcSMatt Macybehavior for mounted file systems in use.
98eda14cbcSMatt Macy.It Xo
997877fdebSMatt Macy.Nm zfs
100eda14cbcSMatt Macy.Cm destroy
101eda14cbcSMatt Macy.Op Fl Rdnprv
102eda14cbcSMatt Macy.Ar filesystem Ns | Ns Ar volume Ns @ Ns Ar snap Ns
10316038816SMartin Matuska.Oo % Ns Ar snap Ns Oo , Ns Ar snap Ns Oo % Ns Ar snap Oc Oc Oc Ns …
104eda14cbcSMatt Macy.Xc
105b59a0cdeSMartin MatuskaAttempts to destroy the given snapshot(s).
106b59a0cdeSMartin MatuskaThis will fail if any clones of the snapshot exist or if the snapshot is held.
107b59a0cdeSMartin MatuskaIn this case, by default,
10816038816SMartin Matuska.Nm zfs Cm destroy
109b59a0cdeSMartin Matuskawill have no effect and exit in error.
110b59a0cdeSMartin MatuskaIf the
111eda14cbcSMatt Macy.Fl d
112b59a0cdeSMartin Matuskaoption is applied, the command will instead mark the given snapshot for
113b59a0cdeSMartin Matuskaautomatic destruction as soon as it becomes eligible.
114b59a0cdeSMartin MatuskaWhile marked for destruction, a snapshot remains visible, and the user may
115b59a0cdeSMartin Matuskacreate new clones from it and place new holds on it.
116eda14cbcSMatt Macy.Pp
117b59a0cdeSMartin MatuskaThe read-only snapshot properties
118b59a0cdeSMartin Matuska.Sy defer_destroy
119b59a0cdeSMartin Matuskaand
120b59a0cdeSMartin Matuska.Sy userrefs
121b59a0cdeSMartin Matuskaare used by
122b59a0cdeSMartin Matuska.Nm zfs Cm destroy
123b59a0cdeSMartin Matuskato determine eligibility and marked status.
124eda14cbcSMatt Macy.Pp
125eda14cbcSMatt MacyAn inclusive range of snapshots may be specified by separating the first and
126eda14cbcSMatt Macylast snapshots with a percent sign.
127eda14cbcSMatt MacyThe first and/or last snapshots may be left blank, in which case the
128eda14cbcSMatt Macyfilesystem's oldest or newest snapshot will be implied.
129eda14cbcSMatt Macy.Pp
130eda14cbcSMatt MacyMultiple snapshots
131eda14cbcSMatt Macy.Pq or ranges of snapshots
132eda14cbcSMatt Macyof the same filesystem or volume may be specified in a comma-separated list of
133eda14cbcSMatt Macysnapshots.
134eda14cbcSMatt MacyOnly the snapshot's short name
135eda14cbcSMatt Macy.Po the part after the
136eda14cbcSMatt Macy.Sy @
137eda14cbcSMatt Macy.Pc
138eda14cbcSMatt Macyshould be specified when using a range or comma-separated list to identify
139eda14cbcSMatt Macymultiple snapshots.
140eda14cbcSMatt Macy.Bl -tag -width "-R"
141eda14cbcSMatt Macy.It Fl R
142eda14cbcSMatt MacyRecursively destroy all clones of these snapshots, including the clones,
143eda14cbcSMatt Macysnapshots, and children.
144eda14cbcSMatt MacyIf this flag is specified, the
145eda14cbcSMatt Macy.Fl d
146eda14cbcSMatt Macyflag will have no effect.
147eda14cbcSMatt Macy.It Fl d
148b59a0cdeSMartin MatuskaRather than returning error if the given snapshot is ineligible for immediate
149b59a0cdeSMartin Matuskadestruction, mark it for deferred, automatic destruction once it becomes
150b59a0cdeSMartin Matuskaeligible.
151eda14cbcSMatt Macy.It Fl n
152eda14cbcSMatt MacyDo a dry-run
153eda14cbcSMatt Macy.Pq Qq No-op
154eda14cbcSMatt Macydeletion.
155eda14cbcSMatt MacyNo data will be deleted.
156eda14cbcSMatt MacyThis is useful in conjunction with the
157eda14cbcSMatt Macy.Fl p
158eda14cbcSMatt Macyor
159eda14cbcSMatt Macy.Fl v
160eda14cbcSMatt Macyflags to determine what data would be deleted.
161eda14cbcSMatt Macy.It Fl p
162eda14cbcSMatt MacyPrint machine-parsable verbose information about the deleted data.
163eda14cbcSMatt Macy.It Fl r
164eda14cbcSMatt MacyDestroy
165eda14cbcSMatt Macy.Pq or mark for deferred deletion
166eda14cbcSMatt Macyall snapshots with this name in descendent file systems.
167eda14cbcSMatt Macy.It Fl v
168eda14cbcSMatt MacyPrint verbose information about the deleted data.
169c6767dc1SMartin Matuska.El
170eda14cbcSMatt Macy.Pp
171eda14cbcSMatt MacyExtreme care should be taken when applying either the
172eda14cbcSMatt Macy.Fl r
173eda14cbcSMatt Macyor the
174eda14cbcSMatt Macy.Fl R
175eda14cbcSMatt Macyoptions, as they can destroy large portions of a pool and cause unexpected
176eda14cbcSMatt Macybehavior for mounted file systems in use.
177eda14cbcSMatt Macy.It Xo
1787877fdebSMatt Macy.Nm zfs
179eda14cbcSMatt Macy.Cm destroy
180eda14cbcSMatt Macy.Ar filesystem Ns | Ns Ar volume Ns # Ns Ar bookmark
181eda14cbcSMatt Macy.Xc
182eda14cbcSMatt MacyThe given bookmark is destroyed.
183eda14cbcSMatt Macy.El
18416038816SMartin Matuska.
185da5137abSMartin Matuska.Sh EXAMPLES
186da5137abSMartin Matuska.\" These are, respectively, examples 3, 10, 15 from zfs.8
187da5137abSMartin Matuska.\" Make sure to update them bidirectionally
188da5137abSMartin Matuska.Ss Example 1 : No Creating and Destroying Multiple Snapshots
189da5137abSMartin MatuskaThe following command creates snapshots named
190da5137abSMartin Matuska.Ar yesterday No of Ar pool/home
191da5137abSMartin Matuskaand all of its descendent file systems.
192da5137abSMartin MatuskaEach snapshot is mounted on demand in the
193da5137abSMartin Matuska.Pa .zfs/snapshot
194da5137abSMartin Matuskadirectory at the root of its file system.
195da5137abSMartin MatuskaThe second command destroys the newly created snapshots.
196da5137abSMartin Matuska.Dl # Nm zfs Cm snapshot Fl r Ar pool/home Ns @ Ns Ar yesterday
197da5137abSMartin Matuska.Dl # Nm zfs Cm destroy Fl r Ar pool/home Ns @ Ns Ar yesterday
198da5137abSMartin Matuska.
199da5137abSMartin Matuska.Ss Example 2 : No Promoting a ZFS Clone
200da5137abSMartin MatuskaThe following commands illustrate how to test out changes to a file system, and
201da5137abSMartin Matuskathen replace the original file system with the changed one, using clones, clone
202da5137abSMartin Matuskapromotion, and renaming:
203da5137abSMartin Matuska.Bd -literal -compact -offset Ds
204da5137abSMartin Matuska.No # Nm zfs Cm create Ar pool/project/production
205da5137abSMartin Matuska  populate /pool/project/production with data
206da5137abSMartin Matuska.No # Nm zfs Cm snapshot Ar pool/project/production Ns @ Ns Ar today
207da5137abSMartin Matuska.No # Nm zfs Cm clone Ar pool/project/production@today pool/project/beta
208da5137abSMartin Matuska  make changes to /pool/project/beta and test them
209da5137abSMartin Matuska.No # Nm zfs Cm promote Ar pool/project/beta
210da5137abSMartin Matuska.No # Nm zfs Cm rename Ar pool/project/production pool/project/legacy
211da5137abSMartin Matuska.No # Nm zfs Cm rename Ar pool/project/beta pool/project/production
212da5137abSMartin Matuska  once the legacy version is no longer needed, it can be destroyed
213da5137abSMartin Matuska.No # Nm zfs Cm destroy Ar pool/project/legacy
214da5137abSMartin Matuska.Ed
215da5137abSMartin Matuska.
216da5137abSMartin Matuska.Ss Example 3 : No Performing a Rolling Snapshot
217da5137abSMartin MatuskaThe following example shows how to maintain a history of snapshots with a
218da5137abSMartin Matuskaconsistent naming scheme.
219da5137abSMartin MatuskaTo keep a week's worth of snapshots, the user destroys the oldest snapshot,
220da5137abSMartin Matuskarenames the remaining snapshots, and then creates a new snapshot, as follows:
221da5137abSMartin Matuska.Bd -literal -compact -offset Ds
222da5137abSMartin Matuska.No # Nm zfs Cm destroy Fl r Ar pool/users@7daysago
223da5137abSMartin Matuska.No # Nm zfs Cm rename Fl r Ar pool/users@6daysago No @ Ns Ar 7daysago
224da5137abSMartin Matuska.No # Nm zfs Cm rename Fl r Ar pool/users@5daysago No @ Ns Ar 6daysago
225da5137abSMartin Matuska.No # Nm zfs Cm rename Fl r Ar pool/users@4daysago No @ Ns Ar 5daysago
226da5137abSMartin Matuska.No # Nm zfs Cm rename Fl r Ar pool/users@3daysago No @ Ns Ar 4daysago
227da5137abSMartin Matuska.No # Nm zfs Cm rename Fl r Ar pool/users@2daysago No @ Ns Ar 3daysago
228da5137abSMartin Matuska.No # Nm zfs Cm rename Fl r Ar pool/users@yesterday No @ Ns Ar 2daysago
229da5137abSMartin Matuska.No # Nm zfs Cm rename Fl r Ar pool/users@today No @ Ns Ar yesterday
230da5137abSMartin Matuska.No # Nm zfs Cm snapshot Fl r Ar pool/users Ns @ Ns Ar today
231da5137abSMartin Matuska.Ed
232da5137abSMartin Matuska.
233eda14cbcSMatt Macy.Sh SEE ALSO
234eda14cbcSMatt Macy.Xr zfs-create 8 ,
235b59a0cdeSMartin Matuska.Xr zfs-hold 8 ,
236b59a0cdeSMartin Matuska.Xr zfsprops 8
237