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