3e436ab5f89dec88e11ffdba77e75eaac6f94ecf
[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.58 2008/11/13 02:04:27 dillon Exp $
34 .\"
35 .Dd November 14, 2009
36 .Dt HAMMER 8
37 .Os
38 .Sh NAME
39 .Nm hammer
40 .Nd HAMMER file system utility
41 .Sh SYNOPSIS
42 .Nm
43 .Fl h
44 .Nm
45 .Op Fl 2Bqrvy
46 .Op Fl b Ar bandwidth
47 .Op Fl C Ar cachesize Ns Op Ns Cm \&: Ns Ar readahead
48 .Op Fl c Ar cyclefile
49 .Op Fl f Ar blkdevs
50 .\" .Op Fl s Ar linkpath
51 .Op Fl i Ar delay
52 .Op Fl t Ar seconds
53 .Ar command
54 .Op Ar argument ...
55 .Sh DESCRIPTION
56 This manual page documents the
57 .Nm
58 utility which provides miscellaneous functions related to managing a
59 .Nm HAMMER
60 file system.
61 For a general introduction to the
62 .Nm HAMMER
63 file system, its features, and
64 examples on how to set up and maintain one, see
65 .Xr HAMMER 5 .
66 .Pp
67 The options are as follows:
68 .Bl -tag -width indent
69 .It Fl h
70 Get help.
71 .It Fl 2
72 Tell the mirror commands to use a 2-way protocol, which allows
73 automatic negotiation of transaction id ranges.
74 This option is automatically enabled by the
75 .Cm mirror-copy
76 command.
77 .It Fl B
78 Bulk Transfer.
79 .Cm Mirror-stream
80 will not attempt to break-up large initial bulk transfers into smaller pieces.
81 This can save time but if the link is lost in the middle of the
82 initial bulk transfer you will have to start over from scratch.
83 .It Fl b Ar bandwidth
84 Specify a bandwidth limit in bytes per second for mirroring streams.
85 This option is typically used to prevent batch mirroring operations from
86 loading down the machine.
87 The bandwidth may be suffixed with
88 .Cm k , m ,
89 or
90 .Cm g
91 to specify values in kilobytes, megabytes, and gigabytes per second.
92 If no suffix is specified, bytes per second is assumed.
93 .It Fl C Ar cachesize Ns Op Ns Cm \&: Ns Ar readahead
94 Set the memory cache size for any raw
95 .Tn I/O .
96 The default is 16m.
97 A suffix of
98 .Cm k
99 for kilobytes and
100 .Cm m
101 for megabytes is allowed,
102 else the cache size is specified in bytes.
103 .Pp
104 The read-behind/read-ahead defaults to 4
105 .Nm HAMMER
106 blocks.
107 .Pp
108 This option is typically only used with diagnostic commands
109 as kernel-supported commands will use the kernel's buffer cache.
110 .It Fl c Ar cyclefile
111 When pruning and reblocking you can instruction
112 .Nm
113 to start at the object id stored in the specified file.
114 If the file does not exist
115 .Nm
116 will start at the beginning.
117 If
118 .Nm
119 is told to run for a
120 specific period of time and is unable to complete the operation it will
121 write out the current object id so the next run can pick up where it left off.
122 If
123 .Nm
124 runs to completion it will delete
125 .Ar cyclefile .
126 .It Fl f Ar blkdevs
127 Specify the volumes making up a
128 .Nm HAMMER
129 file system.
130 .Ar Blkdevs
131 is a colon-separated list of devices, each specifying a
132 .Nm HAMMER
133 volume.
134 .It Fl i Ar delay
135 When maintaining a streaming mirroring this option specifies the
136 minimum delay after a batch ends before the next batch is allowed
137 to start.
138 The default is five seconds.
139 .It Fl q
140 Decrease verboseness.
141 May be specified multiple times.
142 .It Fl r
143 Specify recursion for those commands which support it.
144 .It Fl t Ar seconds
145 When pruning and reblocking you can tell the utility to stop after a
146 certain period of time.
147 This option is used along with the
148 .Fl c Ar cyclefile
149 option to prune or reblock a portion of the file system incrementally.
150 .It Fl v
151 Increase verboseness.
152 May be specified multiple times.
153 .It Fl y
154 Force "yes" for any interactive question.
155 .El
156 .Pp
157 The commands are as follows:
158 .Bl -tag -width indent
159 .\" ==== synctid ====
160 .It Cm synctid Ar filesystem Op Cm quick
161 Generates a guaranteed, formal 64 bit transaction id representing the
162 current state of the specified
163 .Nm HAMMER
164 file system.
165 The file system will be synced to the media.
166 .Pp
167 If the
168 .Cm quick
169 keyword is specified the file system will be soft-synced, meaning that a
170 crash might still undo the state of the file system as of the transaction
171 id returned but any new modifications will occur after the returned
172 transaction id as expected.
173 .Pp
174 This operation does not create a snapshot.
175 It is meant to be used
176 to track temporary fine-grained changes to a subset of files and
177 will only remain valid for
178 .Ql @@
179 snapshot access purposes for the
180 .Cm prune-min
181 period configured for the PFS.
182 If you desire a real snapshot then the
183 .Cm snapq
184 directive may be what you are looking for.
185 .\" ==== bstats ====
186 .It Cm bstats Op Ar interval
187 Output
188 .Nm HAMMER
189 B-tree statistics until interrupted.
190 Pause
191 .Ar interval
192 seconds between each display.
193 The default interval is one second.
194 .\" ==== iostats ====
195 .It Cm iostats Op Ar interval
196 Output
197 .Nm HAMMER
198 .Tn I/O
199 statistics until interrupted.
200 Pause
201 .Ar interval
202 seconds between each display.
203 The default interval is one second.
204 .\" ==== history ====
205 .It Cm history Ar path ...
206 Show the modification history for
207 .Nm HAMMER
208 file's inode and data.
209 .\" ==== blockmap ====
210 .It Cm blockmap
211 Dump the blockmap for the file system.
212 The
213 .Nm HAMMER
214 blockmap is two-layer
215 blockmap representing the maximum possible file system size of 1 Exabyte.
216 Needless to say the second layer is only present for blocks which exist.
217 .Nm HAMMER Ns 's
218 blockmap represents 8-Megabyte blocks, called big-blocks.
219 Each big-block has an append
220 point, a free byte count, and a typed zone id which allows content to be
221 reverse engineered to some degree.
222 .Pp
223 In
224 .Nm HAMMER
225 allocations essentially appended to a selected big-block using
226 the append offset and deducted from the free byte count.
227 When space is freed the free byte count is adjusted but
228 .Nm HAMMER
229 does not track holes in big-blocks for reallocation.
230 A big-block must be completely freed, either
231 through normal file system operations or through reblocking, before
232 it can be reused.
233 .Pp
234 Data blocks can be shared by deducting the space used from the free byte
235 count for each shared references, though
236 .Nm HAMMER
237 does not yet make use of this feature.
238 This means the free byte count can legally go negative.
239 .Pp
240 This command needs the
241 .Fl f
242 flag.
243 .\" ==== show ====
244 .It Cm show Op Ar lo Ns Cm \&: Ns Ar objid
245 Dump the B-tree.
246 By default this command will validate all B-Tree
247 linkages and CRCs, including data CRCs, and will report the most verbose
248 information it can dig up.
249 Any errors will show up with a
250 .Ql B
251 in column 1 along with various
252 other error flags.
253 .Pp
254 If you specify a localization and object id field,
255 .Ar lo Ns Cm \&: Ns Ar objid ,
256 the dump will
257 search for the key printing nodes as it recurses down, and then
258 will iterate forwards.
259 .Pp
260 If you use
261 .Fl q
262 the command will report less information about the inode contents.
263 .Pp
264 If you use
265 .Fl qq
266 the command will not report the content of the inode or other typed
267 data at all.
268 .Pp
269 If you use
270 .Fl qqq
271 the command will not report volume header information, big-block fill
272 ratios, mirror transaction ids, or report or check data CRCs.
273 B-tree CRCs and linkages are still checked.
274 .Pp
275 This command needs the
276 .Fl f
277 flag.
278 .\" ==== show-undo ====
279 .It Cm show-undo
280 .Nm ( HAMMER
281 VERSION 4+)
282 Dump the UNDO map.
283 .Pp
284 This command needs the
285 .Fl f
286 flag.
287 .\" .It Ar blockmap
288 .\" Dump the B-tree, record, large-data, and small-data blockmaps, showing
289 .\" physical block assignments and free space percentages.
290 .\" ==== namekey1 ====
291 .It Cm namekey1 Ar filename
292 Generate a
293 .Nm HAMMER
294 64 bit directory hash for the specified file name, using
295 the original directory hash algorithm in version 1 of the file system.
296 The low 32 bits are used as an iterator for hash collisions and will be
297 output as 0.
298 .\" ==== namekey2 ====
299 .It Cm namekey2 Ar filename
300 Generate a
301 .Nm HAMMER
302 64 bit directory hash for the specified file name, using
303 the new directory hash algorithm in version 2 of the file system.
304 The low 32 bits are still used as an iterator but will start out containing
305 part of the hash key.
306 .\" ==== namekey32 ====
307 .It Cm namekey32 Ar filename
308 Generate the top 32 bits of a
309 .Nm HAMMER
310 64 bit directory hash for the specified file name.
311 .\" ==== info ====
312 .It Cm info
313 Shows extended information about all the mounted
314 .Nm HAMMER
315 file systems.
316 At the moment volume identification, big-blocks information, space and
317 and pseudo-filesystem (PFS) details are shown.
318 .\" ==== cleanup ====
319 .It Cm cleanup Op Ar filesystem ...
320 This is a meta-command which executes snapshot, prune, rebalance and reblock
321 commands on the specified
322 .Nm HAMMER
323 file systems.
324 If no
325 .Ar filesystem
326 is specified this command will clean-up all
327 .Nm HAMMER
328 file systems in use, including PFS's.
329 To do this it will scan all
330 .Nm HAMMER
331 and
332 .Nm null
333 mounts, extract PFS id's, and clean-up each PFS found.
334 .Pp
335 This command will access a snapshots
336 directory and a configuration file for each
337 .Ar filesystem ,
338 creating them if necessary.
339 .Bl -tag -width indent
340 .It Nm HAMMER No version 2-
341 The configuration file is
342 .Pa config
343 in the snapshots directory which defaults to
344 .Pa <pfs>/snapshots .
345 .It Nm HAMMER No version 3+
346 The configuration file is saved in file system meta-data, see
347 .Nm
348 .Cm config .
349 The snapshots directory defaults to
350 .Pa /var/hammer/<pfs>
351 .Pa ( /var/hammer/root
352 for root mount).
353 .El
354 .Pp
355 The format of the configuration file is:
356 .Bd -literal -offset indent
357 snapshots  <period> <retention-time> [any]
358 prune      <period> <max-runtime>
359 rebalance  <period> <max-runtime>
360 reblock    <period> <max-runtime>
361 recopy     <period> <max-runtime>
362 .Ed
363 .Pp
364 Defaults are:
365 .Bd -literal -offset indent
366 snapshots  1d 60d  # 0d 0d  for PFS /tmp, /var/tmp, /usr/obj
367 prune      1d 5m
368 rebalance  1d 5m
369 reblock    1d 5m
370 recopy     30d 10m
371 .Ed
372 .Pp
373 Time is given with a suffix of
374 .Cm d ,
375 .Cm h ,
376 .Cm m
377 or
378 .Cm s
379 meaning day, hour, minute and second.
380 .Pp
381 If the
382 .Cm snapshots
383 directive has a period of 0 and a retention time of 0
384 then snapshot generation is disabled, removal of old snapshots are
385 disabled, and prunes will use
386 .Cm prune-everything .
387 If the
388 .Cm snapshots
389 directive has a period of 0 but a non-zero retention time
390 then this command will not create any new snapshots but will remove old
391 snapshots it finds based on the retention time.
392 .Pp
393 By default only snapshots in the form
394 .Ql snap- Ns Ar yyyymmdd Ns Op - Ns Ar HHMM
395 are processed.
396 If the
397 .Cm any
398 directive is specified as a third argument on the
399 .Cm snapshots
400 config line then any softlink of the form
401 .Ql *- Ns Ar yyyymmdd Ns Op - Ns Ar HHMM
402 or
403 .Ql *. Ns Ar yyyymmdd Ns Op - Ns Ar HHMM
404 will be processed.
405 .Pp
406 A prune max-runtime of 0 means unlimited.
407 .Pp
408 If period hasn't passed since the previous
409 .Cm cleanup
410 run nothing is done.
411 For example a day has passed when midnight is passed (localtime).
412 By default,
413 .Dx
414 is set up to run
415 .Nm Ar cleanup
416 nightly via
417 .Xr periodic 8 .
418 .Pp
419 The default configuration file will create a daily snapshot, do a daily
420 pruning, rebalancing and reblocking run and a monthly recopy run.
421 Reblocking is defragmentation with a level of 95%,
422 and recopy is full defragmentation.
423 .Pp
424 By default prune and rebalance operations are time limited to 5 minutes,
425 reblock operations to a bit over 5 minutes,
426 and recopy operations to a bit over 10 minutes.
427 Reblocking and recopy runs are each broken down into four separate functions:
428 btree, inodes, dirs and data.
429 Each function is time limited to the time given in the configuration file,
430 but the btree, inodes and dirs functions usually does not take very long time,
431 full defragmentation is always used for these three functions.
432 Also note that this directive will by default disable snapshots on
433 the following PFS's:
434 .Pa /tmp ,
435 .Pa /var/tmp
436 and
437 .Pa /usr/obj .
438 .Pp
439 The defaults may be adjusted by modifying the configuration file.
440 The pruning and reblocking commands automatically maintain a cyclefile
441 for incremental operation.
442 If you interrupt (^C) the program the cyclefile will be updated,
443 but a sub-command
444 may continue to run in the background for a few seconds until the
445 .Nm HAMMER
446 ioctl detects the interrupt.
447 The
448 .Cm snapshots
449 PFS option can be set to use another location for the snapshots directory.
450 .Pp
451 Work on this command is still in progress.
452 Expected additions:
453 An ability to remove snapshots dynamically as the
454 file system becomes full.
455 .\" ==== config ====
456 .It Cm config Op Ar filesystem Op Ar configfile
457 .Nm ( HAMMER
458 VERSION 3+)
459 If zero or one arguments are specified this function dumps the current
460 configuration file to stdout.
461 Zero arguments specifies the PFS containing the current directory.
462 This configuration file is stored in file system meta-data.
463 If two arguments are specified this function installs a new config file.
464 .Pp
465 In
466 .Nm HAMMER
467 versions less than 3 the configuration file is by default stored in
468 .Pa <pfs>/snapshots/config ,
469 but in all later versions the configuration file is stored in file system
470 meta-data.
471 .\" ==== viconfig ====
472 .It Cm viconfig Op Ar filesystem
473 .Nm ( HAMMER
474 VERSION 3+)
475 Edit the configuration file and reinstall into file system meta-data when done.
476 Zero arguments specifies the PFS containing the current directory.
477 .\" ==== expand ====
478 .It Cm expand Ar filesystem Ar device
479 This command will format
480 .Ar device
481 and add all of its space to
482 .Ar filesystem .
483 .Pp
484 .Em NOTE!
485 All existing data contained on
486 .Ar device
487 will be destroyed by this operation!
488 If
489 .Ar device
490 contains a valid
491 .Nm HAMMER
492 file system, formatting will be denied.
493 You can overcome this sanity check
494 by using
495 .Xr dd 1
496 to erase the beginning sectors of the device.
497 Also remember that you have to specify
498 .Ar device ,
499 together with any other device that make up the file system,
500 colon-separated to
501 .Pa /etc/fstab
502 and
503 .Xr mount_hammer 8 .
504 .\" ==== snapshot ====
505 .It Cm snapshot Oo Ar filesystem Oc Ar snapshot-dir
506 .It Cm snapshot Ar filesystem Ar snapshot-dir Op Ar note
507 Takes a snapshot of the file system either explicitly given by
508 .Ar filesystem
509 or implicitly derived from the
510 .Ar snapshot-dir
511 argument and creates a symlink in the directory provided by
512 .Ar snapshot-dir
513 pointing to the snapshot.
514 If
515 .Ar snapshot-dir
516 is not a directory, it is assumed to be a format string passed to
517 .Xr strftime 3
518 with the current time as parameter.
519 If
520 .Ar snapshot-dir
521 refers to an existing directory, a default format string of
522 .Ql snap-%Y%d%m-%H%M
523 is assumed and used as name for the newly created symlink.
524 .Pp
525 Snapshot is a per PFS operation, so a
526 .Nm HAMMER
527 file system and each PFS in it have to be snapshot separately.
528 .Pp
529 Example, assuming that
530 .Pa /mysnapshots
531 is on file system
532 .Pa /
533 and that
534 .Pa /obj
535 and
536 .Pa /usr
537 are file systems on their own, the following invocations:
538 .Bd -literal -offset indent
539 hammer snapshot /mysnapshots
540
541 hammer snapshot /mysnapshots/%Y-%m-%d
542
543 hammer snapshot /obj /mysnapshots/obj-%Y-%m-%d
544
545 hammer snapshot /usr /my/snaps/usr "note"
546 .Ed
547 .Pp
548 Would create symlinks similar to:
549 .Bd -literal -offset indent
550 /mysnapshots/snap-20080627-1210 -> /@@0x10d2cd05b7270d16
551
552 /mysnapshots/2008-06-27 -> /@@0x10d2cd05b7270d16
553
554 /mysnapshots/obj-2008-06-27 -> /obj@@0x10d2cd05b7270d16
555
556 /my/snaps/usr/snap-20080627-1210 -> /usr@@0x10d2cd05b7270d16
557 .Ed
558 .Pp
559 When run on a
560 .Nm HAMMER
561 version 3+ file system the snapshot is also recorded in file system meta-data
562 along with the optional
563 .Ar note .
564 See the
565 .Cm snapls
566 directive.
567 .\" ==== snap* ====
568 .It Cm snap Ar path Op Ar note
569 .Nm ( HAMMER
570 VERSION 3+)
571 Create a snapshot for the PFS containing
572 .Ar path
573 and create a snapshot softlink.
574 If the path specified is a
575 directory a standard snapshot softlink will be created in the directory.
576 The snapshot softlink points to the base of the mounted PFS.
577 .It Cm snaplo Ar path Op Ar note
578 .Nm ( HAMMER
579 VERSION 3+)
580 Create a snapshot for the PFS containing
581 .Ar path
582 and create a snapshot softlink.
583 If the path specified is a
584 directory a standard snapshot softlink will be created in the directory.
585 The snapshot softlink points into the directory it is contained in.
586 .It Cm snapq Ar dir Op Ar note
587 .Nm ( HAMMER
588 VERSION 3+)
589 Create a snapshot for the PFS containing the specified directory but do
590 not create a softlink.
591 Instead output a path which can be used to access
592 the directory via the snapshot.
593 .Pp
594 An absolute or relative path may be specified.
595 The path will be used as-is as a prefix in the path output to stdout.
596 As with the other
597 snap and snapshot directives the snapshot transaction id will be registered
598 in the file system meta-data.
599 .It Cm snaprm Bro Ar path | transid Brc Ar ...
600 .Nm ( HAMMER
601 VERSION 3+)
602 Remove a snapshot given its softlink or transaction id.
603 If specifying a transaction id
604 the snapshot is removed from file system meta-data but you are responsible
605 for removing any related softlinks.
606 .It Cm snapls Op Ar path ...
607 .Nm ( HAMMER
608 VERSION 3+)
609 Dump the snapshot meta-data for PFSs containing each
610 .Ar path
611 listing all available snapshots and their notes.
612 If no arguments are specified snapshots for the PFS containing the
613 current directory are listed.
614 This is the definitive list of snapshots for the file system.
615 .\" ==== prune ====
616 .It Cm prune Ar softlink-dir
617 Prune the file system based on previously created snapshot softlinks.
618 Pruning is the act of deleting file system history.
619 The
620 .Cm prune
621 command will delete file system history such that
622 the file system state is retained for the given snapshots,
623 and all history after the latest snapshot.
624 By setting the per PFS parameter
625 .Cm prune-min ,
626 history is guaranteed to be saved at least this time interval.
627 All other history is deleted.
628 .Pp
629 The target directory is expected to contain softlinks pointing to
630 snapshots of the file systems you wish to retain.
631 The directory is scanned non-recursively and the mount points and
632 transaction ids stored in the softlinks are extracted and sorted.
633 The file system is then explicitly pruned according to what is found.
634 Cleaning out portions of the file system is as simple as removing a
635 snapshot softlink and then running the
636 .Cm prune
637 command.
638 .Pp
639 As a safety measure pruning only occurs if one or more softlinks are found
640 containing the
641 .Ql @@
642 snapshot id extension.
643 Currently the scanned softlink directory must contain softlinks pointing
644 to a single
645 .Nm HAMMER
646 mount.
647 The softlinks may specify absolute or relative paths.
648 Softlinks must use 20-character
649 .Ql @@0x%016llx
650 transaction ids, as might be returned from
651 .Nm Cm synctid Ar filesystem .
652 .Pp
653 Pruning is a per PFS operation, so a
654 .Nm HAMMER
655 file system and each PFS in it have to be pruned separately.
656 .Pp
657 Note that pruning a file system may not immediately free-up space,
658 though typically some space will be freed if a large number of records are
659 pruned out.
660 The file system must be reblocked to completely recover all available space.
661 .Pp
662 Example, lets say your that you didn't set
663 .Cm prune-min ,
664 and snapshot directory contains the following links:
665 .Bd -literal -offset indent
666 lrwxr-xr-x  1 root  wheel  29 May 31 17:57 snap1 ->
667 /usr/obj/@@0x10d2cd05b7270d16
668
669 lrwxr-xr-x  1 root  wheel  29 May 31 17:58 snap2 ->
670 /usr/obj/@@0x10d2cd13f3fde98f
671
672 lrwxr-xr-x  1 root  wheel  29 May 31 17:59 snap3 ->
673 /usr/obj/@@0x10d2cd222adee364
674 .Ed
675 .Pp
676 If you were to run the
677 .Cm prune
678 command on this directory, then the
679 .Nm HAMMER
680 .Pa /usr/obj
681 mount will be pruned to retain the above three snapshots.
682 In addition, history for modifications made to the file system older than
683 the oldest snapshot will be destroyed and history for potentially fine-grained
684 modifications made to the file system more recently than the most recent
685 snapshot will be retained.
686 .Pp
687 If you then delete the
688 .Pa snap2
689 softlink and rerun the
690 .Cm prune
691 command,
692 history for modifications pertaining to that snapshot would be destroyed.
693 .Pp
694 In
695 .Nm HAMMER
696 file system versions 3+ this command also scans the snapshots stored
697 in the file system meta-data and includes them in the prune.
698 .\" ==== prune-everything ====
699 .It Cm prune-everything Ar filesystem
700 This command will remove all historical records from the file system.
701 This directive is not normally used on a production system.
702 .Pp
703 This command does not remove snapshot softlinks but will delete all
704 snapshots recorded in file system meta-data (for file system version 3+).
705 The user is responsible for deleting any softlinks.
706 .\" ==== rebalance ====
707 .It Cm rebalance Ar filesystem Op Ar saturation_percentage
708 This command will rebalance the B-tree, nodes with small number of
709 elements will be combined and element counts will be smoothed out
710 between nodes.
711 .Pp
712 The saturation percentage is between 50% and 100%.
713 The default is 75% (the
714 .Sq %
715 suffix is not needed).
716 .\" ==== reblock* ====
717 .It Cm reblock Ar filesystem Op Ar fill_percentage
718 .It Cm reblock-btree Ar filesystem Op Ar fill_percentage
719 .It Cm reblock-inodes Ar filesystem Op Ar fill_percentage
720 .It Cm reblock-dirs Ar filesystem Op Ar fill_percentage
721 .It Cm reblock-data Ar filesystem Op Ar fill_percentage
722 Attempt to defragment and free space for reuse by reblocking a live
723 .Nm HAMMER
724 file system.
725 Big-blocks cannot be reused by
726 .Nm HAMMER
727 until they are completely free.
728 This command also has the effect of reordering all elements, effectively
729 defragmenting the file system.
730 .Pp
731 The default fill percentage is 100% and will cause the file system to be
732 completely defragmented.
733 All specified element types will be reallocated and rewritten.
734 If you wish to quickly free up space instead try specifying
735 a smaller fill percentage, such as 90% or 80% (the
736 .Sq %
737 suffix is not needed).
738 .Pp
739 Since this command may rewrite the entire contents of the disk it is
740 best to do it incrementally from a
741 .Xr cron 8
742 job along with the
743 .Fl c Ar cyclefile
744 and
745 .Fl t Ar seconds
746 options to limit the run time.
747 The file system would thus be defragmented over long period of time.
748 .Pp
749 It is recommended that separate invocations be used for each data type.
750 B-tree nodes, inodes, and directories are typically the most important
751 elements needing defragmentation.
752 Data can be defragmented over a longer period of time.
753 .Pp
754 Reblocking is a per PFS operation, so a
755 .Nm HAMMER
756 file system and each PFS in it have to be reblocked separately.
757 .\" ==== pfs-status ====
758 .It Cm pfs-status Ar dirpath ...
759 Retrieve the mirroring configuration parameters for the specified
760 .Nm HAMMER
761 file systems or pseudo-filesystems (PFS's).
762 .\" ==== pfs-master ====
763 .It Cm pfs-master Ar dirpath Op Ar options
764 Create a pseudo-filesystem (PFS) inside a
765 .Nm HAMMER
766 file system.
767 Up to 65535 such file systems can be created.
768 Each PFS uses an independent inode numbering space making it suitable
769 for use as a replication source or target.
770 .Pp
771 The
772 .Cm pfs-master
773 directive creates a PFS that you can read, write, and use as a mirroring
774 source.
775 .Pp
776 It is recommended to use a
777 .Nm null
778 mount to access a PFS, for more information see
779 .Xr HAMMER 5 .
780 .\" ==== pfs-slave ====
781 .It Cm pfs-slave Ar dirpath Op Ar options
782 Create a pseudo-filesystem (PFS) inside a
783 .Nm HAMMER
784 file system.
785 Up to 65535 such file systems can be created.
786 Each PFS uses an independent inode numbering space making it suitable
787 for use as a replication source or target.
788 .Pp
789 The
790 .Cm pfs-slave
791 directive creates a PFS that you can use as a mirroring target.
792 You will not be able to access a slave PFS until you have completed the
793 first mirroring operation with it as the target (its root directory will
794 not exist until then).
795 .Pp
796 Access to the pfs-slave via the special softlink, as described in the
797 .Sx PFS NOTES
798 below, allows
799 .Nm HAMMER
800 to
801 dynamically modify the snapshot transaction id by returning a dynamic result
802 from
803 .Xr readlink 2
804 calls.
805 .Pp
806 A PFS can only be truly destroyed with the
807 .Cm pfs-destroy
808 directive.
809 Removing the softlink will not destroy the underlying PFS.
810 .Pp
811 It is recommended to use a
812 .Nm null
813 mount to access a PFS, for more information see
814 .Xr HAMMER 5 .
815 .\" ==== pfs-update ====
816 .It Cm pfs-update Ar dirpath Op Ar options
817 Update the configuration parameters for an existing
818 .Nm HAMMER
819 file system or pseudo-filesystem.
820 Options that may be specified:
821 .Bl -tag -width indent
822 .It Cm sync-beg-tid= Ns Ar 0x16llx
823 This is the automatic snapshot access starting transaction id for
824 mirroring slaves.
825 This parameter is normally updated automatically by the
826 .Cm mirror-write
827 directive.
828 .Pp
829 It is important to note that accessing a mirroring slave
830 with a transaction id greater than the last fully synchronized transaction
831 id can result in an unreliable snapshot since you will be accessing
832 data that is still undergoing synchronization.
833 .Pp
834 Manually modifying this field is dangerous and can result in a broken mirror.
835 .It Cm sync-end-tid= Ns Ar 0x16llx
836 This is the current synchronization point for mirroring slaves.
837 This parameter is normally updated automatically by the
838 .Cm mirror-write
839 directive.
840 .Pp
841 Manually modifying this field is dangerous and can result in a broken mirror.
842 .It Cm shared-uuid= Ns Ar uuid
843 Set the shared UUID for this file system.
844 All mirrors must have the same shared UUID.
845 For safety purposes the
846 .Cm mirror-write
847 directives will refuse to operate on a target with a different shared UUID.
848 .Pp
849 Changing the shared UUID on an existing, non-empty mirroring target,
850 including an empty but not completely pruned target,
851 can lead to corruption of the mirroring target.
852 .It Cm unique-uuid= Ns Ar uuid
853 Set the unique UUID for this file system.
854 This UUID should not be used anywhere else,
855 even on exact copies of the file system.
856 .It Cm label= Ns Ar string
857 Set a descriptive label for this file system.
858 .It Cm snapshots= Ns Ar string
859 Specify the snapshots directory which
860 .Nm
861 .Cm cleanup
862 will use to manage this PFS.
863 .Bl -tag -width indent
864 .It Nm HAMMER No version 2-
865 The snapshots directory does not need to be configured for
866 PFS masters and will default to
867 .Pa <pfs>/snapshots .
868 .Pp
869 PFS slaves are mirroring slaves so you cannot configure a snapshots
870 directory on the slave itself to be managed by the slave's machine.
871 In fact, the slave will likely have a
872 .Pa snapshots
873 sub-directory mirrored
874 from the master, but that directory contains the configuration the master
875 is using for its copy of the file system, not the configuration that we
876 want to use for our slave.
877 .Pp
878 It is recommended that
879 .Pa <fs>/var/slaves/<name>
880 be configured for a PFS slave, where
881 .Pa <fs>
882 is the base
883 .Nm HAMMER
884 file system, and
885 .Pa <name>
886 is an appropriate label.
887 .It Nm HAMMER No version 3+
888 The snapshots directory does not need to be configured for PFS masters or
889 slaves.
890 The snapshots directory defaults to
891 .Pa /var/hammer/<pfs>
892 .Pa ( /var/hammer/root
893 for root mount).
894 .El
895 .Pp
896 You can control snapshot retention on your slave independent of the master.
897 .It Cm snapshots-clear
898 Zero out the
899 .Cm snapshots
900 directory path for this PFS.
901 .It Cm prune-min= Ns Ar N Ns Cm d
902 .It Cm prune-min= Ns Oo Ar N Ns Cm d/ Oc Ns \
903 Ar hh Ns Op Cm \&: Ns Ar mm Ns Op Cm \&: Ns Ar ss
904 Set the minimum fine-grained data retention period.
905 .Nm HAMMER
906 always retains fine-grained history up to the most recent snapshot.
907 You can extend the retention period further by specifying a non-zero
908 pruning minimum.
909 Any snapshot softlinks within the retention period are ignored
910 for the purposes of pruning (the fine grained history is retained).
911 Number of days, hours, minutes and seconds are given as
912 .Ar N , hh , mm
913 and
914 .Ar ss .
915 .Pp
916 Because the transaction id in the snapshot softlink cannot be used
917 to calculate a timestamp,
918 .Nm HAMMER
919 uses the earlier of the
920 .Fa st_ctime
921 or
922 .Fa st_mtime
923 field of the softlink to
924 determine which snapshots fall within the retention period.
925 Users must be sure to retain one of these two fields when manipulating
926 the softlink.
927 .El
928 .\" ==== pfs-upgrade ====
929 .It Cm pfs-upgrade Ar dirpath
930 Upgrade a PFS from slave to master operation.
931 The PFS will be rolled back to the current end synchronization transaction id
932 (removing any partial synchronizations), and will then become writable.
933 .Pp
934 .Em WARNING!
935 .Nm HAMMER
936 currently supports only single masters and using
937 this command can easily result in file system corruption
938 if you don't know what you are doing.
939 .Pp
940 This directive will refuse to run if any programs have open descriptors
941 in the PFS, including programs chdir'd into the PFS.
942 .\" ==== pfs-downgrade ====
943 .It Cm pfs-downgrade Ar dirpath
944 Downgrade a master PFS from master to slave operation
945 The PFS becomes read-only and access will be locked to its
946 .Cm sync-end-tid .
947 .Pp
948 This directive will refuse to run if any programs have open descriptors
949 in the PFS, including programs chdir'd into the PFS.
950 .\" ==== pfs-destroy ====
951 .It Cm pfs-destroy Ar dirpath
952 This permanently destroys a PFS.
953 .Pp
954 This directive will refuse to run if any programs have open descriptors
955 in the PFS, including programs chdir'd into the PFS.
956 .\" ==== mirror-read ====
957 .It Cm mirror-read Ar filesystem Op Ar begin-tid
958 Generate a mirroring stream to stdout.
959 The stream ends when the transaction id space has been exhausted.
960 .\" ==== mirror-read-stream ====
961 .It Cm mirror-read-stream Ar filesystem Op Ar begin-tid
962 Generate a mirroring stream to stdout.
963 Upon completion the stream is paused until new data is synced to the
964 master, then resumed.
965 Operation continues until the pipe is broken.
966 .\" ==== mirror-write ====
967 .It Cm mirror-write Ar filesystem
968 Take a mirroring stream on stdin.
969 .Pp
970 This command will fail if the
971 .Cm shared-uuid
972 configuration field for the two file systems do not match.
973 .Pp
974 If the target PFS does not exist this command will ask you whether
975 you want to create a compatible PFS slave for the target or not.
976 .\" ==== mirror-dump ====
977 .It Cm mirror-dump
978 A
979 .Cm mirror-read
980 can be piped into a
981 .Cm mirror-dump
982 to dump an ASCII representation of the mirroring stream.
983 .\" ==== mirror-copy ====
984 .\".It Cm mirror-copy Ar [[user@]host:]filesystem [[user@]host:]filesystem
985 .It Cm mirror-copy \
986 Oo Oo Ar user Ns Cm @ Oc Ns Ar host Ns Cm \&: Oc Ns Ar filesystem \
987 Oo Oo Ar user Ns Cm @ Oc Ns Ar host Ns Cm \&: Oc Ns Ar filesystem
988 This is a shortcut which pipes a
989 .Cm mirror-read
990 command to a
991 .Cm mirror-write
992 command.
993 If a remote host specification is made the program forks a
994 .Xr ssh 1
995 and execs the
996 .Cm mirror-read
997 and/or
998 .Cm mirror-write
999 on the appropriate host.
1000 The source may be a master or slave PFS, and the target must be a slave PFS.
1001 .Pp
1002 This command also established full duplex communication and turns on
1003 the two-way protocol feature which automatically negotiates transaction id
1004 ranges without having to use a cyclefile.
1005 If the operation completes successfully the target PFS's
1006 .Cm sync-end-tid
1007 will be updated.
1008 Note that you must re-chdir into the target PFS to see the updated information.
1009 If you do not you will still be in the previous snapshot.
1010 .Pp
1011 If the target PFS does not exist this command will ask you whether
1012 you want to create a compatible PFS slave for the target or not.
1013 .\" ==== mirror-stream ====
1014 .\".It Cm mirror-stream Ar [[user@]host:]filesystem [[user@]host:]filesystem
1015 .It Cm mirror-stream \
1016 Oo Oo Ar user Ns Cm @ Oc Ns Ar host Ns Cm \&: Oc Ns Ar filesystem \
1017 Oo Oo Ar user Ns Cm @ Oc Ns Ar host Ns Cm \&: Oc Ns Ar filesystem
1018 This command works similarly to
1019 .Cm mirror-copy
1020 but does not exit after the initial mirroring completes.
1021 The mirroring operation will resume as changes continue to be made to the
1022 master.
1023 The command is commonly used with
1024 .Fl i Ar delay
1025 and
1026 .Fl b Ar bandwidth
1027 options to keep the mirroring target in sync with the source on a continuing
1028 basis.
1029 .Pp
1030 If the pipe is broken the command will automatically retry after sleeping
1031 for a short while.
1032 The time slept will be 15 seconds plus the time given in the
1033 .Fl i
1034 option.
1035 .Pp
1036 This command also detects the initial-mirroring case and spends some
1037 time scanning the B-Tree to find good break points, allowing the initial
1038 bulk mirroring operation to be broken down into about 20 separate pieces.
1039 This means that the user can kill and restart the operation and it will
1040 not have to start from scratch once it has gotten past the first chunk.
1041 The
1042 .Fl B
1043 option may be used to disable this feature and perform an initial bulk
1044 transfer instead.
1045 .\" ==== version ====
1046 .It Cm version Ar filesystem
1047 This command returns the
1048 .Nm HAMMER
1049 file system version for the specified
1050 .Ar filesystem
1051 as well as the range of versions supported in the kernel.
1052 The
1053 .Fl q
1054 option may be used to remove the summary at the end.
1055 .\" ==== version-upgrade ====
1056 .It Cm version-upgrade Ar filesystem Ar version Op Cm force
1057 This command upgrades the
1058 .Nm HAMMER
1059 .Ar filesystem
1060 to the specified
1061 .Ar version .
1062 Once upgraded a file system may not be downgraded.
1063 If you wish to upgrade a file system to a version greater or equal to the
1064 work-in-progress version number you must specify the
1065 .Cm force
1066 directive.
1067 Use of WIP versions should be relegated to testing and may require wiping
1068 the file system as development progresses, even though the WIP version might
1069 not change.
1070 .Pp
1071 .Em NOTE!
1072 This command operates on the entire
1073 .Nm HAMMER
1074 file system and is not a per PFS operation.
1075 All PFS's will be affected.
1076 .Bl -tag -width indent
1077 .It 1
1078 .Dx 2.0
1079 default version, first
1080 .Nm HAMMER
1081 release.
1082 .It 2
1083 .Dx 2.3 .
1084 New directory entry layout.
1085 This version is using a new directory hash key.
1086 .It 3
1087 .Dx 2.5
1088 default version.
1089 New snapshot management, using file system meta-data for saving
1090 configuration file and snapshots (transaction ids etc.).
1091 Also default snapshots directory has changed.
1092 .It 4
1093 .Dx 2.5 .
1094 New REDO, faster flush/sync.
1095 WIP.
1096 .El
1097 .El
1098 .\".Sh EXAMPLES
1099 .Sh PSEUDO-FILESYSTEM (PFS) NOTES
1100 The root of a PFS is not hooked into the primary
1101 .Nm HAMMER
1102 file system as a directory.
1103 Instead,
1104 .Nm HAMMER
1105 creates a special softlink called
1106 .Ql @@PFS%05d
1107 (exactly 10 characters long) in the primary
1108 .Nm HAMMER
1109 file system.
1110 .Nm HAMMER
1111 then modifies the contents of the softlink as read by
1112 .Xr readlink 2 ,
1113 and thus what you see with an
1114 .Nm ls
1115 command or if you were to
1116 .Nm cd
1117 into the link.
1118 If the PFS is a master the link reflects the current state of the PFS.
1119 If the PFS is a slave the link reflects the last completed snapshot, and the
1120 contents of the link will change when the next snapshot is completed, and
1121 so forth.
1122 .Pp
1123 The
1124 .Nm
1125 utility employs numerous safeties to reduce user foot-shooting.
1126 The
1127 .Cm mirror-copy
1128 directive requires that the target be configured as a slave and that the
1129 .Cm shared-uuid
1130 field of the mirroring source and target match.
1131 .Sh UPGRADE INSTRUCTIONS HAMMER V1 TO V2
1132 This upgrade changes the way directory entries are stored.
1133 It is possible to upgrade a V1 file system to V2 in place, but
1134 directories created prior to the upgrade will continue to use
1135 the old layout.
1136 .Pp
1137 Note that the slave mirroring code in the target kernel had bugs in
1138 V1 which can create an incompatible root directory on the slave.
1139 Do not mix a
1140 .Nm HAMMER
1141 master created after the upgrade with a
1142 .Nm HAMMER
1143 slave created prior to the upgrade.
1144 .Pp
1145 Any directories created after upgrading will use a new layout.
1146 .Sh UPGRADE INSTRUCTIONS HAMMER V2 TO V3
1147 This upgrade adds meta-data elements to the B-Tree.
1148 It is possible to upgrade a V2 file system to V3 in place.
1149 After issuing the upgrade be sure to run a
1150 .Nm
1151 .Cm cleanup
1152 to perform post-upgrade tasks.
1153 .Pp
1154 After making this upgrade running a
1155 .Nm
1156 .Cm cleanup
1157 will move the
1158 .Pa <pfs>/snapshots
1159 directory for each PFS mount into
1160 .Pa /var/hammer/<pfs> .
1161 A
1162 .Nm HAMMER
1163 root mount will migrate
1164 .Pa /snapshots
1165 into
1166 .Pa /var/hammer/root .
1167 Migration occurs only once and only if you have not specified
1168 a snapshots directory in the PFS configuration.
1169 If you have specified a snapshots directory in the PFS configuration no
1170 automatic migration will occur.
1171 .Pp
1172 For slaves, if you desire, you can migrate your snapshots
1173 config to the new location manually and then clear the
1174 snapshot directory configuration in the slave PFS.
1175 The new snapshots hierarchy is designed to work with
1176 both master and slave PFSs equally well.
1177 .Pp
1178 In addition, the old config file will be moved to file system meta-data,
1179 editable via the new
1180 .Nm
1181 .Cm viconfig
1182 directive.
1183 The old config file will be deleted.
1184 Migration occurs only once.
1185 .Pp
1186 The V3 file system has new
1187 .Cm snap*
1188 directives for creating snapshots.
1189 All snapshot directives, including the original, will create
1190 meta-data entries for the snapshots and the pruning code will
1191 automatically incorporate these entries into its list and
1192 expire them the same way it expires softlinks.
1193 If you by accident blow away your snapshot softlinks you can use the
1194 .Cm snapls
1195 directive to get a definitive list from the file system meta-data and
1196 regenerate them from that list.
1197 .Pp
1198 .Em WARNING!
1199 If you are using
1200 .Nm
1201 to backup file systems your scripts may be using the
1202 .Cm synctid
1203 directive to generate transaction ids.
1204 This directive does not create a snapshot.
1205 You will have to modify your scripts to use the
1206 .Cm snapq
1207 directive to generate the linkbuf for the softlink you create, or
1208 use one of the other
1209 .Cm snap*
1210 directives.
1211 The older
1212 .Cm snapshot
1213 directive will continue to work as expected and in V3 it will also
1214 record the snapshot transaction id in file system meta-data.
1215 You may also want to make use of the new
1216 .Ar note
1217 tag for the meta-data.
1218 .Pp
1219 .Em WARNING!
1220 If you used to remove snapshot softlinks with
1221 .Nm rm
1222 you should probably start using the
1223 .Cm snaprm
1224 directive instead to also remove the related meta-data.
1225 The pruning code scans the meta-data so just removing the
1226 softlink is not sufficient.
1227 .Sh EXIT STATUS
1228 .Ex -std
1229 .Sh FILES
1230 .Bl -tag -width ".It Pa <fs>/var/slaves/<name>" -compact
1231 .It Pa <pfs>/snapshots
1232 default per PFS snapshots directory
1233 .Nm ( HAMMER
1234 VERSION 2-)
1235 .It Pa /var/hammer/<pfs>
1236 default per PFS snapshots directory (not root)
1237 .Nm ( HAMMER
1238 VERSION 3+)
1239 .It Pa /var/hammer/root
1240 default snapshots directory for root directory
1241 .Nm ( HAMMER
1242 VERSION 3+)
1243 .It Pa <snapshots>/config
1244 per PFS
1245 .Nm
1246 .Cm cleanup
1247 configuration file
1248 .Nm ( HAMMER
1249 VERSION 2-)
1250 .It Pa <fs>/var/slaves/<name>
1251 recommended slave PFS snapshots directory
1252 .Nm ( HAMMER
1253 VERSION 2-)
1254 .El
1255 .Sh SEE ALSO
1256 .Xr ssh 1 ,
1257 .Xr undo 1 ,
1258 .Xr HAMMER 5 ,
1259 .Xr periodic.conf 5 ,
1260 .Xr mount_hammer 8 ,
1261 .Xr mount_null 8 ,
1262 .Xr newfs_hammer 8
1263 .Sh HISTORY
1264 The
1265 .Nm
1266 utility first appeared in
1267 .Dx 1.11 .
1268 .Sh AUTHORS
1269 .An Matthew Dillon Aq dillon@backplane.com