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