fshash.1: Fix some stupid editorial errors.
[rsync-backup] / rsync-backup.8
CommitLineData
69305044
MW
1.ie t .ds o \(bu
2.el .ds o o
3.de hP
4.IP
5\h'-\w'\fB\\$1\ \fP'u'\fB\\$1\ \fP\c
6..
f6b4ffdc 7.TH rsync-backup 8 "7 October 2012" rsync-backup
977d0da9
MW
8.SH NAME
9rsync-backup \- back up files using rsync
f6b4ffdc
MW
10.SH SYNOPSIS
11.B rsync-backup
3f496b2b 12.RB [ \-nv ]
f6b4ffdc
MW
13.RB [ \-c
14.IR config-file ]
15.SH DESCRIPTION
16The
17.B rsync-backup
18script is a backup program of the currently popular
19.RB ` rsync (1)
20.BR \-\-link-dest '
21variety. It uses
22.BR rsync 's
23ability to create hardlinks from (apparently) similar existing local
24trees to make incremental dumps efficient, even from remote sources.
25Restoring files is easy because the backups created are just directories
26full of files, exactly as they were on the source \(en and this is
27verified using the
28.BR fshash (1)
29program.
30.PP
31The script does more than just running
32.BR rsync .
33It is also responsible for creating and removing snapshots of volumes to
34be backed up, and expiring old dumps according to a user-specified
35retention policy.
36.SS Installation
37The idea is that the
38.B rsync-backup
39script should be installed and run on a central backup server with local
40access to the backup volumes.
41.PP
42The script should be run with full (root) privileges, so that it can
43correctly record file ownership information. The server should also be
44able to connect via
45.BR ssh (1)
46to the client machines, and run processes there as root. (This is not a
47security disaster. Remember that the backup server is, in the end,
48responsible for the integrity of the backup data. A dishonest backup
49server can easily compromise a client which is being restored from
50corrupt backup data.)
69305044
MW
51.SS Command-line options
52Most of the behaviour of
53.B rsync-backup
54is controlled by a configuration file, described starting with the
55section named
56.B Configuration commands
57below.
58But a few features are controlled by command-line options.
59.TP
60.B \-h
61Show a brief help message for the program, and exit successfully.
62.TP
63.B \-V
64Show
65.BR rsync-backup 's
66version number and some choice pieces of build-time configuration, and
67exit successfully.
68.TP
69.BI "\-c " conf
70Read
71.I conf
72instead of the default configuration file (shown as
73.B conf
74in the
75.B \-V
76output).
77.TP
3f496b2b
MW
78.B \-n
79Don't actually take a backup, or write proper logs: instead, write a
80description of what would be done to standard error.
81.TP
69305044
MW
82.B \-v
83Produce verbose progress information on standard output while the backup
84is running. This keeps one amused while running a backup
85interactively. In any event,
86.B rsync-backup
87will report failures to standard error, and otherwise run silently, so
88it doesn't annoy unnecessarily if run by
89.BR cron (8).
90.SS Backup process
91Backing up a filesystem works as follows.
92.hP \*o
93Make a snapshot of the filesystem on the client, and ensure that the
94snapshot is mounted. There are some `trivial' snapshot types which use
95the existing mounted filesystem, and either prevent processes writing to
96it during the backup, or just hope for the best. Other snapshot types
97require the snapshot to be mounted somewhere distinct from the main
98filesystem, so that the latter can continue being used.
99.hP \*o
100Run
101.B rsync
102to copy the snapshot to the backup volume \(en specifically, to
103.IB host / fs / new \fR.
104If this directory already exists, then it's presumed to be debris from a
105previous attempt to dump this filesystem:
106.B rsync
107will update it appropriately, by adding, deleting or modifying the
108files. This means that retrying a failed dump \(en after fixing whatever
109caused it to go wrong, obviously! \(en is usually fairly quick.
110.hP \*o
111Run
112.B fshash
113on the client to generate a `digest' describing the contents of the
114filesystem, and send this to the server as
115.IB host / fs / new .fshash \fR.
116.hP \*o
117Release the snapshot: we don't need it any more.
118.hP \*o
119Run
120.B fshash
121over the new backup; specifically, to
122.BI tmp/fshash. host . fs . date \fR.
123This gives us a digest for what the backup volume actually stored.
124.hP \*o
125Compare the two
126.B fshash
127digests. If they differ then dump the differences to the log file and
128report a backup failure. (Backups aren't any good if they don't
129actually back up the right thing. And you stand a better chance of
130fixing them if you know that they're going wrong.)
131.hP \*o
132Commit the backup, by renaming the dump directory to
133.IB host / fs / date
134and the
135.B fshash
136digest file to
137.IB host / fs / date .fshash \fR.
f6b4ffdc 138.PP
69305044 139The backup is now complete.
f6b4ffdc
MW
140.SS Configuration commands
141The configuration file is simply a Bash shell fragment: configuration
142commands are shell functions.
143.TP
144.BI "backup " "fs\fR[:\fIfsarg\fR] ..."
145Back up the named filesystems. The corresponding
146.IR fsarg s
147may be required by the snapshot type.
148.TP
149.BI "host " host
150Future
151.B backup
152commands will back up filesystems on the named
153.IR host .
69305044
MW
154To back up filesystems on the backup server itself, use its hostname:
155.B rsync-backup
156will avoid inefficient and pointless messing about
157.BR ssh (1)
158in this case.
159This command clears the
f6b4ffdc 160.B like
f8d0b27d
MW
161list, and resets the retention policy to its default (i.e., the to
162policy defined prior to the first
163.B host
164command).
f6b4ffdc
MW
165.TP
166.BI "like " "host\fR ..."
167Declare that subsequent filesystems are `similar' to like-named
168filesystems on the named
169.IR host s,
170and that
171.B rsync
172should use those trees as potential sources of hardlinkable files. Be
173careful when using this option without
174.BR rsync 's
175.B \-\-checksum
176option: an erroneous hardlink will cause the backup to fail. (The
177backup won't be left silently incorrect.)
178.TP
179.BI "retain " frequency " " duration
180Define part a backup retention policy: backup trees of the
181.I frequency
182should be kept for the
183.IR duration .
184The
185.I frequency
186can be
187.BR daily ,
188.BR weekly ,
189.BR monthly ,
190or
69305044 191.B annually
f6b4ffdc
MW
192(or
193.BR yearly ,
194which means the same); the
195.I duration
196may be any of
197.BR week ,
198.BR month ,
199.BR year ,
200or
201.BR forever .
202Expiry considers each existing dump against the policy lines in order:
203the last applicable line determines the dump's fate \(en so you should
204probably write the lines in decreasing order of duration.
e69b31ea 205.RS
f8d0b27d
MW
206.PP
207Groups of
208.B retain
209commands between
210.B host
211and/or
212.B backup
213commands collectively define a retention policy. Once a policy is
214defined, subsequent
215.B backup
216operations use the policy. The first
217.B retain
218command after a
219.B host
220or
221.B backup
222command clears the policy and starts defining a new one. The policy
223defined before the first
224.B host
225is the
226.I default
227policy: at the start of each
228.B host
229stanza, the policy is reset to the default.
e69b31ea 230.RE
f6b4ffdc 231.TP
5675acda
MW
232.BI "retry " count
233The
234.B live
235snapshot type (see below) doesn't prevent a filesystem from being
236modified while it's being backed up. If this happens, the
237.B fshash
238pass will detect the difference and fail. If the filesystem in question
239is relatively quiescent, then maybe retrying the backup will result in a
240successful consistent copy. Following this command, a backup which
241results in an
242.B fshash
243mismatch will be retried up to
244.I count
245times before being declared a failure.
246.TP
f6b4ffdc
MW
247.BI "snap " type " " \fR[\fIargs\fR...]
248Use the snapshot
249.I type
250for subsequent backups. Some snapshot types require additional
5675acda
MW
251arguments, which may be supplied here. This command clears the
252.B retry
253counter.
f6b4ffdc
MW
254.SS Configuration variables
255The following shell variables may be overridden by the configuration
256file.
257.TP
8e40e6cf
MW
258.B HASH
259The hash function to use for verifying archive integrity. This is
260passed to the
261.B \-H
262option of
263.BR fshash ,
264so it must name one of the hash functions supported by your Python's
265.B hashlib
266module.
267The default is
268.BR sha256 .
269.TP
a8447303
MW
270.B INDEXDB
271The name of a SQLite database initialized by
272.BR update-bkp-index (8)
273in which an index is maintained of which dumps are on which backup
274volumes. If the file doesn't exist, then no index is maintained. The
275default is
276.IB localstatedir /lib/bkp/index.db
277where
278.I localstatedir
279is the state directory configured at build time.
280.TP
f6b4ffdc
MW
281.B MAXLOG
282The number of log files to be kept for each filesystem. Old logfiles
283are deleted to keep the total number below this bound. The default
284value is 14.
285.TP
a8447303
MW
286.B METADIR
287The metadata directory for the currently mounted backup volume.
288The default is
289.IB mntbkpdir /meta
290where
291.I mntbkpdir
292is the backup mount directory configured at build time.
293.TP
f6b4ffdc
MW
294.B RSYNCOPTS
295Command-line options to pass to
296.BR rsync (1)
297in addition to the basic set:
69305044
MW
298.B \-\-archive
299.B \-\-hard-links
300.B \-\-numeric-ids
301.B \-\-del
302.B \-\-sparse
303.B \-\-compress
304.B \-\-one-file-system
305.B \-\-partial
306.BR "\-\-filter=""dir-merge .rsync-backup""" .
f6b4ffdc
MW
307The default is
308.BR \-\-verbose .
309.TP
310.B SNAPDIR
311LVM (and
312.BR rfreezefs )
313snapshots are mounted on subdirectories below the
314.B SNAPDIR
315.IR "on backup clients" .
316The default is
317.IB mntbkpdir /snap
318where
319.I mntbkpdir
320is the backup mount directory configured at build time.
321.TP
322.B SNAPSIZE
323The volume size option to pass to
324.BR lvcreate (8)
325when creating a snapshot. The default is
326.B \-l10%ORIGIN
327which seems to work fairly well.
328.TP
329.B STOREDIR
330Where the actual backup trees should be stored. See the section on
331.B Archive structure
332below.
333The default is
334.IB mntbkpdir /store
335where
336.I mntbkpdir
337is the backup mount directory configured at build time.
338.TP
a8447303
MW
339.B VOLUME
340The name of the current volume. If this is left unset, the volume name
341is read from the file
342.IB METADIR /volume
343once at the start of the backup run.
f6b4ffdc
MW
344.SS Hook functions
345The configuration file may define shell functions to perform custom
346actions at various points in the backup process.
347.TP
348.BI "backup_precommit_hook " host " " fs " " date
349Called after a backup has been verified complete and about to be
350committed. The backup tree is in
351.B new
352in the current directory, and the
353.B fshash
354manifest is in
355.BR new.fshash .
356A typical action would be to create a digital signature on the
357manifest.
358.TP
359.BI "backup_commit_hook " host " " fs " " date
360Called during the commit procedure. The backup tree and manifest have
361been renamed into their proper places. Typically one would use this
362hook to rename files created by the
363.B backup_precommit_hook
364function.
365.TP
366.BR "whine " [ \-n ] " " \fItext\fR...
367Called to report `interesting' events when the
368.B \-v
369option is in force. The default action is to echo the
370.I text
371to (what was initially) standard output, followed by a newline unless
372.B \-n
373is given.
374.SS Snapshot types
375The following snapshot types are available.
376.TP
377.B live
378A trivial snapshot type: attempts to back up a live filesystem. How
379well this works depends on how active the filesystem is. If files
380change while the dump is in progress then the
381.B fshash
382verification will likely fail. Backups using this snapshot type must
383specify the filesystem mount point as the
384.IR fsarg .
385.TP
386.B ro
387A slightly less trivial snapshot type: make the filesystem read-only
388while the dump is in progress. Backups using this snapshot type must
389specify the filesystem mount point as the
390.IR fsarg .
391.TP
392.BI "lvm " vg
393Create snapshots using LVM. The snapshot argument is interpreted as the
394relevant volume group. The filesystem name is interpreted as the origin
395volume name; the snapshot will be called
396.IB fs .bkp
397and mounted on
398.IB SNAPDIR / fs \fR;
399space will be allocated to it according to the
400.I SNAPSIZE
401variable.
402.TP
403.BI "rfreezefs " client " " vg
404This gets complicated. Suppose that a server has an LVM volume group,
405and exports (somehow) a logical volume to a client. Examples are a host
406providing a virtual disk to a guest, or a server providing
407network-attached storage to a client. The server can create a snapshot
408of the volume using LVM, but must synchronize with the client to ensure
409that the filesystem image captured in the snapshot is clean. The
410.BR rfreezefs (8)
411program should be installed on the client to perform this rather
412delicate synchronization. Declare the server using the
413.B host
414command as usual; pass the client's name as the
415.I client
416and the
417server's volume group name as the
418.I vg
419snapshot arguments. Finally, backups using this snapshot type must
420specify the filesystem mount point (or, actually, any file in the
421filesystem) on the client, as the
422.IR fsarg .
423.PP
424Additional snapshot types can be defined in the configuration file. A
425snapshot type requires two shell functions.
426.TP
427.BI snap_ type " " snapargs " " fs " " fsarg
428Create the snapshot, and write the mountpoint (on the client host) to
429standard output, in a form suitable as an argument to
430.BR rsync .
431.TP
432.BI unsnap_ type " " snapargs " " fs " " fsarg
433Remove the snapshot.
434.PP
435There are a number of utility functions which can be used by snapshot
436type handlers: please see the script for details. Please send the
437author interesting snapshot handlers for inclusion in the main
438distribution.
439.SS Archive structure
69305044
MW
440Backup trees are stored in a fairly straightforward directory tree.
441.PP
442At the top level is one directory for each client host. There are also
443some special entries:
444.TP
6037bdb3
MW
445.B \&.rsync-backup-store
446This file must be present in order to indicate that a backup volume is
447present (and not just an empty mount point).
448.TP
69305044
MW
449.B fshash.cache
450The cache database used for improving performance of local file
451hashing. There may be other
452.B fshash.cache-*
453files used by SQLite for its own purposes.
454.TP
455.B lost+found
456Part of the filesystem used on the backup volume. You don't want to
457mess with this.
458.TP
459.B tmp
460Used to store temporary files during the backup process. (Some of them
461want to be on the same filesystem as the rest of the backup.) When
462things go wrong, files are left behind in the hope that they might help
463someone debug the mess. It's always safe to delete the files in here
464when no backup is running.
465.PP
466So don't use those names for your hosts.
467.PP
468The next layer down contains a directory for each filesystem on the given host.
469.PP
470The bottom layer contains a directory for each dump of that filesystem,
471named with the date at which the dump was started (in ISO8601
472.IB yyyy \(en mm \(en dd
473format), together with associated files named
474.IB date .* \fR.
2aea4573
MW
475There is also a symbolic link
476.B last
477referring to the most recent backup of the filesystem.
69305044
MW
478.SH SEE ALSO
479.BR fshash (1),
480.BR lvm (8),
481.BR rfreezefs (8),
482.BR rsync (1),
a8447303
MW
483.BR ssh (1),
484.BR update-bkp-index (8).
69305044
MW
485.SH AUTHOR
486Mark Wooding, <mdw@distorted.org.uk>