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