- fixed configure.pl and makeDist.
[BackupPC.git] / lib / BackupPC / Storage.pm
1 #============================================================= -*-perl-*-
2 #
3 # BackupPC::Storage package
4 #
5 # DESCRIPTION
6 #
7 #   This library defines a BackupPC::Storage class for reading/writing
8 #   data like config, host info, backup and restore info.
9 #
10 # AUTHOR
11 #   Craig Barratt  <cbarratt@users.sourceforge.net>
12 #
13 # COPYRIGHT
14 #   Copyright (C) 2004  Craig Barratt
15 #
16 #   This program is free software; you can redistribute it and/or modify
17 #   it under the terms of the GNU General Public License as published by
18 #   the Free Software Foundation; either version 2 of the License, or
19 #   (at your option) any later version.
20 #
21 #   This program is distributed in the hope that it will be useful,
22 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
23 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 #   GNU General Public License for more details.
25 #
26 #   You should have received a copy of the GNU General Public License
27 #   along with this program; if not, write to the Free Software
28 #   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
29 #
30 #========================================================================
31 #
32 # Version 3.0.0alpha, released 23 Jan 2006.
33 #
34 # See http://backuppc.sourceforge.net.
35 #
36 #========================================================================
37
38 package BackupPC::Storage;
39
40 use strict;
41 use BackupPC::Storage::Text;
42 use Data::Dumper;
43
44 sub new
45 {
46     my $class = shift;
47     my($paths) = @_;
48     my $flds = {
49         BackupFields => [qw(
50                     num type startTime endTime
51                     nFiles size nFilesExist sizeExist nFilesNew sizeNew
52                     xferErrs xferBadFile xferBadShare tarErrs
53                     compress sizeExistComp sizeNewComp
54                     noFill fillFromNum mangle xferMethod level
55                     charset
56                 )],
57         RestoreFields => [qw(
58                     num startTime endTime result errorMsg nFiles size
59                     tarCreateErrs xferErrs
60                 )],
61         ArchiveFields => [qw(
62                     num startTime endTime result errorMsg
63                 )],
64     };
65
66     return BackupPC::Storage::Text->new($flds, $paths, @_);
67 }
68
69 #
70 # Writes per-backup information into the pc/nnn/backupInfo
71 # file to allow later recovery of the pc/backups file in
72 # cases when it is corrupted.
73 #
74 sub backupInfoWrite
75 {
76     my($class, $pcDir, $bkupNum, $bkupInfo, $force) = @_;
77
78     return if ( !$force && -f "$pcDir/$bkupNum/backupInfo" );
79     my($dump) = Data::Dumper->new(
80              [   $bkupInfo],
81              [qw(*backupInfo)]);
82     $dump->Indent(1);
83     if ( open(BKUPINFO, ">", "$pcDir/$bkupNum/backupInfo") ) {
84         print(BKUPINFO $dump->Dump);
85         close(BKUPINFO);
86     }
87 }
88
89 1;