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