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