Minor grammar/typographic cleanups; attempt to add a "subtle" reminder that pfs/...
[ikiwiki.git] / docs / how_to_implement_hammer_pseudo_file_system__40___pfs___41___slave_mirroring_from_pfs_master / index.mdwn
1 [[!toc]]
2 #Scenario
3 I have two 500 GB hard disks both with the Hammer file system. I want to create a master PFS in one hard disk and a slave PFS in the other disk. I want to mirror the data continuously from the master PFS to the slave PFS. This will help me avoid long 'fsck' and RAID parity rewrite times after an unclean shut down, and also will give me a setup somewhat like RAID 1.
4
5 #Creating the master PFS on Disk 1
6
7 The Hammer file systems on Disk 1 and Disk 2 are mounted in '/etc/fstab' according to the following.
8
9     /dev/ad4s1h             /Backup1        hammer  rw              2       2
10     /dev/ad6s1h             /Backup2        hammer  rw              2       2
11
12 Go to the Hammer file system on Disk 1. We will be creaing a master PFS called 'test' and will be mounting it using a null mount. If you don't have a directory called 'pfs' under the Hammer file system you should create it.
13
14     # pwd
15     /Backup1
16     # mkdir pfs
17
18 If you already have the pfs directory under the Hammer file system you can skip the above step and continue.
19
20     # hammer pfs-master /Backup1/pfs/test
21     Creating PFS #3 succeeded!
22     /Backup1/pfs/test
23     sync-beg-tid=0x0000000000000001
24     sync-end-tid=0x000000013f644ce0
25     shared-uuid=9043570e-b3d9-11de-9bef-011617202aa6
26     unique-uuid=9043574c-b3d9-11de-9bef-011617202aa6
27     label=""
28     prune-min=00:00:00
29     operating as a MASTER
30     snapshots dir for master defaults to <fs>/snapshots
31
32     
33 Now the master PFS 'test' is created. Make a note of its 'shared-uuid' because we will need to use that to create the slave PFS for mirroring.
34 You can mount the PFS under the Hammer file system on Disk 1 by doing the following.
35
36     # mkdir /Backup1/test
37
38 Now Edit '/etc/fstab' to contain the following line.
39
40     /Backup1/pfs/test      /Backup1/test    null    rw              0       0
41
42 Now mount the PFS by doing.
43
44     # mount -a
45     # mount |grep test
46     /Backup1/pfs/@@-1:00003 on /Backup1/test (null, local)
47
48 #Creating the slave PFS on Disk 2. 
49
50 Note that we must use the 'shared-uuid' of the master PFS to enable mirroring.
51     
52     # hammer pfs-slave /Backup2/pfs/test shared-uuid=9043570e-b3d9-11de-9bef-011617202aa6
53     Creating PFS #3 succeeded!
54     /Backup2/pfs/test
55     sync-beg-tid=0x0000000000000001
56     sync-end-tid=0x0000000000000001
57     shared-uuid=9043570e-b3d9-11de-9bef-011617202aa6
58     unique-uuid=97d77f53-b3da-11de-9bef-011617202aa6
59     slave
60     label=""
61     prune-min=00:00:00
62     operating as a SLAVE
63     snapshots directory not set for slave
64
65
66 The slave PFS is not mounted but a symlink can be created in the root Hammer file system to point to it.  This step is optional, the PFS can be read through its original magic symlink in /Backup2/pfs.
67
68     # ln -s /Backup2/pfs/test /Backup2/test
69     # ls -l /Backup2/test
70     lrwxr-xr-x  1 root  wheel  17 Oct  8 12:07 /Backup2/test -> /Backup2/pfs/test
71
72 #Copying contents from PFS on Disk 1 to PFS on Disk 2 to enable mirroring. 
73
74 The slave PFS will be accessible only after the first 'mirror-copy' operation.
75
76     # touch /Backup1/test/test-file
77     # ls /Backup1/test/
78     test-file
79     # sync
80
81 We do the "sync" so that the file creation operation in flushed from the kernel memory. Mirroring works only on operations flushed from the kernel memory. The slave PFS will be accessible only after the first mirroring operation.
82
83     # hammer mirror-copy /Backup1/test /Backup2/pfs/test
84     histogram range 000000013f6425fd - 000000013f644d60
85     Mirror-read: Mirror from 0000000000000002 to 000000013f644d60
86     Mirror-read /Backup1/test succeeded
87
88     # ls /Backup2/test/
89     test-file
90
91 #Enabling continuous mirroring.
92
93 You can enable continuous mirroring by editing a few files.
94 One way to make sure the mirroring works continuously is to use the 'lockf' utility.
95 This is one way to do it.
96
97     # mkdir /root/adm && cd /root/adm
98     # touch .lockfile
99
100 Now make two scripts 'hms' and 'hmc' with the following contents inside /root/adm
101
102     # cat hms
103     hammer mirror-stream /Backup1/test /Backup2/test &
104
105     # cat hmc
106     hammer synctid /Backup1/test
107     hammer mirror-copy /Backup1/test /Backup2/test 
108
109 Edit '/etc/rc.local' and add the following line.
110
111     (cd /root/adm; /usr/bin/lockf -k -t 0 .lockfile ./hms) &
112
113 Edit 'crontab' and add the following Lines.
114
115     #Check and restart mirroring if needed every 10 minutes
116     10 1 * * * (cd /root/adm; /usr/bin/lockf -k -t 0 .lockfile ./hms) &
117
118 Edit '/etc/rc.shutdown.local' and add the following lines.
119
120     pkill -f /usr/bin/lockf -k -t 0 .lockfile ./hms
121     pkill -f hammer mirror-stream /Backup1/test /Backup2/test
122     (cd /root/adm; /usr/bin/lockf -k -t 10 .lockfile ./hmc)