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