arg parsing is only functional thing right now
[BackupPC.git] / doc-src / BackupPC.pod
1 =head1 BackupPC Introduction
2
3 This documentation describes BackupPC version __VERSION__,
4 released on __RELEASEDATE__.
5
6 =head2 Overview
7
8 BackupPC is a high-performance, enterprise-grade system for backing up
9 Unix, Linux, WinXX, and MacOSX PCs, desktops and laptops to a server's
10 disk.  BackupPC is highly configurable and easy to install and maintain.
11
12 Given the ever decreasing cost of disks and raid systems, it is now
13 practical and cost effective to backup a large number of machines onto
14 a server's local disk or network storage.  For some sites this might be
15 the complete backup solution.  For other sites additional permanent
16 archives could be created by periodically backing up the server to tape.
17
18 Features include:
19
20 =over 4
21
22 =item *
23
24 A clever pooling scheme minimizes disk storage and disk I/O.
25 Identical files across multiple backups of the same or different PC
26 are stored only once (using hard links), resulting in substantial
27 savings in disk storage and disk writes.
28
29 =item *
30
31 Optional compression provides additional reductions in storage
32 (around 40%).  The CPU impact of compression is low since only
33 new files (those not already in the pool) need to be compressed.
34
35 =item *
36
37 A powerful http/cgi user interface allows administrators to view
38 the current status, edit configuration, add/delete hosts, view log
39 files, and allows users to initiate and cancel backups and browse
40 and restore files from backups.
41
42 =item *
43
44 The http/cgi user interface has internationalization (i18n) support,
45 currently providing English, French, German, Spanish, Italian,
46 Dutch, Polish, Portuguese-Brazilian and Chinese
47
48 =item *
49
50 No client-side software is needed. On WinXX the standard smb
51 protocol is used to extract backup data. On linux, unix or MacOSX
52 clients, rsync, tar (over ssh/rsh/nfs) or ftp is used to extract
53 backup data. Alternatively, rsync can also be used on WinXX (using
54 cygwin), and Samba could be installed on the linux or unix client
55 to provide smb shares).
56
57 =item *
58
59 Flexible restore options.  Single files can be downloaded from
60 any backup directly from the CGI interface.  Zip or Tar archives
61 for selected files or directories from any backup can also be
62 downloaded from the CGI interface.  Finally, direct restore to
63 the client machine (using smb or tar) for selected files or
64 directories is also supported from the CGI interface.
65
66 =item *
67
68 BackupPC supports mobile environments where laptops are only
69 intermittently connected to the network and have dynamic IP addresses
70 (DHCP).  Configuration settings allow machines connected via slower WAN
71 connections (eg: dial up, DSL, cable) to not be backed up, even if they
72 use the same fixed or dynamic IP address as when they are connected
73 directly to the LAN.
74
75 =item *
76
77 Flexible configuration parameters allow multiple backups to be performed
78 in parallel, specification of which shares to backup, which directories
79 to backup or not backup, various schedules for full and incremental
80 backups, schedules for email reminders to users and so on.  Configuration
81 parameters can be set system-wide or also on a per-PC basis.
82
83 =item *
84
85 Users are sent periodic email reminders if their PC has not
86 recently been backed up.  Email content, timing and policies
87 are configurable.
88
89 =item *
90
91 BackupPC is Open Source software hosted by SourceForge.
92
93 =back
94
95 =head2 Backup basics
96
97 =over 4
98
99 =item Full Backup
100
101 A full backup is a complete backup of a share. BackupPC can be
102 configured to do a full backup at a regular interval (typically
103 weekly).  BackupPC can be configured to keep a certain number
104 of full backups.  Exponential expiry is also supported, allowing
105 full backups with various vintages to be kept (for example, a
106 settable number of most recent weekly fulls, plus a settable
107 number of older fulls that are 2, 4, 8, or 16 weeks apart).
108
109 =item Incremental Backup
110
111 An incremental backup is a backup of files that have changed
112 since the last successful full or incremental backup.  Starting
113 in BackupPC 3.0 multi-level incrementals are supported.
114 A full backup has level 0.  A new incremental of level N will
115 backup all files that have changed since the most recent backup
116 of a lower level.  $Conf{IncrLevels} is used to specify the
117 level of each successive incremental.  The default value is
118 all level 1, which makes the behavior the same as earlier
119 versions of BackupPC: each incremental will back up all the
120 files that changed since the last full (level 0).
121
122 For SMB and tar, BackupPC uses the modification time (mtime) to
123 determine which files have changed since the last lower-level
124 backup.  That means SMB and tar incrementals are not able to detect
125 deleted files, renamed files or new files whose modification time
126 is prior to the last lower-level backup.
127
128 Rsync is more clever: any files whose attributes have changed (ie: uid,
129 gid, mtime, modes, size) since the last full are backed up.  Deleted,
130 new files and renamed files are detected by Rsync incrementals.
131
132 BackupPC can also be configured to keep a certain number of incremental
133 backups, and to keep a smaller number of very old incremental backups.
134 If multi-level incrementals are specified then it is likely that
135 more incrementals will need to be kept since lower-level incrementals
136 (and the full backup) are needed to reconstruct a higher-level
137 incremental.
138
139 BackupPC "fills-in" incremental backups when browsing or restoring,
140 based on the levels of each backup, giving every backup a "full"
141 appearance.  This makes browsing and restoring backups much easier:
142 you can restore from any one backup independent of whether it was
143 an incremental or full.
144
145 =item Partial Backup
146
147 When a full backup fails or is canceled, and some files have already
148 been backed up, BackupPC keeps a partial backup containing just the
149 files that were backed up successfully.  The partial backup is removed
150 when the next successful backup completes, or if another full backup
151 fails resulting in a newer partial backup.  A failed full backup
152 that has not backed up any files, or any failed incremental backup,
153 is removed; no partial backup is saved in these cases.
154
155 The partial backup may be browsed or used to restore files just like
156 a successful full or incremental backup.
157
158 With the rsync transfer method the partial backup is used to resume
159 the next full backup, avoiding the need to retransfer the file data
160 already in the partial backup.
161
162 =item Identical Files
163
164 BackupPC pools identical files using hardlinks.  By "identical
165 files" we mean files with identical contents, not necessary the
166 same permissions, ownership or modification time.  Two files might
167 have different permissions, ownership, or modification time but
168 will still be pooled whenever the contents are identical.  This
169 is possible since BackupPC stores the file meta-data (permissions,
170 ownership, and modification time) separately from the file contents.
171
172 =item Backup Policy
173
174 Based on your site's requirements you need to decide what your backup
175 policy is.  BackupPC is not designed to provide exact re-imaging of
176 failed disks.  See L<Limitations|limitations> for more information.
177 However, the addition of tar transport for linux/unix clients, plus
178 full support for special file types and unix attributes in v1.4.0
179 likely means an exact image of a linux/unix file system can be made.
180
181 BackupPC saves backups onto disk. Because of pooling you can relatively
182 economically keep several weeks of old backups.
183
184 At some sites the disk-based backup will be adequate, without a
185 secondary tape backup. This system is robust to any single failure: if a
186 client disk fails or loses files, the BackupPC server can be used to
187 restore files. If the server disk fails, BackupPC can be restarted on a
188 fresh file system, and create new backups from the clients. The chance
189 of the server disk failing can be made very small by spending more money
190 on increasingly better RAID systems.  However, there is still the risk
191 of catastrophic events like fires or earthquakes that can destroy
192 both the BackupPC server and the clients it is backing up if they
193 are physically nearby.
194
195 Some sites might choose to do periodic backups to tape or cd/dvd.
196 This backup can be done perhaps weekly using the archive function of
197 BackupPC.
198
199 Other users have reported success with removable disks to rotate the
200 BackupPC data drives, or using rsync to mirror the BackupPC data pool
201 offsite.
202
203 =back
204
205 =head2 Resources
206
207 =over 4
208
209 =item BackupPC home page
210
211 The BackupPC Open Source project is hosted on SourceForge.  The
212 home page can be found at:
213
214     http://backuppc.sourceforge.net
215
216 This page has links to the current documentation, the SourceForge
217 project page and general information.
218
219 =item SourceForge project
220
221 The SourceForge project page is at:
222
223     http://sourceforge.net/projects/backuppc
224
225 This page has links to the current releases of BackupPC.
226
227 =item BackupPC Wiki
228
229 BackupPC has a Wiki at L<http://backuppc.wiki.sourceforge.net>.
230 Everyone is encouraged to contribute to the Wiki.  Anyone with
231 a SourceForge account can edit the Wiki.
232
233 The old FAQ is at L<http://backuppc.sourceforge.net/faq>, but
234 is deprecated in favor of the Wiki.
235
236 =item Mailing lists
237
238 Three BackupPC mailing lists exist for announcements (backuppc-announce),
239 developers (backuppc-devel), and a general user list for support, asking
240 questions or any other topic relevant to BackupPC (backuppc-users).
241
242 The lists are archived on SourceForge and Gmane.  The SourceForge lists
243 are not always up to date and the searching is limited, so Gmane is
244 a good alternative.  See:
245
246     http://news.gmane.org/index.php?prefix=gmane.comp.sysutils.backup.backuppc
247     http://sourceforge.net/mailarchive/forum.php?forum=backuppc-users
248
249 You can subscribe to these lists by visiting:
250
251     http://lists.sourceforge.net/lists/listinfo/backuppc-announce
252     http://lists.sourceforge.net/lists/listinfo/backuppc-users
253     http://lists.sourceforge.net/lists/listinfo/backuppc-devel
254
255 The backuppc-announce list is moderated and is used only for
256 important announcements (eg: new versions).  It is low traffic.
257 You only need to subscribe to one of backuppc-announce and
258 backuppc-users: backuppc-users also receives any messages on
259 backuppc-announce.
260
261 The backuppc-devel list is only for developers who are working on BackupPC.
262 Do not post questions or support requests there.  But detailed technical
263 discussions should happen on this list.
264
265 To post a message to the backuppc-users list, send an email to
266
267     backuppc-users@lists.sourceforge.net
268
269 Do not send subscription requests to this address!
270
271 =item Other Programs of Interest
272
273 If you want to mirror linux or unix files or directories to a remote server
274 you should use rsync, L<http://rsync.samba.org>.  BackupPC uses
275 rsync as a transport mechanism; if you are already an rsync user you
276 can think of BackupPC as adding efficient storage (compression and
277 pooling) and a convenient user interface to rsync.
278
279 Two popular open source packages that do tape backup are
280 Amanda (L<http://www.amanda.org>)
281 and Bacula (L<http://www.bacula.org>).
282 These packages can be used as complete solutions, or also as back
283 ends to BackupPC to backup the BackupPC server data to tape.
284
285 Various programs and scripts use rsync to provide hardlinked backups.
286 See, for example, Mike Rubel's site (L<http://www.mikerubel.org/computers/rsync_snapshots>),
287 JW Schultz's dirvish (L<http://www.dirvish.org/>),
288 Ben Escoto's rdiff-backup (L<http://www.nongnu.org/rdiff-backup>),
289 and John Bowman's rlbackup (L<http://www.math.ualberta.ca/imaging/rlbackup>).
290
291 Unison is a utility that can do two-way, interactive, synchronization.
292 See L<http://freshmeat.net/projects/unison>.  An external wrapper around
293 rsync that maintains transfer data to enable two-way synchronization is
294 drsync; see L<http://freshmeat.net/projects/drsync>.
295
296 BackupPC provides many additional features, such as compressed storage,
297 hardlinking any matching files (rather than just files with the same name),
298 and storing special files without root privileges.  But these other programs
299 provide simple, effective and fast solutions and are definitely worthy of
300 consideration.
301
302 =back
303
304 =head2 Road map
305
306 The new features planned for future releases of BackupPC
307 are on the Wiki at L<http://backuppc.wiki.sourceforge.net>.
308
309 Comments and suggestions are welcome.
310
311 =head2 You can help
312
313 BackupPC is free. I work on BackupPC because I enjoy doing it and I like
314 to contribute to the open source community.
315
316 BackupPC already has more than enough features for my own needs.  The
317 main compensation for continuing to work on BackupPC is knowing that
318 more and more people find it useful.  So feedback is certainly
319 appreciated, both positive and negative.
320
321 Beyond being a satisfied user and telling other people about it, everyone
322 is encouraged to add links to L<http://backuppc.sourceforge.net>
323 (I'll see them via Google) or otherwise publicize BackupPC.  Unlike
324 the commercial products in this space, I have a zero budget (in both
325 time and money) for marketing, PR and advertising, so it's up to
326 all of you!  Feel free to vote for BackupPC at
327 L<http://freshmeat.net/projects/backuppc>.
328
329 Also, everyone is encouraged to contribute patches, bug reports,
330 feature and design suggestions, new code, Wiki additions (you can
331 do those directly) and documentation corrections or improvements.
332 Answering questions on the mailing list is a big help too.
333
334 =head1 Installing BackupPC
335
336 =head2 Requirements
337
338 BackupPC requires:
339
340 =over 4
341
342 =item *
343
344 A linux, solaris, or unix based server with a substantial amount of free
345 disk space (see the next section for what that means). The CPU and disk
346 performance on this server will determine how many simultaneous backups
347 you can run. You should be able to run 4-8 simultaneous backups on a
348 moderately configured server.
349
350 Several users have reported significantly better performance using
351 reiserfs compared to ext3 for the BackupPC data file system.  It is
352 also recommended you consider either an LVM or RAID setup (either
353 in HW or SW; eg: 3Ware RAID10 or RAID5) so that you can expand the
354 file system as necessary.
355
356 When BackupPC starts with an empty pool, all the backup data will be
357 written to the pool on disk. After more backups are done, a higher
358 percentage of incoming files will already be in the pool. BackupPC is
359 able to avoid writing to disk new files that are already in the pool.
360 So over time disk writes will reduce significantly (by perhaps a factor
361 of 20 or more), since eventually 95% or more of incoming backup files
362 are typically in the pool. Disk reads from the pool are still needed to
363 do file compares to verify files are an exact match. So, with a mature
364 pool, if a relatively fast client generates data at say 1MB/sec, and you
365 run 4 simultaneous backups, there will be an average server disk load of
366 about 4MB/sec reads and 0.2MB/sec writes (assuming 95% of the incoming
367 files are in the pool). These rates will be perhaps 40% lower if
368 compression is on.
369
370 =item *
371
372 Perl version 5.8.0 or later.  If you don't have perl, please
373 see L<http://www.cpan.org>.
374
375 =item *
376
377 Perl modules Compress::Zlib, Archive::Zip and File::RsyncP.  Try "perldoc
378 Compress::Zlib" and "perldoc Archive::Zip" to see if you have these
379 modules.  If not, fetch them from L<http://www.cpan.org> and see the
380 instructions below for how to build and install them.
381
382 The File::RsyncP module is available from L<http://perlrsync.sourceforge.net>
383 or CPAN.  You'll need to install the File::RsyncP module if you want to use
384 Rsync as a transport method.
385
386 =item *
387
388 If you are using smb to backup WinXX machines you need smbclient and
389 nmblookup from the samba package.  You will also need nmblookup if
390 you are backing up linux/unix DHCP machines.  See L<http://www.samba.org>.
391 Samba versions 3.x are stable and now recommended instead of 2.x.
392
393 See L<http://www.samba.org> for source and binaries.  It's pretty easy to
394 fetch and compile samba, and just grab smbclient and nmblookup, without
395 doing the installation. Alternatively, L<http://www.samba.org> has binary
396 distributions for most platforms.
397
398 =item *
399
400 If you are using tar to backup linux/unix machines, those machines should have
401 version 1.13.7 at a minimum, with version 1.13.20 or higher recommended.  Use
402 "tar --version" to check your version.  Various GNU mirrors have the newest
403 versions of tar; see L<http://www.gnu.org/software/tar/>.
404
405 =item *
406
407 If you are using rsync to backup linux/unix machines you should have
408 version 2.6.3 or higher on each client machine.  See
409 L<http://rsync.samba.org>. Use "rsync --version" to check your version.
410
411 For BackupPC to use Rsync you will also need to install the perl
412 File::RsyncP module, which is available from
413 L<http://perlrsync.sourceforge.net>.
414 Version 0.68 or later is required.
415
416 =item *
417
418 The Apache web server, see L<http://www.apache.org>, preferably built
419 with mod_perl support.
420
421 =back
422
423 =head2 What type of storage space do I need?
424
425 BackupPC uses hardlinks to pool files common to different backups.
426 Therefore BackupPC's data store (__TOPDIR__) must point to a single
427 file system that supports hardlinks.  You cannot split this file
428 system with multiple mount points or using symbolic links to point a
429 sub-directory to a different file system (it is ok to use a single
430 symbolic link at the top-level directory (__TOPDIR__) to point the
431 entire data store somewhere else).  You can of course use any kind of
432 RAID system or logical volume manager that combines the capacity of
433 multiple disks into a single, larger, file system. Such approaches
434 have the advantage that the file system can be expanded without having
435 to copy it.
436
437 Any standard linux or unix file system supports hardlinks.  NFS mounted
438 file systems work too (provided the underlying file system supports
439 hardlinks).  But windows based FAT and NTFS file systems will not work.
440
441 Starting with BackupPC 3.1.0, run-time checks are done at startup and
442 at the start of each backup to ensure that the file system can support
443 hardlinks, since this is a common area of configuration problems.
444
445 =head2 How much disk space do I need?
446
447 Here's one real example for an environment that is backing up 65 laptops
448 with compression off. Each full backup averages 3.2GB. Each incremental
449 backup averages about 0.2GB. Storing one full backup and two incremental
450 backups per laptop is around 240GB of raw data. But because of the
451 pooling of identical files, only 87GB is used.  This is without
452 compression.
453
454 Another example, with compression on: backing up 95 laptops, where
455 each backup averages 3.6GB and each incremental averages about 0.3GB.
456 Keeping three weekly full backups, and six incrementals is around
457 1200GB of raw data.  Because of pooling and compression, only 150GB
458 is needed.
459
460 Here's a rule of thumb. Add up the disk usage of all the machines you
461 want to backup (210GB in the first example above). This is a rough
462 minimum space estimate that should allow a couple of full backups and at
463 least half a dozen incremental backups per machine. If compression is on
464 you can reduce the storage requirements by maybe 30-40%.  Add some margin
465 in case you add more machines or decide to keep more old backups.
466
467 Your actual mileage will depend upon the types of clients, operating
468 systems and applications you have. The more uniform the clients and
469 applications the bigger the benefit from pooling common files.
470
471 For example, the Eudora email tool stores each mail folder in a separate
472 file, and attachments are extracted as separate files. So in the sadly
473 common case of a large attachment emailed to many recipients, Eudora
474 will extract the attachment into a new file. When these machines are
475 backed up, only one copy of the file will be stored on the server, even
476 though the file appears in many different full or incremental backups. In
477 this sense Eudora is a "friendly" application from the point of view of
478 backup storage requirements.
479
480 An example at the other end of the spectrum is Outlook. Everything
481 (email bodies, attachments, calendar, contact lists) is stored in a
482 single file, which often becomes huge. Any change to this file requires
483 a separate copy of the file to be saved during backup. Outlook is even
484 more troublesome, since it keeps this file locked all the time, so it
485 cannot be read by smbclient whenever Outlook is running.  See the
486 L<Limitations|limitations> section for more discussion of this problem.
487
488 In addition to total disk space, you should make sure you have
489 plenty of inodes on your BackupPC data partition. Some users have
490 reported running out of inodes on their BackupPC data partition.
491 So even if you have plenty of disk space, BackupPC will report
492 failures when the inodes are exhausted.  This is a particular
493 problem with ext2/ext3 file systems that have a fixed number of
494 inodes when the file system is built.  Use "df -i" to see your
495 inode usage.
496
497 =head2 Step 1: Getting BackupPC
498
499 Some linux distributions now include BackupPC.  The Debian
500 distribution, supported by Ludovic Drolez, can be found at
501 L<http://packages.debian.org/backuppc> and is included
502 in the current stable Debian release.  On Debian, BackupPC can
503 be installed with the command:
504
505     apt-get install backuppc
506
507 In the future there might be packages for Gentoo and other
508 linux flavors.  If the packaged version is older than the
509 released version then you may want to install the
510 latest version as described below.
511
512 Otherwise, manually fetching and installing BackupPC is easy.
513 Start by downloading the latest version from
514 L<http://backuppc.sourceforge.net>.  Hit the "Code" button,
515 then select the "backuppc" or "backuppc-beta" package and
516 download the latest version.
517
518 =head2 Step 2: Installing the distribution
519
520 Note: most information in this step is only relevant if you build
521 and install BackupPC yourself.  If you use a package provided by a
522 distribution, the package management system should take of installing
523 any needed dependencies.
524
525 First off, there are three perl modules you should install.
526 These are all optional, but highly recommended:
527
528 =over 4
529
530 =item Compress::Zlib
531
532 To enable compression, you will need to install Compress::Zlib
533 from L<http://www.cpan.org>.
534 You can run "perldoc Compress::Zlib" to see if this module is installed.
535
536 =item Archive::Zip
537
538 To support restore via Zip archives you will need to install
539 Archive::Zip, also from L<http://www.cpan.org>.
540 You can run "perldoc Archive::Zip" to see if this module is installed.
541
542 =item XML::RSS
543
544 To support the RSS feature you will need to install XML::RSS, also from
545 L<http://www.cpan.org>.  There is not need to install this module if you
546 don't plan on using RSS. You can run "perldoc XML::RSS" to see if this
547 module is installed.
548
549 =item File::RsyncP
550
551 To use rsync and rsyncd with BackupPC you will need to install File::RsyncP.
552 You can run "perldoc File::RsyncP" to see if this module is installed.
553 File::RsyncP is available from L<http://perlrsync.sourceforge.net>.
554 Version 0.68 or later is required.
555
556 =item File::RsyncP
557
558 To use ftp with BackupPC you will need to install three libraries:
559 Net::FTP, Net::FTP::RetrHandle and Net::FTP::AutoReconnect. You can
560 run "perldoc Net::FTP" to see if a particular module is installed.
561
562 =back
563
564 To build and install these packages you should use the cpan program.
565 Alternatively, you can fetch the tar.gz file from L<http://www.cpan.org>
566 and then run these commands:
567
568     tar zxvf Archive-Zip-1.26.tar.gz
569     cd Archive-Zip-1.26
570     perl Makefile.PL
571     make
572     make test
573     make install
574
575 The same sequence of commands can be used for each module.
576
577 Now let's move onto BackupPC itself.  After fetching
578 BackupPC-__VERSION__.tar.gz, run these commands as root:
579
580     tar zxf BackupPC-__VERSION__.tar.gz
581     cd BackupPC-__VERSION__
582     perl configure.pl
583
584 In the future this release might also have patches available on the
585 SourceForge site.  These patch files are text files, with a name of
586 the form
587
588     BackupPC-__VERSION__plN.diff
589
590 where N is the patch level, eg: pl2 is patch-level 2.  These
591 patch files are cumulative: you only need apply the last patch
592 file, not all the earlier patch files.  If a patch file is
593 available, eg: BackupPC-__VERSION__pl2.diff, you should apply
594 the patch after extracting the tar file:
595
596      # fetch BackupPC-__VERSION__.tar.gz
597      # fetch BackupPC-__VERSION__pl2.diff
598      tar zxf BackupPC-__VERSION__.tar.gz
599      cd BackupPC-__VERSION__
600      patch -p0 < ../BackupPC-__VERSION__pl2.diff
601      perl configure.pl
602
603 A patch file includes comments that describe that bug fixes
604 and changes.  Feel free to review it before you apply the patch.
605
606 The configure.pl script also accepts command-line options if you
607 wish to run it in a non-interactive manner.  It has self-contained
608 documentation for all the command-line options, which you can
609 read with perldoc:
610
611     perldoc configure.pl
612
613 Starting with BackupPC 3.0.0, the configure.pl script by default
614 complies with the file system hierarchy (FHS) conventions.  The
615 major difference compared to earlier versions is that by default
616 configuration files will be stored in /etc/BackupPC
617 rather than below the data directory, __TOPDIR__/conf,
618 and the log files will be stored in /var/log/BackupPC
619 rather than below the data directory, __TOPDIR__/log.
620
621 Note that distributions may choose to use different locations for
622 BackupPC files than these defaults.
623
624 If you are upgrading from an earlier version the configure.pl script
625 will keep the configuration files and log files in their original
626 location.
627
628 When you run configure.pl you will be prompted for the full paths
629 of various executables, and you will be prompted for the following
630 information.
631
632 =over 4
633
634 =item BackupPC User
635
636 It is best if BackupPC runs as a special user, eg backuppc, that has
637 limited privileges. It is preferred that backuppc belongs to a system
638 administrator group so that sys admin members can browse BackupPC files,
639 edit the configuration files and so on. Although configurable, the
640 default settings leave group read permission on pool files, so make
641 sure the BackupPC user's group is chosen restrictively.
642
643 On this installation, this is __BACKUPPCUSER__.
644
645 For security purposes you might choose to configure the BackupPC
646 user with the shell set to /bin/false.  Since you might need to
647 run some BackupPC programs as the BackupPC user for testing
648 purposes, you can use the -s option to su to explicitly run
649 a shell, eg:
650
651     su -s /bin/bash __BACKUPPCUSER__
652
653 Depending upon your configuration you might also need the -l option.
654
655 =item Data Directory
656
657 You need to decide where to put the data directory, below which
658 all the BackupPC data is stored.  This needs to be a big file system.
659
660 On this installation, this is __TOPDIR__.
661
662 =item Install Directory
663
664 You should decide where the BackupPC scripts, libraries and documentation
665 should be installed, eg: /usr/local/BackupPC.
666
667 On this installation, this is __INSTALLDIR__.
668
669 =item CGI bin Directory
670
671 You should decide where the BackupPC CGI script resides.  This will
672 usually be below Apache's cgi-bin directory.
673
674 It is also possible to use a different directory and use Apache's
675 ``<Directory>'' directive to specifiy that location.  See the Apache
676 HTTP Server documentation for additional information.
677
678 On this installation, this is __CGIDIR__.
679
680 =item Apache image Directory
681
682 A directory where BackupPC's images are stored so that Apache can
683 serve them.  You should ensure this directory is readable by Apache and
684 create a symlink to this directory from the BackupPC CGI bin Directory.
685
686 =item Config and Log Directories
687
688 In this installation the configuration and log directories are
689 located in the following locations:
690
691     __CONFDIR__/config.pl    main config file
692     __CONFDIR__/hosts        hosts file
693     __CONFDIR__/pc/HOST.pl   per-pc config file
694     __LOGDIR__/BackupPC      log files, pid, status
695
696 The configure.pl script doesn't prompt for these locations but
697 they can be set for new installations using command-line options.
698
699 =back
700
701 =head2 Step 3: Setting up config.pl
702
703 After running configure.pl, browse through the config file,
704 __CONFDIR__/config.pl, and make sure all the default settings are
705 correct. In particular, you will need to decide whether to use
706 smb, tar,or rsync or ftp transport (or whether to set it on a
707 per-PC basis) and set the relevant parameters for that transport
708 method. See the section L<Client Setup|step 5: client setup> for
709 more details.
710
711 =head2 Step 4: Setting up the hosts file
712
713 The file __CONFDIR__/hosts contains the list of clients to backup.
714 BackupPC reads this file in three cases:
715
716 =over 4
717
718 =item *
719
720 Upon startup.
721
722 =item *
723
724 When BackupPC is sent a HUP (-1) signal.  Assuming you installed the
725 init.d script, you can also do this with "/etc/init.d/backuppc reload".
726
727 =item *
728
729 When the modification time of the hosts file changes.  BackupPC
730 checks the modification time once during each regular wakeup.
731
732 =back
733
734 Whenever you change the hosts file (to add or remove a host) you can
735 either do a kill -HUP BackupPC_pid or simply wait until the next regular
736 wakeup period.
737
738 Each line in the hosts file contains three fields, separated
739 by white space:
740
741 =over 4
742
743 =item Host name
744
745 This is typically the host name or NetBios name of the client machine
746 and should be in lower case.  The host name can contain spaces (escape
747 with a backslash), but it is not recommended.
748
749 Please read the section L<How BackupPC Finds Hosts|how backuppc finds hosts>.
750
751 In certain cases you might want several distinct clients to refer
752 to the same physical machine.  For example, you might have a database
753 you want to backup, and you want to bracket the backup of the database
754 with shutdown/restart using $Conf{DumpPreUserCmd} and $Conf{DumpPostUserCmd}.
755 But you also want to backup the rest of the machine while the database
756 is still running.  In the case you can specify two different clients in
757 the host file, using any mnemonic name (eg: myhost_mysql and myhost), and
758 use $Conf{ClientNameAlias} in myhost_mysql's config.pl to specify the
759 real host name of the machine.
760
761 =item DHCP flag
762
763 Starting with v2.0.0 the way hosts are discovered has changed and now
764 in most cases you should specify 0 for the DHCP flag, even if the host
765 has a dynamically assigned IP address.
766 Please read the section L<How BackupPC Finds Hosts|how backuppc finds hosts>
767 to understand whether you need to set the DHCP flag.
768
769 You only need to set DHCP to 1 if your client machine doesn't
770 respond to the NetBios multicast request:
771
772     nmblookup myHost
773
774 but does respond to a request directed to its IP address:
775
776     nmblookup -A W.X.Y.Z
777
778 If you do set DHCP to 1 on any client you will need to specify the range of
779 DHCP addresses to search is specified in $Conf{DHCPAddressRanges}.
780
781 Note also that the $Conf{ClientNameAlias} feature does not work for
782 clients with DHCP set to 1.
783
784 =item User name
785
786 This should be the unix login/email name of the user who "owns" or uses
787 this machine. This is the user who will be sent email about this
788 machine, and this user will have permission to stop/start/browse/restore
789 backups for this host.  Leave this blank if no specific person should
790 receive email or be allowed to stop/start/browse/restore backups
791 for this host.  Administrators will still have full permissions.
792
793 =item More users
794
795 Additional user names, separate by commas and with no white space,
796 can be specified.  These users will also have full permission in
797 the CGI interface to stop/start/browse/restore backups for this host.
798 These users will not be sent email about this host.
799
800 =back
801
802 The first non-comment line of the hosts file is special: it contains
803 the names of the columns and should not be edited.
804
805 Here's a simple example of a hosts file:
806
807     host        dhcp    user      moreUsers
808     farside     0       craig     jim,dave
809     larson      1       gary      andy
810
811 =head2 Step 5: Client Setup
812
813 Four methods for getting backup data from a client are supported:
814 smb, tar, rsync and ftp.  Smb or rsync are the preferred methods
815 for WinXX clients and rsync or tar are the preferred methods for
816 linux/unix/MacOSX clients.
817
818 The transfer method is set using the $Conf{XferMethod} configuration
819 setting. If you have a mixed environment (ie: you will use smb for some
820 clients and tar for others), you will need to pick the most common
821 choice for $Conf{XferMethod} for the main config.pl file, and then
822 override it in the per-PC config file for those hosts that will use
823 the other method.  (Or you could run two completely separate instances
824 of BackupPC, with different data directories, one for WinXX and the
825 other for linux/unix, but then common files between the different
826 machine types will duplicated.)
827
828 Here are some brief client setup notes:
829
830 =over 4
831
832 =item WinXX
833
834 One setup for WinXX clients is to set $Conf{XferMethod} to "smb".
835 Actually, rsyncd is the better method for WinXX if you are prepared to
836 run rsync/cygwin on your WinXX client.
837
838 If you want to use rsyncd for WinXX clients you can find a pre-packaged
839 zip file on L<http://backuppc.sourceforge.net>. The package is called
840 cygwin-rsync. It contains rsync.exe, template setup files and the
841 minimal set of cygwin libraries for everything to run.  The README file
842 contains instructions for running rsync as a service, so it starts
843 automatically everytime you boot your machine.  If you use rsync
844 to backup WinXX machines, be sure to set $Conf{ClientCharset}
845 correctly (eg: 'cp1252') so that the WinXX file name encoding is
846 correctly converted to utf8.
847
848 Otherwise, to use SMB, you can either create shares for the data you want
849 to backup or your can use the existing C$ share.  To create a new 
850 share, open "My Computer", right click on the drive (eg: C), and
851 select "Sharing..." (or select "Properties" and select the "Sharing"
852 tab). In this dialog box you can enable sharing, select the share name
853 and permissions.
854
855 All Windows NT based OS (NT, 2000, XP Pro), are configured by default 
856 to share the entire C drive as C$.  This is a special share used for 
857 various administration functions, one of which is to grant access to backup 
858 operators. All you need to do is create a new domain user, specifically 
859 for backup. Then add the new backup user to the built in "Backup 
860 Operators" group. You now have backup capability for any directory on 
861 any computer in the domain in one easy step. This avoids using 
862 administrator accounts and only grants permission to do exactly what you 
863 want for the given user, i.e.: backup.
864 Also, for additional security, you may wish to deny the ability for this 
865 user to logon to computers in the default domain policy.
866
867 If this machine uses DHCP you will also need to make sure the
868 NetBios name is set.  Go to Control Panel|System|Network Identification
869 (on Win2K) or Control Panel|System|Computer Name (on WinXP).
870 Also, you should go to Control Panel|Network Connections|Local Area
871 Connection|Properties|Internet Protocol (TCP/IP)|Properties|Advanced|WINS
872 and verify that NetBios is not disabled.
873
874 The relevant configuration settings are $Conf{SmbShareName},
875 $Conf{SmbShareUserName}, $Conf{SmbSharePasswd}, $Conf{SmbClientPath},
876 $Conf{SmbClientFullCmd}, $Conf{SmbClientIncrCmd} and
877 $Conf{SmbClientRestoreCmd}.
878
879 BackupPC needs to know the smb share user name and password for a
880 client machine that uses smb.  The user name is specified in
881 $Conf{SmbShareUserName}. There are four ways to tell BackupPC the
882 smb share password:
883
884 =over 4
885
886 =item *
887
888 As an environment variable BPC_SMB_PASSWD set before BackupPC starts.
889 If you start BackupPC manually the BPC_SMB_PASSWD variable must be set
890 manually first.  For backward compatibility for v1.5.0 and prior, the
891 environment variable PASSWD can be used if BPC_SMB_PASSWD is not set.
892 Warning: on some systems it is possible to see environment variables of
893 running processes.
894
895 =item *
896
897 Alternatively the BPC_SMB_PASSWD setting can be included in
898 /etc/init.d/backuppc, in which case you must make sure this file
899 is not world (other) readable.
900
901 =item *
902
903 As a configuration variable $Conf{SmbSharePasswd} in
904 __CONFDIR__/config.pl.  If you put the password
905 here you must make sure this file is not world (other) readable.
906
907 =item *
908
909 As a configuration variable $Conf{SmbSharePasswd} in the per-PC
910 configuration file (__CONFDIR__/pc/$host.pl or
911 __TOPDIR__/pc/$host/config.pl in non-FHS versions of BackupPC).
912 You will have to use this option if the smb share password is different
913 for each host. If you put the password here you must make sure this file
914 is not world (other) readable.
915
916 =back
917
918 Placement and protection of the smb share password is a possible
919 security risk, so please double-check the file and directory
920 permissions.  In a future version there might be support for
921 encryption of this password, but a private key will still have to
922 be stored in a protected place.  Suggestions are welcome.
923
924 As an alternative to setting $Conf{XferMethod} to "smb" (using
925 smbclient) for WinXX clients, you can use an smb network filesystem (eg:
926 ksmbfs or similar) on your linux/unix server to mount the share,
927 and then set $Conf{XferMethod} to "tar" (use tar on the network
928 mounted file system).
929
930 Also, to make sure that file names with special characters are correctly
931 transferred by smbclient you should make sure that the smb.conf file
932 has (for samba 3.x):
933
934     [global]
935         unix charset = UTF8
936
937 UTF8 is the default setting, so if the parameter is missing then it
938 is ok.  With this setting $Conf{ClientCharset} should be emtpy,
939 since smbclient has already converted the file names to utf8.
940
941 =item Linux/Unix
942
943 The preferred setup for linux/unix clients is to set $Conf{XferMethod}
944 to "rsync", "rsyncd" or "tar".
945
946 You can use either rsync, smb, or tar for linux/unix machines. Smb requires
947 that the Samba server (smbd) be run to provide the shares. Since the smb
948 protocol can't represent special files like symbolic links and fifos,
949 tar and rsync are the better transport methods for linux/unix machines.
950 (In fact, by default samba makes symbolic links look like the file or
951 directory that they point to, so you could get an infinite loop if a
952 symbolic link points to the current or parent directory. If you really
953 need to use Samba shares for linux/unix backups you should turn off the
954 "follow symlinks" samba config setting. See the smb.conf manual page.)
955
956 The requirements for each Xfer Method are:
957
958 =over 4
959
960 =item tar
961
962 You must have GNU tar on the client machine.  Use "tar --version"
963 or "gtar --version" to verify.  The version should be at least
964 1.13.7, and 1.13.20 or greater is recommended.  Tar is run on
965 the client machine via rsh or ssh.
966
967 The relevant configuration settings are $Conf{TarClientPath},
968 $Conf{TarShareName}, $Conf{TarClientCmd}, $Conf{TarFullArgs},
969 $Conf{TarIncrArgs}, and $Conf{TarClientRestoreCmd}.
970
971 =item rsync
972
973 You should have at least rsync 2.6.3, and the latest version is
974 recommended.  Rsync is run on the remote client via rsh or ssh.
975
976 The relevant configuration settings are $Conf{RsyncClientPath},
977 $Conf{RsyncClientCmd}, $Conf{RsyncClientRestoreCmd}, $Conf{RsyncShareName},
978 $Conf{RsyncArgs}, and $Conf{RsyncRestoreArgs}.
979
980 =item rsyncd
981
982 You should have at least rsync 2.6.3, and the latest version is
983 recommended.  In this case the rsync daemon should be running on
984 the client machine and BackupPC connects directly to it.
985
986 The relevant configuration settings are $Conf{RsyncdClientPort},
987 $Conf{RsyncdUserName}, $Conf{RsyncdPasswd}, $Conf{RsyncdAuthRequired},
988 $Conf{RsyncShareName}, $Conf{RsyncArgs}, $Conf{RsyncArgsExtra}, and
989 $Conf{RsyncRestoreArgs}. $Conf{RsyncShareName} is the name of an rsync
990 module (ie: the thing in square brackets in rsyncd's conf file -- see
991 rsyncd.conf), not a file system path.
992
993 Be aware that rsyncd will remove the leading '/' from path names in
994 symbolic links if you specify "use chroot = no" in the rsynd.conf file.
995 See the rsyncd.conf manual page for more information.
996
997 =item ftp
998
999 You need to be running an ftp server on the client machine.
1000 The relevant configuration settings are $Conf{FtpShareName},
1001 $Conf{FtpUserName}, $Conf{FtpPasswd}, $Conf{FtpBlockSize},
1002 $Conf{FtpPort}, $Conf{FtpTimeout}, and $Conf{FtpFollowSymlinks}.
1003
1004 =back
1005
1006 You need to set $Conf{ClientCharset} to the client's charset so that
1007 file names are correctly converted to utf8.  Use "locale charmap"
1008 on the client to see its charset.
1009
1010 For linux/unix machines you should not backup "/proc".  This directory
1011 contains a variety of files that look like regular files but they are
1012 special files that don't need to be backed up (eg: /proc/kcore is a
1013 regular file that contains physical memory).  See $Conf{BackupFilesExclude}.
1014 It is safe to back up /dev since it contains mostly character-special
1015 and block-special files, which are correctly handed by BackupPC
1016 (eg: backing up /dev/hda5 just saves the block-special file information,
1017 not the contents of the disk).
1018
1019 Alternatively, rather than backup all the file systems as a single
1020 share ("/"), it is easier to restore a single file system if you backup
1021 each file system separately.  To do this you should list each file system
1022 mount point in $Conf{TarShareName} or $Conf{RsyncShareName}, and add the
1023 --one-file-system option to $Conf{TarClientCmd} or $Conf{RsyncArgs}.
1024 In this case there is no need to exclude /proc explicitly since it looks
1025 like a different file system.
1026
1027 Next you should decide whether to run tar over ssh, rsh or nfs. Ssh is
1028 the preferred method. Rsh is not secure and therefore not recommended.
1029 Nfs will work, but you need to make sure that the BackupPC user (running
1030 on the server) has sufficient permissions to read all the files below
1031 the nfs mount.
1032
1033 Ssh allows BackupPC to run as a privileged user on the client (eg:
1034 root), since it needs sufficient permissions to read all the backup
1035 files. Ssh is setup so that BackupPC on the server (an otherwise low
1036 privileged user) can ssh as root on the client, without being prompted
1037 for a password. There are two common versions of ssh: v1 and v2. Here
1038 are some instructions for one way to setup ssh.  (Check which version
1039 of SSH you have by typing "ssh" or "man ssh".)
1040
1041 =item MacOSX
1042
1043 In general this should be similar to Linux/Unix machines.
1044 In versions 10.4 and later, the native MacOSX tar works,
1045 and also supports resource forks.  xtar is another option,
1046 and rsync works too (although the MacOSX-supplied rsync
1047 has an extension for extended attributes that is not
1048 compatible with standard rsync).
1049
1050 =item SSH Setup
1051
1052 SSH is a secure way to run tar or rsync on a backup client to extract
1053 the data.  SSH provides strong authentication and encryption of
1054 the network data.
1055
1056 Note that if you run rsyncd (rsync daemon), ssh is not used.
1057 In this case, rsyncd provides its own authentication, but there
1058 is no encryption of network data.  If you want encryption of
1059 network data you can use ssh to create a tunnel, or use a
1060 program like stunnel.
1061
1062 Setup instructions for ssh can be found at
1063 L<http://backuppc.sourceforge.net/faq/ssh.html> or on the Wiki.
1064
1065 =item Clients that use DHCP
1066
1067 If a client machine uses DHCP BackupPC needs some way to find the
1068 IP address given the host name.  One alternative is to set dhcp
1069 to 1 in the hosts file, and BackupPC will search a pool of IP
1070 addresses looking for hosts.  More efficiently, it is better to
1071 set dhcp = 0 and provide a mechanism for BackupPC to find the
1072 IP address given the host name.
1073
1074 For WinXX machines BackupPC uses the NetBios name server to determine
1075 the IP address given the host name.
1076 For unix machines you can run nmbd (the NetBios name server) from
1077 the Samba distribution so that the machine responds to a NetBios
1078 name request. See the manual page and Samba documentation for more
1079 information.
1080
1081 Alternatively, you can set $Conf{NmbLookupFindHostCmd} to any command
1082 that returns the IP address given the host name.
1083
1084 Please read the section L<How BackupPC Finds Hosts|how backuppc finds hosts>
1085 for more details.
1086
1087 =back
1088
1089 =head2 Step 6: Running BackupPC
1090
1091 The installation contains an init.d backuppc script that can be copied
1092 to /etc/init.d so that BackupPC can auto-start on boot.
1093 See init.d/README for further instructions.
1094
1095 BackupPC should be ready to start.  If you installed the init.d script,
1096 then you should be able to run BackupPC with:
1097
1098     /etc/init.d/backuppc start
1099
1100 (This script can also be invoked with "stop" to stop BackupPC and "reload"
1101 to tell BackupPC to reload config.pl and the hosts file.)
1102
1103 Otherwise, just run
1104
1105      __INSTALLDIR__/bin/BackupPC -d
1106
1107 as user __BACKUPPCUSER__.  The -d option tells BackupPC to run as a daemon
1108 (ie: it does an additional fork).
1109
1110 Any immediate errors will be printed to stderr and BackupPC will quit.
1111 Otherwise, look in __LOGDIR__/LOG and verify that BackupPC reports
1112 it has started and all is ok.
1113
1114 =head2 Step 7: Talking to BackupPC
1115
1116 You should verify that BackupPC is running by using BackupPC_serverMesg.
1117 This sends a message to BackupPC via the unix (or TCP) socket and prints
1118 the response.  Like all BackupPC programs, BackupPC_serverMesg
1119 should be run as the BackupPC user (__BACKUPPCUSER__), so you
1120 should
1121
1122     su __BACKUPPCUSER__
1123
1124 before running BackupPC_serverMesg.  If the BackupPC user is
1125 configured with /bin/false as the shell, you can use the -s
1126 option to su to explicitly run a shell, eg:
1127
1128     su -s /bin/bash __BACKUPPCUSER__
1129
1130 Depending upon your configuration you might also need
1131 the -l option.
1132
1133 You can request status information and start and stop backups using this
1134 interface. This socket interface is mainly provided for the CGI interface
1135 (and some of the BackupPC sub-programs use it too).  But right now we just
1136 want to make sure BackupPC is happy.  Each of these commands should
1137 produce some status output:
1138
1139     __INSTALLDIR__/bin/BackupPC_serverMesg status info
1140     __INSTALLDIR__/bin/BackupPC_serverMesg status jobs
1141     __INSTALLDIR__/bin/BackupPC_serverMesg status hosts
1142
1143 The output should be some hashes printed with Data::Dumper.  If it
1144 looks cryptic and confusing, and doesn't look like an error message,
1145 then all is ok.
1146
1147 The jobs status should initially show just BackupPC_trashClean.
1148 The hosts status should produce a list of every host you have listed
1149 in __CONFDIR__/hosts as part of a big cryptic output line.
1150
1151 You can also request that all hosts be queued:
1152
1153     __INSTALLDIR__/bin/BackupPC_serverMesg backup all
1154
1155 At this point you should make sure the CGI interface works since
1156 it will be much easier to see what is going on.  That's our
1157 next subject.
1158
1159 =head2 Step 8: Checking email delivery
1160
1161 The script BackupPC_sendEmail sends status and error emails to
1162 the administrator and users.  It is usually run each night
1163 by BackupPC_nightly.
1164
1165 To verify that it can run sendmail and deliver email correctly
1166 you should ask it to send a test email to you:
1167
1168     su __BACKUPPCUSER__
1169     __INSTALLDIR__/bin/BackupPC_sendEmail -u MYNAME@MYDOMAIN.COM
1170
1171 BackupPC_sendEmail also takes a -c option that checks if BackupPC
1172 is running, and it sends an email to $Conf{EMailAdminUserName}
1173 if it is not.  That can be used as a keep-alive check by adding
1174
1175     __INSTALLDIR__/bin/BackupPC_sendEmail -c
1176
1177 to __BACKUPPCUSER__'s cron.
1178
1179 The -t option to BackupPC_sendEmail causes it to print the email
1180 message instead of invoking sendmail to deliver the message.
1181
1182 =head2 Step 9: CGI interface
1183
1184 The CGI interface script, BackupPC_Admin, is a powerful and flexible
1185 way to see and control what BackupPC is doing.  It is written for an
1186 Apache server.  If you don't have Apache, see L<http://www.apache.org>.
1187
1188 There are two options for setting up the CGI interface: standard
1189 mode and using mod_perl.  Mod_perl provides much higher performance
1190 (around 15x) and is the best choice if your Apache was built with
1191 mod_perl support.  To see if your apache was built with mod_perl
1192 run this command:
1193
1194     httpd -l | egrep mod_perl
1195
1196 If this prints mod_perl.c then your Apache supports mod_perl.
1197
1198 Note: on some distributions (like Debian) the command is not ``httpd'',
1199 but ``apache'' or ``apache2''. Those distributions will generally also
1200 use ``apache'' for the Apache user account and configuration files.
1201
1202 Using mod_perl with BackupPC_Admin requires a dedicated Apache
1203 to be run as the BackupPC user (__BACKUPPCUSER__).  This is
1204 because BackupPC_Admin needs permission to access various files
1205 in BackupPC's data directories.  In contrast, the standard
1206 installation (without mod_perl) solves this problem by having
1207 BackupPC_Admin installed as setuid to the BackupPC user, so that
1208 BackupPC_Admin runs as the BackupPC user.
1209
1210 Here are some specifics for each setup:
1211
1212 =over 4
1213
1214 =item Standard Setup
1215
1216 The CGI interface should have been installed by the configure.pl script
1217 in __CGIDIR__/BackupPC_Admin.  BackupPC_Admin should have been installed
1218 as setuid to the BackupPC user (__BACKUPPCUSER__), in addition to user
1219 and group execute permission.
1220
1221 You should be very careful about permissions on BackupPC_Admin and
1222 the directory __CGIDIR__: it is important that normal users cannot
1223 directly execute or change BackupPC_Admin, otherwise they can access
1224 backup files for any PC. You might need to change the group ownership
1225 of BackupPC_Admin to a group that Apache belongs to so that Apache
1226 can execute it (don't add "other" execute permission!).
1227 The permissions should look like this:
1228
1229     ls -l __CGIDIR__/BackupPC_Admin
1230     -swxr-x---    1 __BACKUPPCUSER__   web      82406 Jun 17 22:58 __CGIDIR__/BackupPC_Admin
1231
1232 The setuid script won't work unless perl on your machine was installed
1233 with setuid emulation.  This is likely the problem if you get an error
1234 saying such as "Wrong user: my userid is 25, instead of 150", meaning
1235 the script is running as the httpd user, not the BackupPC user.
1236 This is because setuid scripts are disabled by the kernel in most
1237 flavors of unix and linux.
1238
1239 To see if your perl has setuid emulation, see if there is a program
1240 called sperl5.8.0 (or sperl5.8.2 etc, based on your perl version)
1241 in the place where perl is installed. If you can't find this program,
1242 then you have two options: rebuild and reinstall perl with the setuid
1243 emulation turned on (answer "y" to the question "Do you want to do
1244 setuid/setgid emulation?" when you run perl's configure script), or
1245 switch to the mod_perl alternative for the CGI script (which doesn't
1246 need setuid to work).
1247
1248 =item Mod_perl Setup
1249
1250 The advantage of the mod_perl setup is that no setuid script is needed,
1251 and there is a huge performance advantage.  Not only does all the perl
1252 code need to be parsed just once, the config.pl and hosts files, plus
1253 the connection to the BackupPC server are cached between requests.  The
1254 typical speedup is around 15 times.
1255
1256 To use mod_perl you need to run Apache as user __BACKUPPCUSER__.
1257 If you need to run multiple Apache's for different services then
1258 you need to create multiple top-level Apache directories, each
1259 with their own config file.  You can make copies of /etc/init.d/httpd
1260 and use the -d option to httpd to point each http to a different
1261 top-level directory.  Or you can use the -f option to explicitly
1262 point to the config file.  Multiple Apache's will run on different
1263 Ports (eg: 80 is standard, 8080 is a typical alternative port accessed
1264 via http://yourhost.com:8080).
1265
1266 Inside BackupPC's Apache http.conf file you should check the
1267 settings for ServerRoot, DocumentRoot, User, Group, and Port.  See 
1268 L<http://httpd.apache.org/docs/server-wide.html> for more details.
1269
1270 For mod_perl, BackupPC_Admin should not have setuid permission, so
1271 you should turn it off:
1272
1273     chmod u-s __CGIDIR__/BackupPC_Admin
1274
1275 To tell Apache to use mod_perl to execute BackupPC_Admin, add this
1276 to Apache's 1.x httpd.conf file:
1277
1278     <IfModule mod_perl.c>
1279         PerlModule Apache::Registry
1280         PerlTaintCheck On
1281         <Location /cgi-bin/BackupPC/BackupPC_Admin>   # <--- change path as needed
1282            SetHandler perl-script
1283            PerlHandler Apache::Registry
1284            Options ExecCGI
1285            PerlSendHeader On
1286         </Location>
1287     </IfModule>
1288
1289 Apache 2.0.44 with Perl 5.8.0 on RedHat 7.1, Don Silvia reports that
1290 this works (with tweaks from Michael Tuzi):
1291
1292     LoadModule perl_module modules/mod_perl.so
1293     PerlModule Apache2
1294
1295     <Directory /path/to/cgi/>
1296         SetHandler perl-script
1297         PerlResponseHandler ModPerl::Registry
1298         PerlOptions +ParseHeaders
1299         Options +ExecCGI
1300         Order deny,allow
1301         Deny from all
1302         Allow from 192.168.0  
1303         AuthName "Backup Admin"
1304         AuthType Basic
1305         AuthUserFile /path/to/user_file
1306         Require valid-user
1307     </Directory>
1308
1309 There are other optimizations and options with mod_perl.  For
1310 example, you can tell mod_perl to preload various perl modules,
1311 which saves memory compared to loading separate copies in every
1312 Apache process after they are forked.  See Stas's definitive
1313 mod_perl guide at L<http://perl.apache.org/guide>.
1314
1315 =back
1316
1317 BackupPC_Admin requires that users are authenticated by Apache.
1318 Specifically, it expects that Apache sets the REMOTE_USER environment
1319 variable when it runs.  There are several ways to do this.  One way
1320 is to create a .htaccess file in the cgi-bin directory that looks like:
1321
1322     AuthGroupFile /etc/httpd/conf/group    # <--- change path as needed
1323     AuthUserFile /etc/http/conf/passwd     # <--- change path as needed
1324     AuthType basic
1325     AuthName "access"
1326     require valid-user
1327
1328 You will also need "AllowOverride Indexes AuthConfig" in the Apache
1329 httpd.conf file to enable the .htaccess file. Alternatively, everything
1330 can go in the Apache httpd.conf file inside a Location directive. The
1331 list of users and password file above can be extracted from the NIS
1332 passwd file.
1333
1334 One alternative is to use LDAP.  In Apache's http.conf add these lines:
1335
1336     LoadModule auth_ldap_module   modules/auth_ldap.so
1337     AddModule auth_ldap.c
1338
1339     # cgi-bin - auth via LDAP (for BackupPC)
1340     <Location /cgi-binBackupPC/BackupPC_Admin>    # <--- change path as needed
1341       AuthType Basic
1342       AuthName "BackupPC login"
1343       # replace MYDOMAIN, PORT, ORG and CO as needed
1344       AuthLDAPURL ldap://ldap.MYDOMAIN.com:PORT/o=ORG,c=CO?uid?sub?(objectClass=*)
1345       require valid-user
1346     </Location>
1347
1348 If you want to disable the user authentication you can set
1349 $Conf{CgiAdminUsers} to '*', which allows any user to have
1350 full access to all hosts and backups.  In this case the REMOTE_USER
1351 environment variable does not have to be set by Apache.
1352
1353 Alternatively, you can force a particular user name by getting Apache
1354 to set REMOTE_USER, eg, to hardcode the user to www you could add
1355 this to Apache's httpd.conf:
1356
1357     <Location /cgi-bin/BackupPC/BackupPC_Admin>   # <--- change path as needed
1358         Setenv REMOTE_USER www
1359     </Location>
1360
1361 Finally, you should also edit the config.pl file and adjust, as necessary,
1362 the CGI-specific settings.  They're near the end of the config file. In
1363 particular, you should specify which users or groups have administrator
1364 (privileged) access: see the config settings $Conf{CgiAdminUserGroup}
1365 and $Conf{CgiAdminUsers}.  Also, the configure.pl script placed various
1366 images into $Conf{CgiImageDir} that BackupPC_Admin needs to serve
1367 up.  You should make sure that $Conf{CgiImageDirURL} is the correct
1368 URL for the image directory.
1369
1370 See the section L<Fixing installation problems|fixing installation problems> for suggestions on debugging the Apache authentication setup.
1371
1372 =head2 How BackupPC Finds Hosts
1373
1374 Starting with v2.0.0 the way hosts are discovered has changed.  In most
1375 cases you should specify 0 for the DHCP flag in the conf/hosts file,
1376 even if the host has a dynamically assigned IP address.
1377
1378 BackupPC (starting with v2.0.0) looks up hosts with DHCP = 0 in this manner:
1379
1380 =over 4
1381
1382 =item *
1383
1384 First DNS is used to lookup the IP address given the client's name
1385 using perl's gethostbyname() function.  This should succeed for machines
1386 that have fixed IP addresses that are known via DNS.  You can manually
1387 see whether a given host have a DNS entry according to perl's
1388 gethostbyname function with this command:
1389
1390     perl -e 'print(gethostbyname("myhost") ? "ok\n" : "not found\n");'
1391
1392 =item *
1393
1394 If gethostbyname() fails, BackupPC then attempts a NetBios multicast to
1395 find the host.  Provided your client machine is configured properly,
1396 it should respond to this NetBios multicast request.  Specifically,
1397 BackupPC runs a command of this form:
1398
1399     nmblookup myhost
1400
1401 If this fails you will see output like:
1402
1403     querying myhost on 10.10.255.255
1404     name_query failed to find name myhost
1405
1406 If it is successful you will see output like:
1407
1408     querying myhost on 10.10.255.255
1409     10.10.1.73 myhost<00>
1410
1411 Depending on your netmask you might need to specify the -B option to
1412 nmblookup.  For example:
1413
1414     nmblookup -B 10.10.1.255 myhost
1415
1416 If necessary, experiment with the nmblookup command which will return the
1417 IP address of the client given its name.  Then update
1418 $Conf{NmbLookupFindHostCmd} with any necessary options to nmblookup.
1419
1420 =back
1421
1422 For hosts that have the DHCP flag set to 1, these machines are
1423 discovered as follows:
1424
1425 =over 4
1426
1427 =item *
1428
1429 A DHCP address pool ($Conf{DHCPAddressRanges}) needs to be specified.
1430 BackupPC will check the NetBIOS name of each machine in the range using
1431 a command of the form:
1432
1433     nmblookup -A W.X.Y.Z
1434
1435 where W.X.Y.Z is each candidate address from $Conf{DHCPAddressRanges}.
1436 Any host that has a valid NetBIOS name returned by this command (ie:
1437 matching an entry in the hosts file) will be backed up.  You can
1438 modify the specific nmblookup command if necessary via $Conf{NmbLookupCmd}.
1439
1440 =item *
1441
1442 You only need to use this DHCP feature if your client machine doesn't
1443 respond to the NetBios multicast request:
1444
1445     nmblookup myHost
1446
1447 but does respond to a request directed to its IP address:
1448
1449     nmblookup -A W.X.Y.Z
1450
1451 =back
1452
1453 =head2 Other installation topics
1454
1455 =over 4
1456
1457 =item Removing a client
1458
1459 If there is a machine that no longer needs to be backed up (eg: a retired
1460 machine) you have two choices.  First, you can keep the backups accessible
1461 and browsable, but disable all new backups.  Alternatively, you can
1462 completely remove the client and all its backups.
1463
1464 To disable backups for a client $Conf{BackupsDisable} can be
1465 set to two different values in that client's per-PC config.pl file:
1466
1467 =over 4
1468
1469 =item 1
1470
1471 Don't do any regular backups on this machine.  Manually
1472 requested backups (via the CGI interface) will still occur.
1473
1474 =item 2
1475
1476 Don't do any backups on this machine.  Manually requested
1477 backups (via the CGI interface) will be ignored.
1478
1479 =back
1480
1481 This will still allow the client's old backups to be browsable
1482 and restorable.
1483
1484 To completely remove a client and all its backups, you should remove its
1485 entry in the conf/hosts file, and then delete the __TOPDIR__/pc/$host
1486 directory.  Whenever you change the hosts file, you should send
1487 BackupPC a HUP (-1) signal so that it re-reads the hosts file.
1488 If you don't do this, BackupPC will automatically re-read the
1489 hosts file at the next regular wakeup.
1490
1491 Note that when you remove a client's backups you won't initially
1492 recover much disk space.  That's because the client's files are
1493 still in the pool.  Overnight, when BackupPC_nightly next runs,
1494 all the unused pool files will be deleted and this will recover
1495 the disk space used by the client's backups.
1496
1497 =item Copying the pool
1498
1499 If the pool disk requirements grow you might need to copy the entire
1500 data directory to a new (bigger) file system.  Hopefully you are lucky
1501 enough to avoid this by having the data directory on a RAID file system
1502 or LVM that allows the capacity to be grown in place by adding disks.
1503
1504 The backup data directories contain large numbers of hardlinks.  If
1505 you try to copy the pool the target directory will occupy a lot more
1506 space if the hardlinks aren't re-established.
1507
1508 The best way to copy a pool file system, if possible, is by copying
1509 the raw device at the block level (eg: using dd).  Application level
1510 programs that understand hardlinks include the GNU cp program with
1511 the -a option and rsync -H.  However, the large number of hardlinks
1512 in the pool will make the memory usage large and the copy very slow.
1513 Don't forget to stop BackupPC while the copy runs.
1514
1515 Starting in 3.0.0 a new script bin/BackupPC_tarPCCopy can be
1516 used to assist the copy process.  Given one or more pc paths
1517 (eg: TOPDIR/pc/HOST or TOPDIR/pc/HOST/nnn), BackupPC_tarPCCopy 
1518 creates a tar archive with all the hardlinks pointing to ../cpool/....
1519 Any files not hardlinked (eg: backups, LOG etc) are included
1520 verbatim.
1521
1522 You will need to specify the -P option to tar when you extract
1523 the archive generated by BackupPC_tarPCCopy since the hardlink
1524 targets are outside of the directory being extracted.
1525
1526 To copy a complete store (ie: __TOPDIR__) using BackupPC_tarPCCopy
1527 you should:
1528
1529 =over 4
1530
1531 =item *
1532
1533 stop BackupPC so that the store is static.
1534
1535 =item *
1536
1537 copy the cpool, conf and log directory trees using any technique
1538 (like cp, rsync or tar) without the need to preserve hardlinks.
1539
1540 =item *
1541
1542 copy the pc directory using BackupPC_tarPCCopy:
1543
1544     su __BACKUPPCUSER__
1545     cd NEW_TOPDIR
1546     mkdir pc
1547     cd pc
1548     __INSTALLDIR__/bin/BackupPC_tarPCCopy __TOPDIR__/pc | tar xvPf -
1549
1550 =back
1551
1552 =back
1553
1554 =head2 Fixing installation problems
1555
1556 Please see the Wiki at L<http://backuppc.wiki.sourceforge.net> for
1557 debugging suggestions.  If you find a solution to your problem that
1558 could help other users please add it to the Wiki!
1559
1560 =head1 Restore functions
1561
1562 BackupPC supports several different methods for restoring files. The
1563 most convenient restore options are provided via the CGI interface.
1564 Alternatively, backup files can be restored using manual commands.
1565
1566 =head2 CGI restore options
1567
1568 By selecting a host in the CGI interface, a list of all the backups
1569 for that machine will be displayed.  By selecting the backup number
1570 you can navigate the shares and directory tree for that backup.
1571
1572 BackupPC's CGI interface automatically fills incremental backups
1573 with the corresponding full backup, which means each backup has
1574 a filled appearance.  Therefore, there is no need to do multiple
1575 restores from the incremental and full backups: BackupPC does all
1576 the hard work for you.  You simply select the files and directories
1577 you want from the correct backup vintage in one step.
1578
1579 You can download a single backup file at any time simply by selecting
1580 it.  Your browser should prompt you with the file name and ask you
1581 whether to open the file or save it to disk.
1582
1583 Alternatively, you can select one or more files or directories in
1584 the currently selected directory and select "Restore selected files".
1585 (If you need to restore selected files and directories from several
1586 different parent directories you will need to do that in multiple
1587 steps.)
1588
1589 If you select all the files in a directory, BackupPC will replace
1590 the list of files with the parent directory.  You will be presented
1591 with a screen that has three options:
1592
1593 =over 4
1594
1595 =item Option 1: Direct Restore
1596
1597 With this option the selected files and directories are restored
1598 directly back onto the host, by default in their original location.
1599 Any old files with the same name will be overwritten, so use caution.
1600 You can optionally change the target host name, target share name,
1601 and target path prefix for the restore, allowing you to restore the
1602 files to a different location.
1603
1604 Once you select "Start Restore" you will be prompted one last time
1605 with a summary of the exact source and target files and directories
1606 before you commit.  When you give the final go ahead the restore
1607 operation will be queued like a normal backup job, meaning that it
1608 will be deferred if there is a backup currently running for that host.
1609 When the restore job is run, smbclient, tar, rsync or rsyncd is used
1610 (depending upon $Conf{XferMethod}) to actually restore the files.
1611 Sorry, there is currently no option to cancel a restore that has been
1612 started.  Currently ftp restores are not fully implemented.
1613
1614 A record of the restore request, including the result and list of
1615 files and directories, is kept.  It can be browsed from the host's
1616 home page.  $Conf{RestoreInfoKeepCnt} specifies how many old restore
1617 status files to keep.
1618
1619 Note that for direct restore to work, the $Conf{XferMethod} must
1620 be able to write to the client.  For example, that means an SMB
1621 share for smbclient needs to be writable, and the rsyncd module
1622 needs "read only" set to "false".  This creates additional security
1623 risks.  If you only create read-only SMB shares (which is a good
1624 idea), then the direct restore will fail.  You can disable the
1625 direct restore option by setting $Conf{SmbClientRestoreCmd},
1626 $Conf{TarClientRestoreCmd} and $Conf{RsyncRestoreArgs} to undef.
1627
1628 =item Option 2: Download Zip archive
1629
1630 With this option a zip file containing the selected files and directories
1631 is downloaded.  The zip file can then be unpacked or individual files
1632 extracted as necessary on the host machine. The compression level can be
1633 specified.  A value of 0 turns off compression.
1634
1635 When you select "Download Zip File" you should be prompted where to
1636 save the restore.zip file.
1637
1638 BackupPC does not consider downloading a zip file as an actual
1639 restore operation, so the details are not saved for later browsing
1640 as in the first case.  However, a mention that a zip file was
1641 downloaded by a particular user, and a list of the files, does
1642 appear in BackupPC's log file.
1643
1644 =item Option 3: Download Tar archive
1645
1646 This is identical to the previous option, except a tar file is downloaded
1647 rather than a zip file (and there is currently no compression option).
1648
1649 =back
1650
1651 =head2 Command-line restore options
1652
1653 Apart from the CGI interface, BackupPC allows you to restore files
1654 and directories from the command line.  The following programs can
1655 be used:
1656
1657 =over 4
1658
1659 =item BackupPC_zcat
1660
1661 For each file name argument it inflates (uncompresses) the file and
1662 writes it to stdout.  To use BackupPC_zcat you could give it the
1663 full file name, eg:
1664
1665     __INSTALLDIR__/bin/BackupPC_zcat __TOPDIR__/pc/host/5/fc/fcraig/fexample.txt > example.txt
1666
1667 It's your responsibility to make sure the file is really compressed:
1668 BackupPC_zcat doesn't check which backup the requested file is from.
1669 BackupPC_zcat returns a non-zero status if it fails to uncompress
1670 a file.
1671
1672 =item BackupPC_tarCreate
1673
1674 BackupPC_tarCreate creates a tar file for any files or directories in
1675 a particular backup.  Merging of incrementals is done automatically,
1676 so you don't need to worry about whether certain files appear in the
1677 incremental or full backup.
1678
1679 The usage is:
1680
1681     BackupPC_tarCreate [options] files/directories...
1682     Required options:
1683        -h host         host from which the tar archive is created
1684        -n dumpNum      dump number from which the tar archive is created
1685                        A negative number means relative to the end (eg -1
1686                        means the most recent dump, -2 2nd most recent etc).
1687        -s shareName    share name from which the tar archive is created
1688   
1689     Other options:
1690        -t              print summary totals
1691        -r pathRemove   path prefix that will be replaced with pathAdd
1692        -p pathAdd      new path prefix
1693        -b BLOCKS       BLOCKS x 512 bytes per record (default 20; same as tar)
1694        -w writeBufSz   write buffer size (default 1048576 = 1MB)
1695        -e charset      charset for encoding file names (default: value of
1696                        $Conf{ClientCharset} when backup was done)
1697        -l              just print a file listing; don't generate an archive
1698        -L              just print a detailed file listing; don't generate an archive
1699
1700 The command-line files and directories are relative to the specified
1701 shareName.  The tar file is written to stdout.
1702
1703 The -h, -n and -s options specify which dump is used to generate
1704 the tar archive.  The -r and -p options can be used to relocate
1705 the paths in the tar archive so extracted files can be placed
1706 in a location different from their original location.
1707
1708 =item BackupPC_zipCreate
1709
1710 BackupPC_zipCreate creates a zip file for any files or directories in
1711 a particular backup.  Merging of incrementals is done automatically,
1712 so you don't need to worry about whether certain files appear in the
1713 incremental or full backup.
1714
1715 The usage is:
1716
1717     BackupPC_zipCreate [options] files/directories...
1718     Required options:
1719        -h host         host from which the zip archive is created
1720        -n dumpNum      dump number from which the tar archive is created
1721                        A negative number means relative to the end (eg -1
1722                        means the most recent dump, -2 2nd most recent etc).
1723        -s shareName    share name from which the zip archive is created
1724   
1725     Other options:
1726        -t              print summary totals
1727        -r pathRemove   path prefix that will be replaced with pathAdd
1728        -p pathAdd      new path prefix
1729        -c level        compression level (default is 0, no compression)
1730        -e charset      charset for encoding file names (default: cp1252)
1731
1732 The command-line files and directories are relative to the specified
1733 shareName.  The zip file is written to stdout. The -h, -n and -s
1734 options specify which dump is used to generate the zip archive.  The
1735 -r and -p options can be used to relocate the paths in the zip archive
1736 so extracted files can be placed in a location different from their
1737 original location.
1738
1739 =back
1740
1741 Each of these programs reside in __INSTALLDIR__/bin.
1742
1743 =head1 Archive functions
1744
1745 BackupPC supports archiving to removable media. For users that require
1746 offsite backups, BackupPC can create archives that stream to tape
1747 devices, or create files of specified sizes to fit onto cd or dvd media.
1748
1749 Each archive type is specified by a BackupPC host with its XferMethod
1750 set to 'archive'. This allows for multiple configurations at sites where
1751 there might be a combination of tape and cd/dvd backups being made.
1752
1753 BackupPC provides a menu that allows one or more hosts to be archived.
1754 The most recent backup of each host is archived using BackupPC_tarCreate,
1755 and the output is optionally compressed and split into fixed-sized
1756 files (eg: 650MB).
1757
1758 The archive for each host is done by default using
1759 __INSTALLDIR__/BackupPC_archiveHost.  This script can be copied
1760 and customized as needed.
1761
1762 =head2 Configuring an Archive Host
1763
1764 To create an Archive Host, add it to the hosts file just as any other host
1765 and call it a name that best describes the type of archive, e.g. ArchiveDLT
1766
1767 To tell BackupPC that the Host is for Archives, create a config.pl file in 
1768 the Archive Hosts's pc directory, adding the following line:
1769
1770 $Conf{XferMethod} = 'archive';
1771
1772 To further customise the archive's parameters you can adding the changed
1773 parameters in the host's config.pl file. The parameters are explained in
1774 the config.pl file.  Parameters may be fixed or the user can be allowed 
1775 to change them (eg: output device).
1776
1777 The per-host archive command is $Conf{ArchiveClientCmd}.  By default
1778 this invokes
1779
1780      __INSTALLDIR__/BackupPC_archiveHost
1781
1782 which you can copy and customize as necessary.
1783
1784 =head2 Starting an Archive
1785
1786 In the web interface, click on the Archive Host you wish to use. You will see a
1787 list of previous archives and a summary on each. By clicking the "Start Archive"
1788 button you are presented with the list of hosts and the approximate backup size
1789 (note this is raw size, not projected compressed size) Select the hosts you wish
1790 to archive and press the "Archive Selected Hosts" button.
1791
1792 The next screen allows you to adjust the parameters for this archive run.
1793 Press the "Start the Archive" to start archiving the selected hosts with the
1794 parameters displayed.
1795
1796 =head2 Starting an Archive from the command line
1797
1798 The script BackupPC_archiveStart can be used to start an archive from
1799 the command line (or cron etc).  The usage is:
1800
1801     BackupPC_archiveStart archiveHost userName hosts...
1802
1803 This creates an archive of the most recent backup of each of
1804 the specified hosts.  The first two arguments are the archive
1805 host and the user name making the request.
1806
1807 =head1 Other CGI Functions
1808
1809 =head2 Configuration and Host Editor
1810
1811 The CGI interface has a complete configuration and host editor.
1812 Only the administrator can edit the main configuration settings
1813 and hosts.  The edit links are in the left navigation bar.
1814
1815 When changes are made to any parameter a "Save" button appears
1816 at the top of the page.  If you are editing a text box you will
1817 need to click outside of the text box to make the Save button
1818 appear.  If you don't select Save then the changes won't be saved.
1819
1820 The host-specific configuration can be edited from the host
1821 summary page using the link in the left navigation bar.
1822 The administrator can edit any of the host-specific
1823 configuration settings.
1824
1825 When editing the host-specific configuration, each parameter has
1826 an "override" setting that denotes the value is host-specific,
1827 meaning that it overrides the setting in the main configuration.
1828 If you unselect "override" then the setting is removed from
1829 the host-specific configuration, and the main configuration
1830 file is displayed.
1831
1832 User's can edit their host-specific configuration if enabled
1833 via $Conf{CgiUserConfigEditEnable}.  The specific subset
1834 of configuration settings that a user can edit is specified
1835 with $Conf{CgiUserConfigEdit}.  It is recommended to make this
1836 list short as possible (you probably don't want your users saving
1837 dozens of backups) and it is essential that they can't edit any
1838 of the Cmd configuration settings, otherwise they can specify
1839 an arbitrary command that will be executed as the BackupPC
1840 user.
1841
1842 =head2 RSS
1843
1844 BackupPC supports a very basic RSS feed.  Provided you have the
1845 XML::RSS perl module installed, a URL similar to this will
1846 provide RSS information:
1847
1848     http://localhost/cgi-bin/BackupPC/BackupPC_Admin?action=rss
1849
1850 This feature is experimental.  The information included will
1851 probably change.
1852
1853 =head1 BackupPC Design
1854
1855 =head2 Some design issues
1856
1857 =over 4
1858
1859 =item Pooling common files
1860
1861 To quickly see if a file is already in the pool, an MD5 digest of the
1862 file length and contents is used as the file name in the pool. This
1863 can't guarantee a file is identical: it just reduces the search to
1864 often a single file or handful of files. A complete file comparison
1865 is always done to verify if two files are really the same.
1866
1867 Identical files on multiples backups are represented by hard links.
1868 Hardlinks are used so that identical files all refer to the same
1869 physical file on the server's disk. Also, hard links maintain
1870 reference counts so that BackupPC knows when to delete unused files
1871 from the pool.
1872
1873 For the computer-science majors among you, you can think of the pooling
1874 system used by BackupPC as just a chained hash table stored on a (big)
1875 file system.
1876
1877 =item The hashing function
1878
1879 There is a tradeoff between how much of file is used for the MD5 digest
1880 and the time taken comparing all the files that have the same hash.
1881
1882 Using the file length and just the first 4096 bytes of the file for the
1883 MD5 digest produces some repetitions.  One example: with 900,000 unique
1884 files in the pool, this hash gives about 7,000 repeated files, and in
1885 the worst case 500 files have the same hash.  That's not bad: we only
1886 have to do a single file compare 99.2% of the time.  But in the worst
1887 case we have to compare as many as 500 files checking for a match.
1888
1889 With a modest increase in CPU time, if we use the file length and the
1890 first 256K of the file we now only have 500 repeated files and in the
1891 worst case around 20 files have the same hash. Furthermore, if we
1892 instead use the first and last 128K of the file (more specifically, the
1893 first and eighth 128K chunks for files larger than 1MB) we get only 300
1894 repeated files and in the worst case around 20 files have the same hash.
1895
1896 Based on this experimentation, this is the hash function used by BackupPC.
1897 It is important that you don't change the hash function after files
1898 are already in the pool.  Otherwise your pool will grow to twice the
1899 size until all the old backups (and all the old files with old hashes)
1900 eventually expire.
1901
1902 =item Compression
1903
1904 BackupPC supports compression. It uses the deflate and inflate methods
1905 in the Compress::Zlib module, which is based on the zlib compression
1906 library (see L<http://www.gzip.org/zlib/>).
1907
1908 The $Conf{CompressLevel} setting specifies the compression level to use.
1909 Zero (0) means no compression. Compression levels can be from 1 (least
1910 cpu time, slightly worse compression) to 9 (most cpu time, slightly
1911 better compression). The recommended value is 3. Changing it to 5, for
1912 example, will take maybe 20% more cpu time and will get another 2-3%
1913 additional compression. Diminishing returns set in above 5.  See the zlib
1914 documentation for more information about compression levels.
1915
1916 BackupPC implements compression with minimal CPU load. Rather than
1917 compressing every incoming backup file and then trying to match it
1918 against the pool, BackupPC computes the MD5 digest based on the
1919 uncompressed file, and matches against the candidate pool files by
1920 comparing each uncompressed pool file against the incoming backup file.
1921 Since inflating a file takes roughly a factor of 10 less CPU time than
1922 deflating there is a big saving in CPU time.
1923
1924 The combination of pooling common files and compression can yield
1925 a factor of 8 or more overall saving in backup storage.
1926
1927 =back
1928
1929 =head2 BackupPC operation
1930
1931 BackupPC reads the configuration information from
1932 __CONFDIR__/config.pl. It then runs and manages all the backup
1933 activity. It maintains queues of pending backup requests, user backup
1934 requests and administrative commands. Based on the configuration various
1935 requests will be executed simultaneously.
1936
1937 As specified by $Conf{WakeupSchedule}, BackupPC wakes up periodically
1938 to queue backups on all the PCs.  This is a four step process:
1939
1940 =over 4
1941
1942 =item 1
1943
1944 For each host and DHCP address backup requests are queued on the
1945 background command queue.
1946
1947 =item 2
1948
1949 For each PC, BackupPC_dump is forked. Several of these may be run in
1950 parallel, based on the configuration. First a ping is done to see if
1951 the machine is alive. If this is a DHCP address, nmblookup is run to
1952 get the netbios name, which is used as the host name. If DNS lookup
1953 fails, $Conf{NmbLookupFindHostCmd} is run to find the IP address from
1954 the host name.  The file __TOPDIR__/pc/$host/backups is read to decide
1955 whether a full or incremental backup needs to be run. If no backup is
1956 scheduled, or the ping to $host fails, then BackupPC_dump exits.
1957
1958 The backup is done using the specified XferMethod.  Either samba's smbclient
1959 or tar over ssh/rsh/nfs piped into BackupPC_tarExtract, or rsync over ssh/rsh
1960 is run, or rsyncd is connected to, with the incoming data
1961 extracted to __TOPDIR__/pc/$host/new.  The XferMethod output is put
1962 into __TOPDIR__/pc/$host/XferLOG.
1963
1964 The letter in the XferLOG file shows the type of object, similar to the
1965 first letter of the modes displayed by ls -l:
1966
1967     d -> directory
1968     l -> symbolic link
1969     b -> block special file
1970     c -> character special file
1971     p -> pipe file (fifo)
1972     nothing -> regular file
1973
1974 The words mean:
1975
1976 =over 4
1977
1978 =item create
1979
1980 new for this backup (ie: directory or file not in pool)
1981
1982 =item pool
1983
1984 found a match in the pool
1985
1986 =item same
1987
1988 file is identical to previous backup (contents were
1989 checksummed and verified during full dump).
1990
1991 =item skip
1992
1993 file skipped in incremental because attributes are the
1994 same (only displayed if $Conf{XferLogLevel} >= 2).
1995
1996 =back
1997
1998 As BackupPC_tarExtract extracts the files from smbclient or tar, or as
1999 rsync or ftp runs, it checks each file in the backup to see if it is
2000 identical to an existing file from any previous backup of any PC. It
2001 does this without needed to write the file to disk. If the file matches
2002 an existing file, a hardlink is created to the existing file in the
2003 pool. If the file does not match any existing files, the file is written
2004 to disk and the file name is saved in __TOPDIR__/pc/$host/NewFileList
2005 for later processing by BackupPC_link.  BackupPC_tarExtract and rsync
2006 can handle arbitrarily large files and multiple candidate matching files
2007 without needing to write the file to disk in the case of a match.  This
2008 significantly reduces disk writes (and also reads, since the pool file
2009 comparison is done disk to memory, rather than disk to disk).
2010
2011 Based on the configuration settings, BackupPC_dump checks each
2012 old backup to see if any should be removed.  Any expired backups
2013 are moved to __TOPDIR__/trash for later removal by BackupPC_trashClean.
2014
2015 =item 3
2016
2017 For each complete, good, backup, BackupPC_link is run.
2018 To avoid race conditions as new files are linked into the
2019 pool area, only a single BackupPC_link program runs
2020 at a time and the rest are queued.
2021
2022 BackupPC_link reads the NewFileList written by BackupPC_dump and
2023 inspects each new file in the backup. It re-checks if there is a
2024 matching file in the pool (another BackupPC_link
2025 could have added the file since BackupPC_dump checked). If so, the file
2026 is removed and replaced by a hard link to the existing file. If the file
2027 is new, a hard link to the file is made in the pool area, so that this
2028 file is available for checking against each new file and new backup.
2029
2030 Then, if $Conf{IncrFill} is set (note that the default setting is
2031 off), for each incremental backup, hard links are made in the new
2032 backup to all files that were not extracted during the incremental
2033 backups.  The means the incremental backup looks like a complete
2034 image of the PC (with the exception that files that were removed on
2035 the PC since the last full backup will still appear in the backup
2036 directory tree).
2037
2038 The CGI interface knows how to merge unfilled incremental backups will
2039 the most recent prior filled (full) backup, giving the incremental
2040 backups a filled appearance.  The default for $Conf{IncrFill} is off,
2041 since there is no need to fill incremental backups.  This saves
2042 some level of disk activity, since lots of extra hardlinks are no
2043 longer needed (and don't have to be deleted when the backup expires).
2044
2045 =item 4
2046
2047 BackupPC_trashClean is always run in the background to remove any
2048 expired backups. Every 5 minutes it wakes up and removes all the files
2049 in __TOPDIR__/trash.
2050
2051 Also, once each night, BackupPC_nightly is run to complete some
2052 additional administrative tasks, such as cleaning the pool.  This
2053 involves removing any files in the pool that only have a single
2054 hard link (meaning no backups are using that file).  Again, to
2055 avoid race conditions, BackupPC_nightly is only run when there
2056 are no BackupPC_link processes running.  When BackupPC_nightly is
2057 run no new BackupPC_link jobs are started.  If BackupPC_nightly
2058 takes too long to run, the settings $Conf{MaxBackupPCNightlyJobs}
2059 and $Conf{BackupPCNightlyPeriod} can be used to run several
2060 BackupPC_nightly processes in parallel, and to split its job over
2061 several nights.
2062
2063 =back
2064
2065 BackupPC also listens for TCP connections on $Conf{ServerPort}, which
2066 is used by the CGI script BackupPC_Admin for status reporting and
2067 user-initiated backup or backup cancel requests.
2068
2069 =head2 Storage layout
2070
2071 BackupPC resides in several directories:
2072
2073 =over 4
2074
2075 =item __INSTALLDIR__
2076
2077 Perl scripts comprising BackupPC reside in __INSTALLDIR__/bin,
2078 libraries are in __INSTALLDIR__/lib and documentation
2079 is in __INSTALLDIR__/doc.
2080
2081 =item __CGIDIR__
2082
2083 The CGI script BackupPC_Admin resides in this cgi binary directory.
2084
2085 =item __CONFDIR__
2086
2087 All the configuration information resides below __CONFDIR__.
2088 This directory contains:
2089
2090 The directory __CONFDIR__ contains:
2091
2092 =over 4
2093
2094 =item config.pl
2095
2096 Configuration file. See L<Configuration file|configuration file>
2097 below for more details.
2098
2099 =item hosts
2100
2101 Hosts file, which lists all the PCs to backup.
2102
2103 =item pc
2104
2105 The directory __CONFDIR__/pc contains per-client configuration files
2106 that override settings in the main configuration file.  Each file
2107 is named __CONFDIR__/pc/HOST.pl, where HOST is the host name.
2108
2109 In pre-FHS versions of BackupPC these files were located in
2110 __TOPDIR__/pc/HOST/config.pl.
2111
2112 =back
2113
2114 =item __LOGDIR__
2115
2116 The directory __LOGDIR__ (__TOPDIR__/log on pre-FHS versions
2117 of BackupPC) contains:
2118
2119 =over 4
2120
2121 =item LOG
2122
2123 Current (today's) log file output from BackupPC.
2124
2125 =item LOG.0 or LOG.0.z
2126
2127 Yesterday's log file output.  Log files are aged daily and compressed
2128 (if compression is enabled), and old LOG files are deleted.
2129
2130 =item BackupPC.pid
2131
2132 Contains BackupPC's process id.
2133
2134 =item status.pl
2135
2136 A summary of BackupPC's status written periodically by BackupPC so
2137 that certain state information can be maintained if BackupPC is
2138 restarted.  Should not be edited.
2139
2140 =item UserEmailInfo.pl
2141
2142 A summary of what email was last sent to each user, and when the
2143 last email was sent.  Should not be edited.
2144
2145 =back
2146
2147 =item __TOPDIR__
2148
2149 All of BackupPC's data (PC backup images, logs, configuration information)
2150 is stored below this directory.
2151
2152 Below __TOPDIR__ are several directories:
2153
2154 =over 4
2155
2156 =item __TOPDIR__/trash
2157
2158 Any directories and files below this directory are periodically deleted
2159 whenever BackupPC_trashClean checks. When a backup is aborted or when an
2160 old backup expires, BackupPC_dump simply moves the directory to
2161 __TOPDIR__/trash for later removal by BackupPC_trashClean.
2162
2163 =item __TOPDIR__/pool
2164
2165 All uncompressed files from PC backups are stored below __TOPDIR__/pool.
2166 Each file's name is based on the MD5 hex digest of the file contents.
2167 Specifically, for files less than 256K, the file length and the entire
2168 file is used. For files up to 1MB, the file length and the first and
2169 last 128K are used. Finally, for files longer than 1MB, the file length,
2170 and the first and eighth 128K chunks for the file are used.
2171
2172 Each file is stored in a subdirectory X/Y/Z, where X, Y, Z are the
2173 first 3 hex digits of the MD5 digest.
2174
2175 For example, if a file has an MD5 digest of 123456789abcdef0,
2176 the file is stored in __TOPDIR__/pool/1/2/3/123456789abcdef0.
2177
2178 The MD5 digest might not be unique (especially since not all the file's
2179 contents are used for files bigger than 256K). Different files that have
2180 the same MD5 digest are stored with a trailing suffix "_n" where n is
2181 an incrementing number starting at 0. So, for example, if two additional
2182 files were identical to the first, except the last byte was different,
2183 and assuming the file was larger than 1MB (so the MD5 digests are the
2184 same but the files are actually different), the three files would be
2185 stored as:
2186
2187         __TOPDIR__/pool/1/2/3/123456789abcdef0
2188         __TOPDIR__/pool/1/2/3/123456789abcdef0_0
2189         __TOPDIR__/pool/1/2/3/123456789abcdef0_1
2190
2191 Both BackupPC_dump (actually, BackupPC_tarExtract) and BackupPC_link are
2192 responsible for checking newly backed up files against the pool. For
2193 each file, the MD5 digest is used to generate a file name in the pool
2194 directory. If the file exists in the pool, the contents are compared.
2195 If there is no match, additional files ending in "_n" are checked.
2196 (Actually, BackupPC_tarExtract compares multiple candidate files in
2197 parallel.)  If the file contents exactly match, the file is created by
2198 simply making a hard link to the pool file (this is done by
2199 BackupPC_tarExtract as the backup proceeds). Otherwise,
2200 BackupPC_tarExtract writes the new file to disk and a new hard link is
2201 made in the pool to the file (this is done later by BackupPC_link).
2202
2203 Therefore, every file in the pool will have at least 2 hard links
2204 (one for the pool file and one for the backup file below __TOPDIR__/pc).
2205 Identical files from different backups or PCs will all be linked to
2206 the same file.  When old backups are deleted, some files in the pool
2207 might only have one link.  BackupPC_nightly checks the entire pool
2208 and removes all files that have only a single link, thereby recovering
2209 the storage for that file.
2210
2211 One other issue: zero length files are not pooled, since there are a lot
2212 of these files and on most file systems it doesn't save any disk space
2213 to turn these files into hard links.
2214
2215 =item __TOPDIR__/cpool
2216
2217 All compressed files from PC backups are stored below __TOPDIR__/cpool.
2218 Its layout is the same as __TOPDIR__/pool, and the hashing function
2219 is the same (and, importantly, based on the uncompressed file, not
2220 the compressed file).
2221
2222 =item __TOPDIR__/pc/$host
2223
2224 For each PC $host, all the backups for that PC are stored below
2225 the directory __TOPDIR__/pc/$host.  This directory contains the
2226 following files:
2227
2228 =over 4
2229
2230 =item LOG
2231
2232 Current log file for this PC from BackupPC_dump.
2233
2234 =item LOG.DDMMYYYY or LOG.DDMMYYYY.z
2235
2236 Last month's log file.  Log files are aged monthly and compressed
2237 (if compression is enabled), and old LOG files are deleted.
2238 In earlier versions of BackupPC these files used to have
2239 a suffix of 0, 1, ....
2240
2241 =item XferERR or XferERR.z
2242
2243 Output from the transport program (ie: smbclient, tar, rsync or ftp)
2244 for the most recent failed backup.
2245
2246 =item new
2247
2248 Subdirectory in which the current backup is stored.  This
2249 directory is renamed if the backup succeeds.
2250
2251 =item XferLOG or XferLOG.z
2252
2253 Output from the transport program (ie: smbclient, tar, rsync or ftp)
2254 for the current backup.
2255
2256 =item nnn (an integer)
2257
2258 Successful backups are in directories numbered sequentially starting at 0.
2259
2260 =item XferLOG.nnn or XferLOG.nnn.z
2261
2262 Output from the transport program (ie: smbclient, tar, rsync or ftp)
2263 corresponding to backup number nnn.
2264
2265 =item RestoreInfo.nnn
2266
2267 Information about restore request #nnn including who, what, when, and
2268 why. This file is in Data::Dumper format.  (Note that the restore
2269 numbers are not related to the backup number.)
2270
2271 =item RestoreLOG.nnn.z
2272
2273 Output from smbclient, tar or rsync during restore #nnn.  (Note that the restore
2274 numbers are not related to the backup number.)
2275
2276 =item ArchiveInfo.nnn
2277
2278 Information about archive request #nnn including who, what, when, and
2279 why. This file is in Data::Dumper format.  (Note that the archive
2280 numbers are not related to the restore or backup number.)
2281
2282 =item ArchiveLOG.nnn.z
2283
2284 Output from archive #nnn.  (Note that the archive numbers are not related
2285 to the backup or restore number.)
2286
2287 =item config.pl
2288
2289 Old location of optional configuration settings specific to this host.
2290 Settings in this file override the main configuration file.
2291 In new versions of BackupPC the per-host configuration files are
2292 stored in __CONFDIR__/pc/HOST.pl.
2293
2294 =item backups
2295
2296 A tab-delimited ascii table listing information about each successful
2297 backup, one per row.  The columns are:
2298
2299 =over 4
2300
2301 =item num
2302
2303 The backup number, an integer that starts at 0 and increments
2304 for each successive backup.  The corresponding backup is stored
2305 in the directory num (eg: if this field is 5, then the backup is
2306 stored in __TOPDIR__/pc/$host/5).
2307
2308 =item type
2309
2310 Set to "full" or "incr" for full or incremental backup.
2311
2312 =item startTime
2313
2314 Start time of the backup in unix seconds.
2315
2316 =item endTime
2317
2318 Stop time of the backup in unix seconds.
2319
2320 =item nFiles
2321
2322 Number of files backed up (as reported by smbclient, tar, rsync or ftp).
2323
2324 =item size
2325
2326 Total file size backed up (as reported by smbclient, tar, rsync or ftp).
2327
2328 =item nFilesExist
2329
2330 Number of files that were already in the pool
2331 (as determined by BackupPC_dump and BackupPC_link).
2332
2333 =item sizeExist
2334
2335 Total size of files that were already in the pool
2336 (as determined by BackupPC_dump and BackupPC_link).
2337
2338 =item nFilesNew
2339
2340 Number of files that were not in the pool
2341 (as determined by BackupPC_link).
2342
2343 =item sizeNew
2344
2345 Total size of files that were not in the pool
2346 (as determined by BackupPC_link).
2347
2348 =item xferErrs
2349
2350 Number of errors or warnings from smbclient, tar, rsync or ftp.
2351
2352 =item xferBadFile
2353
2354 Number of errors from smbclient that were bad file errors (zero otherwise).
2355
2356 =item xferBadShare
2357
2358 Number of errors from smbclient that were bad share errors (zero otherwise).
2359
2360 =item tarErrs
2361
2362 Number of errors from BackupPC_tarExtract.
2363
2364 =item compress
2365
2366 The compression level used on this backup.  Zero or empty means no
2367 compression.
2368
2369 =item sizeExistComp
2370
2371 Total compressed size of files that were already in the pool
2372 (as determined by BackupPC_dump and BackupPC_link).
2373
2374 =item sizeNewComp
2375
2376 Total compressed size of files that were not in the pool
2377 (as determined by BackupPC_link).
2378
2379 =item noFill
2380
2381 Set if this backup has not been filled in with the most recent
2382 previous filled or full backup.  See $Conf{IncrFill}.
2383
2384 =item fillFromNum
2385
2386 If this backup was filled (ie: noFill is 0) then this is the
2387 number of the backup that it was filled from
2388
2389 =item mangle
2390
2391 Set if this backup has mangled file names and attributes.  Always
2392 true for backups in v1.4.0 and above.  False for all backups prior
2393 to v1.4.0.
2394
2395 =item xferMethod
2396
2397 Set to the value of $Conf{XferMethod} when this dump was done.
2398
2399 =item level
2400
2401 The level of this dump.  A full dump is level 0.  Currently incrementals
2402 are 1.  But when multi-level incrementals are supported this will reflect
2403 each dump's incremental level.
2404
2405 =back
2406
2407 =item restores
2408
2409 A tab-delimited ascii table listing information about each requested
2410 restore, one per row.  The columns are:
2411
2412 =over 4
2413
2414 =item num
2415
2416 Restore number (matches the suffix of the RestoreInfo.nnn and
2417 RestoreLOG.nnn.z file), unrelated to the backup number.
2418
2419 =item startTime
2420
2421 Start time of the restore in unix seconds.
2422
2423 =item endTime
2424
2425 End time of the restore in unix seconds.
2426
2427 =item result
2428
2429 Result (ok or failed).
2430
2431 =item errorMsg
2432
2433 Error message if restore failed.
2434
2435 =item nFiles
2436
2437 Number of files restored.
2438
2439 =item size
2440
2441 Size in bytes of the restored files.
2442
2443 =item tarCreateErrs
2444
2445 Number of errors from BackupPC_tarCreate during restore.
2446
2447 =item xferErrs
2448
2449 Number of errors from smbclient, tar, rsync or ftp during restore.
2450
2451 =back
2452
2453 =item archives
2454
2455 A tab-delimited ascii table listing information about each requested
2456 archive, one per row.  The columns are:
2457
2458 =over 4
2459
2460 =item num
2461
2462 Archive number (matches the suffix of the ArchiveInfo.nnn and
2463 ArchiveLOG.nnn.z file), unrelated to the backup or restore number.
2464
2465 =item startTime
2466
2467 Start time of the restore in unix seconds.
2468
2469 =item endTime
2470
2471 End time of the restore in unix seconds.
2472
2473 =item result
2474
2475 Result (ok or failed).
2476
2477 =item errorMsg
2478
2479 Error message if archive failed.
2480
2481 =back
2482
2483 =back
2484
2485 =back
2486
2487 =back
2488
2489 =head2 Compressed file format
2490
2491 The compressed file format is as generated by Compress::Zlib::deflate
2492 with one minor, but important, tweak. Since Compress::Zlib::inflate
2493 fully inflates its argument in memory, it could take large amounts of
2494 memory if it was inflating a highly compressed file. For example, a
2495 200MB file of 0x0 bytes compresses to around 200K bytes. If
2496 Compress::Zlib::inflate was called with this single 200K buffer, it
2497 would need to allocate 200MB of memory to return the result.
2498
2499 BackupPC watches how efficiently a file is compressing. If a big file
2500 has very high compression (meaning it will use too much memory when it
2501 is inflated), BackupPC calls the flush() method, which gracefully
2502 completes the current compression.  BackupPC then starts another
2503 deflate and simply appends the output file.  So the BackupPC compressed
2504 file format is one or more concatenated deflations/flushes.  The specific
2505 ratios that BackupPC uses is that if a 6MB chunk compresses to less
2506 than 64K then a flush will be done.
2507
2508 Back to the example of the 200MB file of 0x0 bytes.  Adding flushes
2509 every 6MB adds only 200 or so bytes to the 200K output.  So the
2510 storage cost of flushing is negligible.
2511
2512 To easily decompress a BackupPC compressed file, the script
2513 BackupPC_zcat can be found in __INSTALLDIR__/bin.  For each
2514 file name argument it inflates the file and writes it to stdout.
2515
2516 =head2 Rsync checksum caching
2517
2518 An incremental backup with rsync compares attributes on the client
2519 with the last full backup.  Any files with identical attributes
2520 are skipped.  A full backup with rsync sets the --ignore-times
2521 option, which causes every file to be examined independent of
2522 attributes.
2523
2524 Each file is examined by generating block checksums (default 2K
2525 blocks) on the receiving side (that's the BackupPC side), sending
2526 those checksums to the client, where the remote rsync matches those
2527 checksums with the corresponding file.  The matching blocks and new
2528 data is sent back, allowing the client file to be reassembled.
2529 A checksum for the entire file is sent to as an extra check the
2530 the reconstructed file is correct.
2531
2532 This results in significant disk IO and computation for BackupPC:
2533 every file in a full backup, or any file with non-matching attributes
2534 in an incremental backup, needs to be uncompressed, block checksums
2535 computed and sent.  Then the receiving side reassembles the file and
2536 has to verify the whole-file checksum.  Even if the file is identical,
2537 prior to 2.1.0, BackupPC had to read and uncompress the file twice,
2538 once to compute the block checksums and later to verify the whole-file
2539 checksum.
2540
2541 Starting in 2.1.0, BackupPC supports optional checksum caching,
2542 which means the block and file checksums only need to be computed
2543 once for each file.  This results in a significant performance
2544 improvement.  This only works for compressed pool files.
2545 It is enabled by adding
2546
2547         '--checksum-seed=32761',
2548
2549 to $Conf{RsyncArgs} and $Conf{RsyncRestoreArgs}.
2550
2551 Rsync versions prior to and including rsync-2.6.2 need a small patch to
2552 add support for the --checksum-seed option.  This patch is available in
2553 the cygwin-rsyncd package at L<http://backuppc.sourceforge.net>.
2554 This patch is already included in rsync CVS, so it will be standard
2555 in future versions of rsync.
2556
2557 When this option is present, BackupPC will add block and file checksums
2558 to the compressed pool file the next time a pool file is used and it
2559 doesn't already have cached checksums.  The first time a new file is
2560 written to the pool, the checksums are not appended.  The next time
2561 checksums are needed for a file, they are computed and added.  So the
2562 full performance benefit of checksum caching won't be noticed until the
2563 third time a pool file is used (eg: the third full backup).
2564
2565 With checksum caching enabled, there is a risk that should a file's contents
2566 in the pool be corrupted due to a disk problem, but the cached checksums
2567 are still correct, the corruption will not be detected by a full backup,
2568 since the file contents are no longer read and compared.  To reduce the
2569 chance that this remains undetected, BackupPC can recheck cached checksums
2570 for a fraction of the files.  This fraction is set with the
2571 $Conf{RsyncCsumCacheVerifyProb} setting.  The default value of 0.01 means
2572 that 1% of the time a file's checksums are read, the checksums are verified.
2573 This reduces performance slightly, but, over time, ensures that files
2574 contents are in sync with the cached checksums.
2575
2576 The format of the cached checksum data can be discovered by looking at
2577 the code.  Basically, the first byte of the compressed file is changed
2578 to denote that checksums are appended.  The block and file checksum
2579 data, plus some other information and magic word, are appended to the
2580 compressed file.  This allows the cache update to be done in-place.
2581
2582 =head2 File name mangling
2583
2584 Backup file names are stored in "mangled" form. Each node of
2585 a path is preceded by "f" (mnemonic: file), and special characters
2586 (\n, \r, % and /) are URI-encoded as "%xx", where xx is the ascii
2587 character's hex value.  So c:/craig/example.txt is now stored as
2588 fc/fcraig/fexample.txt.
2589
2590 This was done mainly so meta-data could be stored alongside the backup
2591 files without name collisions. In particular, the attributes for the
2592 files in a directory are stored in a file called "attrib", and mangling
2593 avoids file name collisions (I discarded the idea of having a duplicate
2594 directory tree for every backup just to store the attributes). Other
2595 meta-data (eg: rsync checksums) could be stored in file names preceded
2596 by, eg, "c". There are two other benefits to mangling: the share name
2597 might contain "/" (eg: "/home/craig" for tar transport), and I wanted
2598 that represented as a single level in the storage tree. Secondly, as
2599 files are written to NewFileList for later processing by BackupPC_link,
2600 embedded newlines in the file's path will cause problems which are
2601 avoided by mangling.
2602
2603 The CGI script undoes the mangling, so it is invisible to the user.
2604 Old (unmangled) backups are still supported by the CGI
2605 interface.
2606
2607 =head2 Special files
2608
2609 Linux/unix file systems support several special file types: symbolic
2610 links, character and block device files, fifos (pipes) and unix-domain
2611 sockets. All except unix-domain sockets are supported by BackupPC
2612 (there's no point in backing up or restoring unix-domain sockets since
2613 they only have meaning after a process creates them). Symbolic links are
2614 stored as a plain file whose contents are the contents of the link (not
2615 the file it points to). This file is compressed and pooled like any
2616 normal file. Character and block device files are also stored as plain
2617 files, whose contents are two integers separated by a comma; the numbers
2618 are the major and minor device number. These files are compressed and
2619 pooled like any normal file. Fifo files are stored as empty plain files
2620 (which are not pooled since they have zero size). In all cases, the
2621 original file type is stored in the attrib file so it can be correctly
2622 restored.
2623
2624 Hardlinks are also supported.  When GNU tar first encounters a file with
2625 more than one link (ie: hardlinks) it dumps it as a regular file.  When
2626 it sees the second and subsequent hardlinks to the same file, it dumps
2627 just the hardlink information.  BackupPC correctly recognizes these
2628 hardlinks and stores them just like symlinks: a regular text file
2629 whose contents is the path of the file linked to.  The CGI script
2630 will download the original file when you click on a hardlink.
2631
2632 Also, BackupPC_tarCreate has enough magic to re-create the hardlinks
2633 dynamically based on whether or not the original file and hardlinks
2634 are both included in the tar file.  For example, imagine a/b/x is a
2635 hardlink to a/c/y.  If you use BackupPC_tarCreate to restore directory
2636 a, then the tar file will include a/b/x as the original file and a/c/y
2637 will be a hardlink to a/b/x.  If, instead you restore a/c, then the
2638 tar file will include a/c/y as the original file, not a hardlink.
2639
2640 =head2 Attribute file format
2641
2642 The unix attributes for the contents of a directory (all the files and
2643 directories in that directory) are stored in a file called attrib.
2644 There is a single attrib file for each directory in a backup.
2645 For example, if c:/craig contains a single file c:/craig/example.txt,
2646 that file would be stored as fc/fcraig/fexample.txt and there would be an
2647 attribute file in fc/fcraig/attrib (and also fc/attrib and ./attrib).
2648 The file fc/fcraig/attrib would contain a single entry containing the
2649 attributes for fc/fcraig/fexample.txt.
2650
2651 The attrib file starts with a magic number, followed by the
2652 concatenation of the following information for each file:
2653
2654 =over 4
2655
2656 =item *
2657
2658 File name length in perl's pack "w" format (variable length base 128).
2659
2660 =item *
2661
2662 File name.
2663
2664 =item *
2665
2666 The unix file type, mode, uid, gid and file size divided by 4GB and
2667 file size modulo 4GB (type mode uid gid sizeDiv4GB sizeMod4GB),
2668 in perl's pack "w" format (variable length base 128).
2669
2670 =item *
2671
2672 The unix mtime (unix seconds) in perl's pack "N" format (32 bit integer).
2673
2674 =back
2675
2676 The attrib file is also compressed if compression is enabled.
2677 See the lib/BackupPC/Attrib.pm module for full details.
2678
2679 Attribute files are pooled just like normal backup files.  This saves
2680 space if all the files in a directory have the same attributes across
2681 multiple backups, which is common.
2682
2683 =head2 Optimizations
2684
2685 BackupPC doesn't care about the access time of files in the pool
2686 since it saves attribute meta-data separate from the files.  Since
2687 BackupPC mostly does reads from disk, maintaining the access time of
2688 files generates a lot of unnecessary disk writes.  So, provided 
2689 BackupPC has a dedicated data disk, you should consider mounting
2690 BackupPC's data directory with the noatime (or, with Linux kernels
2691 >=2.6.20, relatime) attribute (see mount(1)).
2692
2693 =head2 Limitations
2694
2695 BackupPC isn't perfect (but it is getting better). Please see
2696 L<http://backuppc.sourceforge.net/faq/limitations.html> for a
2697 discussion of some of BackupPC's limitations.
2698
2699 =head2 Security issues
2700
2701 Please see L<http://backuppc.sourceforge.net/faq/security.html> for a
2702 discussion of some of various security issues.
2703
2704 =head1 Configuration File
2705
2706 The BackupPC configuration file resides in __CONFDIR__/config.pl.
2707 Optional per-PC configuration files reside in __CONFDIR__/pc/$host.pl
2708 (or __TOPDIR__/pc/$host/config.pl in non-FHS versions of BackupPC).
2709 This file can be used to override settings just for a particular PC.
2710
2711 =head2 Modifying the main configuration file
2712
2713 The configuration file is a perl script that is executed by BackupPC, so
2714 you should be careful to preserve the file syntax (punctuation, quotes
2715 etc) when you edit it. It is recommended that you use CVS, RCS or some
2716 other method of source control for changing config.pl.
2717
2718 BackupPC reads or re-reads the main configuration file and
2719 the hosts file in three cases:
2720
2721 =over 4
2722
2723 =item *
2724
2725 Upon startup.
2726
2727 =item *
2728
2729 When BackupPC is sent a HUP (-1) signal.  Assuming you installed the 
2730 init.d script, you can also do this with "/etc/init.d/backuppc reload".
2731
2732 =item *
2733
2734 When the modification time of config.pl file changes.  BackupPC
2735 checks the modification time once during each regular wakeup.
2736
2737 =back
2738
2739 Whenever you change the configuration file you can either do
2740 a kill -HUP BackupPC_pid or simply wait until the next regular
2741 wakeup period.
2742
2743 Each time the configuration file is re-read a message is reported in the
2744 LOG file, so you can tail it (or view it via the CGI interface) to make
2745 sure your kill -HUP worked. Errors in parsing the configuration file are
2746 also reported in the LOG file.
2747
2748 The optional per-PC configuration file (__CONFDIR__/pc/$host.pl or
2749 __TOPDIR__/pc/$host/config.pl in non-FHS versions of BackupPC)
2750 is read whenever it is needed by BackupPC_dump, BackupPC_link and others.
2751
2752 =head1 Configuration Parameters
2753
2754 The configuration parameters are divided into five general groups.
2755 The first group (general server configuration) provides general
2756 configuration for BackupPC.  The next two groups describe what to
2757 backup, when to do it, and how long to keep it.  The fourth group
2758 are settings for email reminders, and the final group contains
2759 settings for the CGI interface.
2760
2761 All configuration settings in the second through fifth groups can
2762 be overridden by the per-PC config.pl file.
2763
2764 __CONFIGPOD__
2765
2766 =head1 Version Numbers
2767
2768 Starting with v1.4.0 BackupPC uses a X.Y.Z version numbering system,
2769 instead of X.0Y. The first digit is for major new releases, the middle
2770 digit is for significant feature releases and improvements (most of
2771 the releases have been in this category), and the last digit is for
2772 bug fixes. You should think of the old 1.00, 1.01, 1.02 and 1.03 as
2773 1.0.0, 1.1.0, 1.2.0 and 1.3.0.
2774
2775 Additionally, patches might be made available.  A patched version
2776 number is of the form X.Y.ZplN (eg: 2.1.0pl2), where N is the
2777 patch level.
2778
2779 =head1 Author
2780
2781 Craig Barratt  <cbarratt@users.sourceforge.net>
2782
2783 See L<http://backuppc.sourceforge.net>.
2784
2785 =head1 Copyright
2786
2787 Copyright (C) 2001-2009 Craig Barratt
2788
2789 =head1 Credits
2790
2791 Ryan Kucera contributed the directory navigation code and images
2792 for v1.5.0.  He contributed the first skeleton of BackupPC_restore.
2793 He also added a significant revision to the CGI interface, including
2794 CSS tags, in v2.1.0, and designed the BackupPC logo.
2795
2796 Xavier Nicollet, with additions from Guillaume Filion, added the
2797 internationalization (i18n) support to the CGI interface for v2.0.0.
2798 Xavier provided the French translation fr.pm, with additions from
2799 Guillaume.
2800
2801 Guillaume Filion wrote BackupPC_zipCreate and added the CGI support
2802 for zip download, in addition to some CGI cleanup, for v1.5.0.
2803 Guillaume continues to support fr.pm updates for each new version.
2804
2805 Josh Marshall implemented the Archive feature in v2.1.0.
2806
2807 Ludovic Drolez supports the BackupPC Debian package.
2808
2809 Javier Gonzalez provided the Spanish translation, es.pm for v2.0.0.
2810
2811 Manfred Herrmann provided the German translation, de.pm for v2.0.0.
2812 Manfred continues to support de.pm updates for each new version,
2813 together with some help from Ralph Paßgang.
2814
2815 Lorenzo Cappelletti provided the Italian translation, it.pm for v2.1.0.
2816 Giuseppe Iuculano and Vittorio Macchi updated it for 3.0.0.
2817
2818 Lieven Bridts provided the Dutch translation, nl.pm, for v2.1.0,
2819 with some tweaks from Guus Houtzager, and updates for 3.0.0.
2820
2821 Reginaldo Ferreira provided the Portuguese Brazillian translation
2822 pt_br.pm for v2.2.0.
2823
2824 Rich Duzenbury provided the RSS feed option to the CGI interface.
2825
2826 Jono Woodhouse from CapeSoft Software (www.capesoft.com) provided a
2827 new CSS skin for 3.0.0 with several layout improvements.  Sean Cameron
2828 (also from CapeSoft) designed new and more compact file icons for 3.0.0.
2829
2830 Youlin Feng provided the Chinese translation for 3.1.0.
2831
2832 Karol 'Semper' Stelmaczonek provided the Polish translation for 3.1.0.
2833
2834 Jeremy Tietsort provided the host summary table sorting feature for 3.1.0.
2835
2836 Paul Mantz contributed the ftp Xfer method for 3.2.0.
2837
2838 Many people have reported bugs, made useful suggestions and helped
2839 with testing; see the ChangeLog and the mailing lists.
2840
2841 Your name could appear here in the next version!
2842
2843 =head1 License
2844
2845 This program is free software; you can redistribute it and/or modify it
2846 under the terms of the GNU General Public License as published by the
2847 Free Software Foundation; either version 2 of the License, or (at your
2848 option) any later version.
2849
2850 This program is distributed in the hope that it will be useful,
2851 but WITHOUT ANY WARRANTY; without even the implied warranty of
2852 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2853 General Public License for more details.
2854
2855 You should have received a copy of the GNU General Public License in the
2856 LICENSE file along with this program; if not, write to the Free Software
2857 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.