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