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