5 \h'-\w'\fB\\$1\ \fP'u'\fB\\$1\ \fP\c
7 .TH rsync-backup 8 "7 October 2012" rsync-backup
16 script is a backup program of the currently popular
21 ability to create hardlinks from (apparently) similar existing local
22 trees to make incremental dumps efficient, even from remote sources.
23 Restoring files is easy because the backups created are just directories
24 full of files, exactly as they were on the source \(en and this is
29 The script does more than just running
31 It is also responsible for creating and removing snapshots of volumes to
32 be backed up, and expiring old dumps according to a user-specified
37 script should be installed and run on a central backup server with local
38 access to the backup volumes.
40 The script should be run with full (root) privileges, so that it can
41 correctly record file ownership information. The server should also be
44 to the client machines, and run processes there as root. (This is not a
45 security disaster. Remember that the backup server is, in the end,
46 responsible for the integrity of the backup data. A dishonest backup
47 server can easily compromise a client which is being restored from
49 .SS Command-line options
50 Most of the behaviour of
52 is controlled by a configuration file, described starting with the
54 .B Configuration commands
56 But a few features are controlled by command-line options.
59 Show a brief help message for the program, and exit successfully.
64 version number and some choice pieces of build-time configuration, and
70 instead of the default configuration file (shown as
77 Don't actually take a backup, or write proper logs: instead, write a
78 description of what would be done to standard error.
81 Produce verbose progress information on standard output while the backup
82 is running. This keeps one amused while running a backup
83 interactively. In any event,
85 will report failures to standard error, and otherwise run silently, so
86 it doesn't annoy unnecessarily if run by
89 Backing up a filesystem works as follows.
91 Make a snapshot of the filesystem on the client, and ensure that the
92 snapshot is mounted. There are some `trivial' snapshot types which use
93 the existing mounted filesystem, and either prevent processes writing to
94 it during the backup, or just hope for the best. Other snapshot types
95 require the snapshot to be mounted somewhere distinct from the main
96 filesystem, so that the latter can continue being used.
100 to copy the snapshot to the backup volume \(en specifically, to
101 .IB host / fs / new \fR.
102 If this directory already exists, then it's presumed to be debris from a
103 previous attempt to dump this filesystem:
105 will update it appropriately, by adding, deleting or modifying the
106 files. This means that retrying a failed dump \(en after fixing whatever
107 caused it to go wrong, obviously! \(en is usually fairly quick.
111 on the client to generate a `digest' describing the contents of the
112 filesystem, and send this to the server as
113 .IB host / fs / new .fshash \fR.
115 Release the snapshot: we don't need it any more.
119 over the new backup; specifically, to
120 .BI tmp/fshash. host . fs . date \fR.
121 This gives us a digest for what the backup volume actually stored.
125 digests. If they differ then dump the differences to the log file and
126 report a backup failure. (Backups aren't any good if they don't
127 actually back up the right thing. And you stand a better chance of
128 fixing them if you know that they're going wrong.)
130 Commit the backup, by renaming the dump directory to
135 .IB host / fs / date .fshash \fR.
137 The backup is now complete.
138 .SS Configuration commands
139 The configuration file is simply a Bash shell fragment: configuration
140 commands are shell functions.
142 .BI "backup " "fs\fR[:\fIfsarg\fR] ..."
143 Back up the named filesystems. The corresponding
145 may be required by the snapshot type.
150 commands will back up filesystems on the named
152 To back up filesystems on the backup server itself, use its hostname:
154 will avoid inefficient and pointless messing about
157 This command clears the
161 .BI "like " "host\fR ..."
162 Declare that subsequent filesystems are `similar' to like-named
163 filesystems on the named
167 should use those trees as potential sources of hardlinkable files. Be
168 careful when using this option without
171 option: an erroneous hardlink will cause the backup to fail. (The
172 backup won't be left silently incorrect.)
174 .BI "retain " frequency " " duration
175 Define part a backup retention policy: backup trees of the
177 should be kept for the
189 which means the same); the
197 Expiry considers each existing dump against the policy lines in order:
198 the last applicable line determines the dump's fate \(en so you should
199 probably write the lines in decreasing order of duration.
204 snapshot type (see below) doesn't prevent a filesystem from being
205 modified while it's being backed up. If this happens, the
207 pass will detect the difference and fail. If the filesystem in question
208 is relatively quiescent, then maybe retrying the backup will result in a
209 successful consistent copy. Following this command, a backup which
212 mismatch will be retried up to
214 times before being declared a failure.
216 .BI "snap " type " " \fR[\fIargs\fR...]
219 for subsequent backups. Some snapshot types require additional
220 arguments, which may be supplied here. This command clears the
223 .SS Configuration variables
224 The following shell variables may be overridden by the configuration
228 The number of log files to be kept for each filesystem. Old logfiles
229 are deleted to keep the total number below this bound. The default
233 Command-line options to pass to
235 in addition to the basic set:
242 .B \-\-one-file-system
244 .BR "\-\-filter=""dir-merge .rsync-backup""" .
251 snapshots are mounted on subdirectories below the
253 .IR "on backup clients" .
258 is the backup mount directory configured at build time.
261 The volume size option to pass to
263 when creating a snapshot. The default is
265 which seems to work fairly well.
268 Where the actual backup trees should be stored. See the section on
275 is the backup mount directory configured at build time.
278 The hash function to use for verifying archive integrity. This is
283 so it must name one of the hash functions supported by your Python's
285 module. The default is
288 The configuration file may define shell functions to perform custom
289 actions at various points in the backup process.
291 .BI "backup_precommit_hook " host " " fs " " date
292 Called after a backup has been verified complete and about to be
293 committed. The backup tree is in
295 in the current directory, and the
299 A typical action would be to create a digital signature on the
302 .BI "backup_commit_hook " host " " fs " " date
303 Called during the commit procedure. The backup tree and manifest have
304 been renamed into their proper places. Typically one would use this
305 hook to rename files created by the
306 .B backup_precommit_hook
309 .BR "whine " [ \-n ] " " \fItext\fR...
310 Called to report `interesting' events when the
312 option is in force. The default action is to echo the
314 to (what was initially) standard output, followed by a newline unless
318 The following snapshot types are available.
321 A trivial snapshot type: attempts to back up a live filesystem. How
322 well this works depends on how active the filesystem is. If files
323 change while the dump is in progress then the
325 verification will likely fail. Backups using this snapshot type must
326 specify the filesystem mount point as the
330 A slightly less trivial snapshot type: make the filesystem read-only
331 while the dump is in progress. Backups using this snapshot type must
332 specify the filesystem mount point as the
336 Create snapshots using LVM. The snapshot argument is interpreted as the
337 relevant volume group. The filesystem name is interpreted as the origin
338 volume name; the snapshot will be called
341 .IB SNAPDIR / fs \fR;
342 space will be allocated to it according to the
346 .BI "rfreezefs " client " " vg
347 This gets complicated. Suppose that a server has an LVM volume group,
348 and exports (somehow) a logical volume to a client. Examples are a host
349 providing a virtual disk to a guest, or a server providing
350 network-attached storage to a client. The server can create a snapshot
351 of the volume using LVM, but must synchronize with the client to ensure
352 that the filesystem image captured in the snapshot is clean. The
354 program should be installed on the client to perform this rather
355 delicate synchronization. Declare the server using the
357 command as usual; pass the client's name as the
360 server's volume group name as the
362 snapshot arguments. Finally, backups using this snapshot type must
363 specify the filesystem mount point (or, actually, any file in the
364 filesystem) on the client, as the
367 Additional snapshot types can be defined in the configuration file. A
368 snapshot type requires two shell functions.
370 .BI snap_ type " " snapargs " " fs " " fsarg
371 Create the snapshot, and write the mountpoint (on the client host) to
372 standard output, in a form suitable as an argument to
375 .BI unsnap_ type " " snapargs " " fs " " fsarg
378 There are a number of utility functions which can be used by snapshot
379 type handlers: please see the script for details. Please send the
380 author interesting snapshot handlers for inclusion in the main
382 .SS Archive structure
383 Backup trees are stored in a fairly straightforward directory tree.
385 At the top level is one directory for each client host. There are also
386 some special entries:
388 .B \&.rsync-backup-store
389 This file must be present in order to indicate that a backup volume is
390 present (and not just an empty mount point).
393 The cache database used for improving performance of local file
394 hashing. There may be other
396 files used by SQLite for its own purposes.
399 Part of the filesystem used on the backup volume. You don't want to
403 Used to store temporary files during the backup process. (Some of them
404 want to be on the same filesystem as the rest of the backup.) When
405 things go wrong, files are left behind in the hope that they might help
406 someone debug the mess. It's always safe to delete the files in here
407 when no backup is running.
409 So don't use those names for your hosts.
411 The next layer down contains a directory for each filesystem on the given host.
413 The bottom layer contains a directory for each dump of that filesystem,
414 named with the date at which the dump was started (in ISO8601
415 .IB yyyy \(en mm \(en dd
416 format), together with associated files named
425 Mark Wooding, <mdw@distorted.org.uk>