Merge from vendor branch LIBARCHIVE:
[dragonfly.git] / sbin / hammer / hammer.8
1 .\" Copyright (c) 2007 The DragonFly Project.  All rights reserved.
2 .\" 
3 .\" This code is derived from software contributed to The DragonFly Project
4 .\" by Matthew Dillon <dillon@backplane.com>
5 .\" 
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
8 .\" are met:
9 .\" 
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\"    notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\"    notice, this list of conditions and the following disclaimer in
14 .\"    the documentation and/or other materials provided with the
15 .\"    distribution.
16 .\" 3. Neither the name of The DragonFly Project nor the names of its
17 .\"    contributors may be used to endorse or promote products derived
18 .\"    from this software without specific, prior written permission.
19 .\" 
20 .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 .\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 .\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
24 .\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 .\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 .\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28 .\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 .\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .\" SUCH DAMAGE.
32 .\" 
33 .\" $DragonFly: src/sbin/hammer/hammer.8,v 1.35 2008/07/12 02:48:46 dillon Exp $
34 .Dd June 26, 2008
35 .Dt HAMMER 8
36 .Os
37 .Sh NAME
38 .Nm hammer
39 .Nd HAMMER file system utility
40 .Sh SYNOPSIS
41 .Nm
42 .Op Fl hrv2
43 .Op Fl c Ar cyclefile
44 .Op Fl f Ar blkdev[:blkdev]*
45 .Op Fl s Ar linkpath
46 .Op Fl t Ar seconds
47 .Ar command
48 .Ar ...
49 .Sh DESCRIPTION
50 The
51 .Nm
52 utility provides miscellaneous functions related to managing a HAMMER
53 filesystem.
54 .Pp
55 The options are as follows:
56 .Bl -tag -width indent
57 .It Fl h
58 Get help
59 .It Fl 2
60 Tell the mirror commands to use a 2-way protocol, which allows
61 automatic negotiation of transaction id ranges.  This option is
62 automatically enabled by the
63 .Ar mirror-copy
64 command.
65 .It Fl r
66 Specify recursion for those commands which support it.
67 .It Fl c Ar cyclefile
68 When pruning and reblocking you can instruction HAMMER to start at the
69 object id stored in the specified file.  If the file does not exist
70 HAMMER will start at the beginning.  If HAMMER is told to run for a
71 specific period of time and is unable to complete the operation it will
72 write out the current obj_id so the next run can pick up where it left
73 off.  If HAMMER runs to completion it will delete the cyclefile.
74 .It Fl f Ar blkdev[:blkdev]*
75 Specify the volumes making up a HAMMER filesystem.
76 .It Fl s Ar linkpath
77 When pruning a filesystem you can instruct HAMMER to create softlinks
78 to available snapshots.
79 .It Fl t Ar seconds
80 When pruning and reblocking you can tell the utility to stop after a
81 certain period of time.  This option is used along with the cycle file
82 option to prune or reblock a portion of the filesystem incrementally.
83 .It Fl v
84 Increase verboseness.  May be specified multiple times.
85 .El
86 .Pp
87 The commands are as follows:
88 .Bl -tag -width indent
89 .It Ar synctid Ar filesystem Op quick
90 Generates a guaranteed, formal 64 bit transaction id representing the
91 current state of the specified HAMMER filesystem.  The filesystem will
92 be synced to the media.
93 .Pp
94 If the
95 .Ar quick
96 keyword is specified the filesystem will be soft-synced, meaning that a
97 crash might still undo the state of the filesystem as of the transaction
98 id returned but any new modifications will occur after the returned
99 transaction id as expected.
100 .It Ar bstats Op interval
101 Output HAMMER B-Tree statistics until interrupted.  The default interval
102 is one second.
103 .It Ar iostats Op interval
104 Output HAMMER I/O statistics until interrupted.  The default interval
105 is one second.
106 .It Ar history Ar path
107 Show the modification history for a HAMMER file's inode and data.
108 .It Ar show Op vol_no[:clu_no]
109 Dump the B-Tree starting at the specified volume and cluster, or
110 at the root volume if not specified.
111 The B-Tree is dumped recursively if the
112 .Fl r
113 option is specified.
114 .It Ar blockmap
115 Dump the btree, record, large-data, and small-data blockmaps, showing
116 physical block assignments and free space percentages.
117 .It Ar namekey Ar filename
118 Generate a HAMMER 64 bit directory hash for the specified file name.
119 The low 32 bits are used as an iterator for hash collisions and will be
120 output as 0.
121 .It Ar namekey32 Ar filename
122 Generate the top 32 bits of a HAMMER 64 bit directory hash for the specified
123 file name.
124 .It Ar prune Ar softlink-dir
125 Prune the filesystem based on previously created snapshot softlinks.
126 The target directory is expected to contain softlinks pointing to
127 snapshots of the filesystems you wish to retain.  The directory is scanned
128 non-recursively and the mount points and transaction ids stored in the
129 softlinks are extracted and sorted.
130 The filesystem is then explicitly pruned according to what is found.
131 Cleaning out portions of the filesystem is as simple as removing a softlink
132 and then running the
133 .Ar prune
134 command.
135 .Pp
136 As a safety measure pruning only occurs if one or more softlinks are found
137 containing the @@ snapshot id extension.
138 .Pp
139 Currently the scanned softlink directory must contain softlinks pointing
140 to a single HAMMER mount.  The softlinks may specify absolute or relative
141 paths.  Softlinks must use 20-character (@@0x%016llx) transaction ids,
142 as might be returned from 'hammer synctid <filesystem>'.
143 .Pp
144 Example, lets say your snapshot directory contains the following links:
145 .Bd -literal
146 lrwxr-xr-x  1 root  wheel  29 May 31 17:57 snap1 ->
147 /usr/obj/@@0x10d2cd05b7270d16
148
149 lrwxr-xr-x  1 root  wheel  29 May 31 17:58 snap2 ->
150 /usr/obj/@@0x10d2cd13f3fde98f
151
152 lrwxr-xr-x  1 root  wheel  29 May 31 17:59 snap3 ->
153 /usr/obj/@@0x10d2cd222adee364
154 .Ed
155 .Pp
156 If you were to run the prune command on this directory, then the HAMMER
157 .Pa /usr/obj
158 mount will be pruned to retain the above three snapshots.
159 In addition, modifications made to the filesystem older than the oldest
160 snapshot will be destroyed and potentially fine-grained modifications made
161 to the filesystem more recently than the most recent snapshot will be
162 retained.
163 .Pp
164 If you then delete the snap2 softlink and rerun the prune command,
165 modifications pertaining to that snapshot would be destroyed.
166 .It Ar prune-everything Ar filesystem
167 This command will remove all historical records from the filesystem.
168 This directive is not normally used on a production system.
169 .Pp
170 Note that pruning a filesystem may not immediately free-up space,
171 though typically some space will be freed if a large number of records are
172 pruned out.  The filesystem must be reblocked to completely recover all
173 available space.
174 .It Ar snapshot Ar snapshot-dir
175 .It Ar snapshot Ar filesystem snapshot-dir
176 Takes a snapshot of the filesystem either explicitly given by
177 .Ar filesystem
178 or implicitly derived from the
179 .Ar snapshot-dir
180 argument and creates a symlink in the directory provided by
181 .Ar snapshot-dir
182 pointing to the snapshot.
183 If
184 .Ar snapshot-dir
185 is no directory, it is assumed to be a format string
186 passed to
187 .Xr strftime 3
188 with the current time as parameter.
189 If
190 .Ar snapshot-dir
191 refers to an existing directory, a default format string of "snap-%Y%d%m-%H%M"
192 is assumed and used as name for the newly created symlink.
193 Assuming that
194 .Pa /mysnapshots
195 is on filesystem
196 .Pa /
197 and that
198 .Pa /obj
199 is a filesystem on its own, the following invocations:
200 .Bd -literal
201 hammer snapshot /mysnapshots
202
203 hammer snapshot /mysnapshots/%Y-%m-%d
204
205 hammer snapshot /obj /mysnapshots/obj-%Y-%m-%d
206 .Ed
207 .Pp
208 would create symlinks similar to:
209 .Bd -literal
210 /mysnapshots/snap-20080627-1210 -> /@@0x10d2cd05b7270d16
211
212 /mysnapshots/2008-06-27 -> /@@0x10d2cd05b7270d16
213
214 /mysnapshots/obj-2008-06-27 -> /obj@@0x10d2cd05b7270d16
215 .Ed
216 .It Ar reblock Ar filesystem Op Ar fill_percentage
217 .It Ar reblock-btree Ar filesystem Op Ar fill_percentage
218 .It Ar reblock-inodes Ar filesystem Op Ar fill_percentage
219 .It Ar reblock-dirs Ar filesystem Op Ar fill_percentage
220 .It Ar reblock-data Ar filesystem Op Ar fill_percentage
221 Attempt to defragment and free space for reuse by reblocking a live
222 HAMMER filesystem.
223 Big blocks cannot be reused by HAMMER until they are completely free.
224 This command also has the effect of reordering all elements, effectively
225 defragmenting the filesystem.
226 .Pp
227 The default fill percentage is 100% and will cause the filesystem to be
228 completely defragmented.  All specified element types will be reallocated
229 and rewritten.  If you wish to quickly free up space instead try specifying
230 a smaller fill percentage, such as 90% or 80% (the '%' suffix is not needed).
231 .Pp
232 Since this command may rewrite the entire contents of the disk it is
233 best to do it incrementally from a cron job along with the
234 .Fl c Ar cyclefile
235 and
236 .Fl t Ar seconds
237 options to limit the run time.
238 The filesystem would thus be defragmented over long period of time.
239 .Pp
240 It is recommended that separate invocations be used for each data type.
241 Btree nodes, inodes, and directories are typically the most important
242 elements needing defragmentation.  Data can be defragmented over a longer
243 period of time.
244 .It Ar pfs-status Ar dirpath
245 Retrieve the mirroring configuration parameters for the specified
246 HAMMER filesystem or pseudo-filesystem.
247 .It Ar pfs-master Ar dirpath Op options
248 Create a pseudo-filesystem (PFS) inside a HAMMER filesystem.
249 Up to 65535 such filesystems can be created.
250 Each PFS uses an independant inode numbering space making it suitable
251 for use as a replication source or target.
252 .Pp
253 The
254 .Ar pfs-master
255 directive creates a PFS that you can read, write, and use as a mirroring
256 source.
257 .It Ar pfs-slave Ar dirpath Op options
258 Create a pseudo-filesystem (PFS) inside a HAMMER filesystem.
259 Up to 65535 such filesystems can be created.
260 Each PFS uses an independant inode numbering space making it suitable
261 for use as a replication source or target.
262 .Pp
263 The
264 .Ar pfs-slave
265 directive creates a PFS that you can use as a mirroring target.  
266 You will not be able to access a slave PFS until you have completed the
267 first mirroring operation with it as the target (its root directory will
268 not exist until then).
269 .Pp
270 Access to the pfs-slave via the special softlink allows Hammer to
271 dynamically modify the snapshot TID by returning a dynamic result
272 from readlink() calls.
273 .Pp
274 A PFS can only be truely destroyed with the
275 .AR pfs-destroy
276 directive.
277 Removing the softlink will not destroy the underlying PFS.
278 .It Ar pfs-upgrade Ar dirpath
279 Upgrade a PFS from slave to master operation.  The PFS becomes writable.
280 A master id must already be assigned to the PFS.
281 .Pp
282 WARNING!  HAMMER currently supports only single masters and using
283 this command can easily result in filesystem corruption if you don't
284 know what you are doing.
285 .Pp
286 This directive will refuse to run if any programs have open descriptors
287 in the PFS, including programs chdir'd into the PFS.
288 .It Ar pfs-downgrade Ar dirpath
289 Downgrade a master PFS from master to slave operation.  The PFS becomes
290 read-only and access will be locked to its sync_end_tid.
291 .Pp
292 This directive will refuse to run if any programs have open descriptors
293 in the PFS, including programs chdir'd into the PFS.
294 .It Ar pfs-destroy Ar dirpath
295 This permanently destroys a PFS.
296 .Pp
297 This directive will refuse to run if any programs have open descriptors
298 in the PFS, including programs chdir'd into the PFS.
299 .It Ar pfs-update Ar dirpath Op options
300 Update the configuration parameters for an existing HAMMER filesystem
301 or pseudo-filesystem.  Options that may be specified:
302 .Pp
303 .Bl -tag -width indent
304 .It sync-beg-tid=0x16llx
305 This is the automatic snapshot access starting TID for mirroring slaves.
306 This parameter is normally updated automatically by the
307 .Ar mirror-write
308 directive.
309 .Pp
310 It is important to note that accessing a mirroring slave
311 with a transaction id greater then the last fully synchronized transaction
312 id can result in an unreliable snapshot since you will be accessing
313 data that is still undergoing synchronization.
314 .Pp
315 Manually modifying this field is dangerous and can result in a broken
316 mirror.
317 .It sync-end-tid=0x16llx
318 This is the current synchronization point for mirroring slaves.
319 This parameter is normally updated automatically by the
320 .Ar mirror-write
321 directive.
322 .Pp
323 Manually modifying this field is dangerous and can result in a broken
324 mirror.
325 .It shared-uuid=<uuid>
326 Set the shared uuid for this filesystem.  All mirrors must have the same
327 shared uuid.  For safety purposes the mirror-write directives will refuse
328 to operate on a target with a different shared uuid.
329 .Pp
330 Changing the shared uuid on an existing, non-empty mirroring target,
331 including an empty but not completely pruned target, can lead
332 to corruption of the mirroring target.
333 .It unique-uuid=<uuid>
334 Set the unique uuid for this filesystem.  This uuid should not be used
335 anywhere else, even on exact copies of the filesystem.
336 .It master=<num>
337 Set the master id for multi-master mirroring.  Only values between 0 and 15
338 inclusive may be specified.  All masters sharing the same
339 .Ar shared-uuid
340 must have different ids.
341 Up to 16 masters will eventually be supported.
342 .Pp
343 Multi-master mirroring is not supported yet and the master id should be
344 set to 0 on the single master when mirroring to one or more slaves.
345 .Pp
346 The master id may only be changed if the PFS is in master mode.  A PFS
347 slave cannot be upgraded to a master at this time.
348 .It no-mirror
349 This disables the ability to use this filesystem as a mirroring source
350 or target.  You can still do full scans with mirror-read but incremental
351 scans will not work.  This option may only be set on masters.
352 .It slave
353 Sets slave mode, allowing the mirror to be used as a slave.  Except for
354 the mirror-write directive all accesses to the mirror will be made read-only
355 and will be as-of the
356 .Ar sync_beg_tid .
357 This option is currently not supported, slave mode must be specified
358 when creating the PFS and cannot be changed on the fly.
359 .It label=<string>
360 Set a descriptive label for this filesystem.
361 .El
362 .It Ar mirror-read Ar filesystem Op Ar <begin-tid>
363 Generate a mirroring stream to stdout.
364 .It Ar mirror-write Ar filesystem Op Ar
365 Take a mirroring stream on stdin and output it to stdout.
366 .Pp
367 This command will fail if the
368 .Ar shared_uuid
369 configuration field for the two filesystems do not match.
370 .It Ar mirror-dump
371 A mirror-read can be piped into a mirror-dump to dump an ascii
372 representation of the mirroring stream.
373 .It Ar mirror-copy Ar [[user@]host:]filesystem Ar [[user@]host:]filesystem
374 This is a shortcut which pipes a mirror-read command to a mirror-write
375 command.  If a remote host specification is made the program forks a
376 ssh and execs the mirror-read and/or mirror-write on the appropriate host.
377 The source may be a master or slave PFS, and the target must be a slave PFS.
378 .Pp
379 This command also established full duplex communication and turns on
380 the two-way protocol feature which automatically negotiates TID ranges 
381 without having to use a cycle file.
382 If the operation completes successfully the target PFS's sync_end_tid will
383 be updated.  Note that you must re-chdir into the target PFS to see the
384 updated information.  If you do not you will still be in the previous snapshot.
385 .El
386 .\".Sh EXAMPLES
387 .Sh PSEUDO FILESYSTEM (PFS) NOTES
388 The root of a PFS is not hooked into the primary HAMMER filesystem as a
389 directory.
390 Instead, HAMMER creates a special softlink called "@@PFS%05d" (exactly 10
391 characters long) in the primary HAMMER filesystem.
392 HAMMER then modifies the contents of the softlink as read by
393 .Xr readlink 2 ,
394 and thus what you see with an ls command or if you were to cd into the link.
395 If the PFS is a master the link reflects the current state of the PFS.
396 If the PFS is a slave the link reflects the last completed snapshot, and the
397 contents of the link will change when the next snapshot is completed, and
398 so forth.
399 .Pp
400 PFS support is currently very new and experimental.  The
401 .Nm
402 utility
403 employs numerous safeties to reduce user foot-shooting.
404 The
405 .Ar mirror-copy
406 directive requires that the target be configured as a slave and that the
407 .Ar shared-uuid
408 field of the mirroring source and target match.
409 .Pp
410 .Sh DIAGNOSTICS
411 .Ex -std
412 .Sh SEE ALSO
413 .Xr newfs_hammer 8
414 .Sh HISTORY
415 The
416 .Nm
417 utility first appeared in
418 .Dx 1.11 .
419 .Sh AUTHORS
420 .An Matthew Dillon Aq dillon@backplane.com