rfreezefs.8: Fix some misformatting and other minor bogosity.
[rsync-backup] / rfreezefs.8
CommitLineData
f6b4ffdc
MW
1.TH rfreezefs 8 "October 2011" "rsync-backup"
2.SH NAME
3rfreezefs \- freeze a filesystem safely
4.SH SYNOPSIS
5.B rfreezefs
6.RB [ \-n ]
7.RB [ \-a
8.IR address ]
9.RB [ \-p
10.IR loport [\fB\- hiport ]]
11.I filesystem
12\&...
13.SH DESCRIPTION
14The
15.B rfreezefs
16program freezes one or more mounted filesystems for a period of time,
17and then thaws them. For more detail on what this means, why you'd want
18to, and how you might go about using
19.B rfreezefs
20to do it, see below.
21.PP
22The following command-line options are recognized.
23.TP
24.B "\-h, \-\-help"
25Writes a help message to standard output, and exits with status 0.
26.TP
27.B "\-v, \-\-version"
28Writes the version number to standard output, and exits with status 0.
29.TP
30.B "\-u, \-\-usage"
31Writes a command-line usage synopsis to standard output, and exits with
32status 0.
33.TP
34.BI "\-a, \-\-address=" address
35Listen only for incoming connections to the given
36.IR address .
37The default is to listen for connections to any local address.
38.TP
39.B "\-n, \-\-not-really"
40Don't actually freeze or thaw any filesystems; instead, write messages
41to standard error explaining what would be done.
42.TP
43.BI "\-p, \-\-port-range=" loport\fR[ \- hiport \fR]]
44Listen for incoming connections on a port between
45.I loport
46and
47.IR hiport .
48If
49.I hiport
50is omitted, listen for connections only on
51.IR loport .
52The default is to allow the kernel a free choice of local port number.
53.PP
54The
55.I filesystem
56arguments name the filesystems to be frozen. There must be at least one
57such argument. It's conventional to name the filesystem mount points,
58though actually any file or directory in the filesystem will do. The
59files are opened read-only.
60.PP
61The
62.B rfreezefs
63program starts, parses its command line, opens the named files, and
64creates a listening TCP socket according to the command-line options.
65It then prints a sequence of lines to standard output, which may have
66one of the following forms.
67.TP
68.BI "PORT " port
69Announces the TCP
70.I port
71number on which that
72.B rfreezefs
73is listening for incoming connections.
74.TP
75.BI "TOKEN " label " " token
76Declares a `token': a randomly chosen string which is to be used in the
77network connection. The token's value is
78.IR token :
79token values are a sequence of non-whitespace printable ASCII
80characters, but their precise structure is not specified. The token
81value will have the meaning given by the
82.IR label ,
83which is one of the token labels described below.
84.TP
85.B READY
86Marks the end of the lines and announces that
87.B rfreezefs
88is ready to accept connections.
89.PP
90These lines may be sent in any order, except that
91.B READY
92is always last. There may be many
93.B TOKEN
94lines.
95.PP
96Network communications use a simple plain-text line-oriented protocol.
97Each line consists of a token, optionally followed by a carriage return
98(code 13), followed by a linefeed (code 10). No other whitespace is
99permitted. The tokens allowed are precisely those announced in the
100.B TOKEN
101lines written to
102.BR rfreezefs 's
103standard output. Furthermore, only certain tokens are valid at
104particular points in the protocol. For reference, the token labels, and
105the meanings of the corresponding tokens, are as follows.
106.TP
107.B FREEZE
108Sent by a client to freeze the filesystems. This must be the first
109token transmitted by the client. On receipt,
110.B rfreezefs
111will close its listening socket and any other client connections. It
112will then freeze the filesystems.
113.TP
114.B FROZEN
115Sent by
116.B rfreezefs
117to indicate successful freezing of the filesystem.
118.TP
119.B KEEPALIVE
120Sent periodically by the client to prevent filesystems being thawed due
121to a timeout. No explicit acknowledgement is sent.
122.TP
123.B THAW
124Sent by the client to request thawing of the filesystems.
125.TP
126.B THAWED
127Sent by
939429c0
MW
128.B rfreezefs
129to indicate successful thawing of the filesystems in response to
f6b4ffdc
MW
130.BR THAW .
131.PP
132The high-level structure of the protocol is then as follows: the client
133sends
134.BR FREEZE ;
135the server freezes and responds with
136.BR FROZEN ;
137the client optionally sends
138.B KEEPALIVE
139at intervals; the client finally sends
140.BR THAW ;
141and the server responds with
142.B THAWED
143and drops the connection.
144.PP
145If sufficient time passes without
146.B rfreezefs
147receiving either
148.B THAW
149or
150.B KEEPALIVE
151tokens, or an invalid token is received, or it receives one of a number
939429c0 152of signals \(en currently
f6b4ffdc
MW
153.BR SIGINT ,
154.BR SIGQUIT ,
155.BR SIGTERM ,
156.BR SIGHUP ,
157.BR SIGALRM ,
158.BR SIGILL ,
159.BR SIGSEGV ,
160.BR SIGBUS ,
161.BR SIGFPE ,
162or
939429c0
MW
163.B SIGABRT
164\(en then
f6b4ffdc
MW
165.B rfreezefs
166will thaw the filesystems and report a failure.
167.PP
168Diagnostics are reported to standard error. Exit statuses have specific
169meanings:
170.TP
171.B 0
172Successful completion. Filesystems were frozen and thawed as required.
173.TP
174.B 1
175Problem with command-line arguments. No filesystems were frozen.
176.TP
177.B 2
178Environmental problem, typically a system call failure: e.g., a file
179failed to open, or there was a problem with the network communications.
180Either no filesystems were frozen, or all filesystems were successfully
181thawed again.
182.TP
183.B 3
184Timeout or invalid data. Either no connections containing the cookie
185were made in time, or no data was received for a long enough period
186after the filesystems were frozen, or an invalid token was received. In
187the first case, no filesystems were frozen; in the other two cases, the
188filesystems were successfully thawed.
189.TP
190.B 4
191Crash. The
192.B rfreezefs
193program received a fatal signal after it had started to freeze
194filesystems. Under these circumstances, it thaws the filesystems,
195removes the signal handler, and sends itself the signal again, but if
196that doesn't work then
197.B rfreezefs
198exits with this status code. All frozen filesystems were successfully
199thawed again.
200.TP
201.B 112
202Failure during filesystem thaw (mnemonic: European emergency number).
203Some filesystems
204.I failed
205to thaw, and are still frozen. You might have some joy with
206.BR SysRq-j ,
207though in the author's experience that doesn't work and you'll probably
208have to reboot. At least your filesystems are consistent...
209.SS Background
210When frozen, a filesystem's backing block device is put in a consistent
211state (as if unmounted), and write operations to it are delayed until
212the filesystem is thawed again. In the meantime, it's possible to take
213a consistent snapshot of the block device. When a filesystem is
214directly mounted on an LVM logical volume, the kernel detects this
215situation and automatically freezes the filesystem while the snapshot is
216being prepared. If the logical volume and filesystem are on separate
217hosts, though, the filesystem must be frozen manually, which is why
218.B rfreezefs
219is useful.
220.PP
221The idea is to run
222.B rfreezefs
223using
224.BR ssh (1)
225or
226.BR userv (1),
227or some other means of acquiring the necessary privilege level. You
228read the port number and tokens, connect to the socket, and send the
229.B FREEZE
230token followed by a newline. You now wait to receive the
231.B FROZEN
232token from
233.BR rfreezefs .
234Once you have received this, the filesystems are frozen: you can safely
235take snapshots. If this will take an extended amount of time, you
236should send
237.B KEEPALIVE
238tokens to the connection at intervals in order to prevent
239.B rfreezefs
240from timing out and thawing the filesystems (but see the
241.B "Security notes"
242below). When your snapshot is prepared, sent the
243.B THAW
244token, and wait for the
245.B THAWED
246token in response. If this is received, the snapshot was completed
247successfully and the filesystems are properly thawed again. If you
248don't receive the
249.B THAWED
250token then something bad might have happened (e.g., the filesystem might
251have been prematurely thawed) and the snapshot is suspect. If the exit
252status is 112 then at least one filesystem is still frozen and some
253emergency action is needed. If you can't retrieve the exit status then
254it's possible that your transport is blocked for trying to write to the
255frozen filesystem (this especially likely if
256.B /
257or
258.B /var
259is frozen) and you should react as if the status was 112.
260.SS Security notes
261The
262.B rfreezefs
263program uses randomly chosen tokens to form a simple code which is
264revealed to the caller. It is assumed that this information is kept
265secret from adversaries, e.g., by ensuring that it is only transmitted
266over local pipes (as used by
267.BR userv (1))
268and/or secure network transports such as SSH (see
269.BR ssh (1)).
270The author believes that the worst possible outcome is that the host
271wedges up because an important filesystem is frozen, and
272.B rfreezefs
273therefore strives to prevent that from happening. In particular,
274cryptographic transport implementations such as SSH may attempt to log
275messages to frozen filesystems or otherwise wedge themselves:
276.B rfreezefs
277deliberately uses only kernel-implemented transports for its
278communication needs once the filesystems are frozen.
279.PP
280Most of the tokens are used at most once in the protocol. In
281particular, the
282.B FROZEN
283token can't be sent by an adversary in advance of the filesystem being
284frozen, since (under the assumption that the tokens are kept secret) it
285only revealed in the clear after a successful freeze. Similarly, the
286.B THAWED
287token is only transmitted if the filesystems are thawed as a result of a
288.B THAW
289request (rather than a dropped connection, timeout, or some other
290problem). If the client only sends the
291.B THAW
292request once its snapshot is complete, then a
293.B THAWED
294response indicates that the filesystems remained frozen until the
295snapshot was indeed completed and therefore the snapshot is consistent.
296.PP
297The exception is the
298.B KEEPALIVE
299token, which may be sent repeatedly. After it is first revealed, an
300adversary can hijack the connection and replay the
301.B KEEPALIVE
302token to keep the filesystems frozen indefinitely. You can recover from
303this by severing the connection somehow, or by sending
304.B rfreezefs
305a signal. It is therefore recommended that
306.B KEEPALIVE
307tokens not be sent unless necessary. The timeout is currently set to
30860s, which ought to be adequate for most snapshot mechanisms.
309.SH BUGS
310There ought to be a better one-time-token protocol for keepalives. I
311want to keep cryptography out of this program, though.
312.SH SEE ALSO
313.BR fsfreeze (8),
314.BR random (4),
315.BR lvm (8),
316.BR ssh (1),
317.BR userv (1).
318.SH AUTHOR
319Mark Wooding, <mdw@distorted.org.uk>