fshash.in: Save and restore working directory when walking.
[rsync-backup] / rsync-backup.8
CommitLineData
f6b4ffdc
MW
1.TH rsync-backup 8 "7 October 2012" rsync-backup
2.SH SYNOPSIS
3.B rsync-backup
4.RB [ \-v ]
5.RB [ \-c
6.IR config-file ]
7.SH DESCRIPTION
8The
9.B rsync-backup
10script is a backup program of the currently popular
11.RB ` rsync (1)
12.BR \-\-link-dest '
13variety. It uses
14.BR rsync 's
15ability to create hardlinks from (apparently) similar existing local
16trees to make incremental dumps efficient, even from remote sources.
17Restoring files is easy because the backups created are just directories
18full of files, exactly as they were on the source \(en and this is
19verified using the
20.BR fshash (1)
21program.
22.PP
23The script does more than just running
24.BR rsync .
25It is also responsible for creating and removing snapshots of volumes to
26be backed up, and expiring old dumps according to a user-specified
27retention policy.
28.SS Installation
29The idea is that the
30.B rsync-backup
31script should be installed and run on a central backup server with local
32access to the backup volumes.
33.PP
34The script should be run with full (root) privileges, so that it can
35correctly record file ownership information. The server should also be
36able to connect via
37.BR ssh (1)
38to the client machines, and run processes there as root. (This is not a
39security disaster. Remember that the backup server is, in the end,
40responsible for the integrity of the backup data. A dishonest backup
41server can easily compromise a client which is being restored from
42corrupt backup data.)
43.PP
44The
45
46
47.SS Configuration commands
48The configuration file is simply a Bash shell fragment: configuration
49commands are shell functions.
50.TP
51.BI "backup " "fs\fR[:\fIfsarg\fR] ..."
52Back up the named filesystems. The corresponding
53.IR fsarg s
54may be required by the snapshot type.
55.TP
56.BI "host " host
57Future
58.B backup
59commands will back up filesystems on the named
60.IR host .
61This clears the
62.B like
63list.
64.TP
65.BI "like " "host\fR ..."
66Declare that subsequent filesystems are `similar' to like-named
67filesystems on the named
68.IR host s,
69and that
70.B rsync
71should use those trees as potential sources of hardlinkable files. Be
72careful when using this option without
73.BR rsync 's
74.B \-\-checksum
75option: an erroneous hardlink will cause the backup to fail. (The
76backup won't be left silently incorrect.)
77.TP
78.BI "retain " frequency " " duration
79Define part a backup retention policy: backup trees of the
80.I frequency
81should be kept for the
82.IR duration .
83The
84.I frequency
85can be
86.BR daily ,
87.BR weekly ,
88.BR monthly ,
89or
90.B annually
91(or
92.BR yearly ,
93which means the same); the
94.I duration
95may be any of
96.BR week ,
97.BR month ,
98.BR year ,
99or
100.BR forever .
101Expiry considers each existing dump against the policy lines in order:
102the last applicable line determines the dump's fate \(en so you should
103probably write the lines in decreasing order of duration.
104.TP
105.BI "snap " type " " \fR[\fIargs\fR...]
106Use the snapshot
107.I type
108for subsequent backups. Some snapshot types require additional
109arguments, which may be supplied here.
110.SS Configuration variables
111The following shell variables may be overridden by the configuration
112file.
113.TP
114.B MAXLOG
115The number of log files to be kept for each filesystem. Old logfiles
116are deleted to keep the total number below this bound. The default
117value is 14.
118.TP
119.B RSYNCOPTS
120Command-line options to pass to
121.BR rsync (1)
122in addition to the basic set:
123.B \-\-archive \-\-hard-links \-\-numeric-ids \-\-del \-\-sparse
124.B \-\-compress \-\-one-file-system \-\-partial
125.B \-\-filter="dir-merge .rsync-backup"
126The default is
127.BR \-\-verbose .
128.TP
129.B SNAPDIR
130LVM (and
131.BR rfreezefs )
132snapshots are mounted on subdirectories below the
133.B SNAPDIR
134.IR "on backup clients" .
135The default is
136.IB mntbkpdir /snap
137where
138.I mntbkpdir
139is the backup mount directory configured at build time.
140.TP
141.B SNAPSIZE
142The volume size option to pass to
143.BR lvcreate (8)
144when creating a snapshot. The default is
145.B \-l10%ORIGIN
146which seems to work fairly well.
147.TP
148.B STOREDIR
149Where the actual backup trees should be stored. See the section on
150.B Archive structure
151below.
152The default is
153.IB mntbkpdir /store
154where
155.I mntbkpdir
156is the backup mount directory configured at build time.
157.TP
158.B HASH
159The hash function to use for verifying archive integrity. This is
160passed to the
161.B \-H
162option of
163.BR fshash ,
164so it must name one of the hash functions supported by your Python's
165.B hashlib
166module. The default is
167.BR sha256 .
168.SS Hook functions
169The configuration file may define shell functions to perform custom
170actions at various points in the backup process.
171.TP
172.BI "backup_precommit_hook " host " " fs " " date
173Called after a backup has been verified complete and about to be
174committed. The backup tree is in
175.B new
176in the current directory, and the
177.B fshash
178manifest is in
179.BR new.fshash .
180A typical action would be to create a digital signature on the
181manifest.
182.TP
183.BI "backup_commit_hook " host " " fs " " date
184Called during the commit procedure. The backup tree and manifest have
185been renamed into their proper places. Typically one would use this
186hook to rename files created by the
187.B backup_precommit_hook
188function.
189.TP
190.BR "whine " [ \-n ] " " \fItext\fR...
191Called to report `interesting' events when the
192.B \-v
193option is in force. The default action is to echo the
194.I text
195to (what was initially) standard output, followed by a newline unless
196.B \-n
197is given.
198.SS Snapshot types
199The following snapshot types are available.
200.TP
201.B live
202A trivial snapshot type: attempts to back up a live filesystem. How
203well this works depends on how active the filesystem is. If files
204change while the dump is in progress then the
205.B fshash
206verification will likely fail. Backups using this snapshot type must
207specify the filesystem mount point as the
208.IR fsarg .
209.TP
210.B ro
211A slightly less trivial snapshot type: make the filesystem read-only
212while the dump is in progress. Backups using this snapshot type must
213specify the filesystem mount point as the
214.IR fsarg .
215.TP
216.BI "lvm " vg
217Create snapshots using LVM. The snapshot argument is interpreted as the
218relevant volume group. The filesystem name is interpreted as the origin
219volume name; the snapshot will be called
220.IB fs .bkp
221and mounted on
222.IB SNAPDIR / fs \fR;
223space will be allocated to it according to the
224.I SNAPSIZE
225variable.
226.TP
227.BI "rfreezefs " client " " vg
228This gets complicated. Suppose that a server has an LVM volume group,
229and exports (somehow) a logical volume to a client. Examples are a host
230providing a virtual disk to a guest, or a server providing
231network-attached storage to a client. The server can create a snapshot
232of the volume using LVM, but must synchronize with the client to ensure
233that the filesystem image captured in the snapshot is clean. The
234.BR rfreezefs (8)
235program should be installed on the client to perform this rather
236delicate synchronization. Declare the server using the
237.B host
238command as usual; pass the client's name as the
239.I client
240and the
241server's volume group name as the
242.I vg
243snapshot arguments. Finally, backups using this snapshot type must
244specify the filesystem mount point (or, actually, any file in the
245filesystem) on the client, as the
246.IR fsarg .
247.PP
248Additional snapshot types can be defined in the configuration file. A
249snapshot type requires two shell functions.
250.TP
251.BI snap_ type " " snapargs " " fs " " fsarg
252Create the snapshot, and write the mountpoint (on the client host) to
253standard output, in a form suitable as an argument to
254.BR rsync .
255.TP
256.BI unsnap_ type " " snapargs " " fs " " fsarg
257Remove the snapshot.
258.PP
259There are a number of utility functions which can be used by snapshot
260type handlers: please see the script for details. Please send the
261author interesting snapshot handlers for inclusion in the main
262distribution.
263.SS Archive structure