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