1 package BackupPC::Config::Text;
7 use base 'BackupPC::Config';
11 my($self, $host) = @_;
12 local(*BK_INFO, *LOCK);
15 flock(LOCK, LOCK_EX) if open(LOCK, "$self->{TopDir}/pc/$host/LOCK");
16 if ( open(BK_INFO, "$self->{TopDir}/pc/$host/backups") ) {
19 next if ( !/^(\d+\t(incr|full)[\d\t]*$)/ );
21 @{$Backups[@Backups]}{@{$self->{BackupFields}}} = split(/\t/);
31 my($self, $host, @Backups) = @_;
32 local(*BK_INFO, *LOCK);
35 flock(LOCK, LOCK_EX) if open(LOCK, "$self->{TopDir}/pc/$host/LOCK");
36 unlink("$self->{TopDir}/pc/$host/backups.old")
37 if ( -f "$self->{TopDir}/pc/$host/backups.old" );
38 rename("$self->{TopDir}/pc/$host/backups",
39 "$self->{TopDir}/pc/$host/backups.old")
40 if ( -f "$self->{TopDir}/pc/$host/backups" );
41 if ( open(BK_INFO, ">$self->{TopDir}/pc/$host/backups") ) {
42 for ( $i = 0 ; $i < @Backups ; $i++ ) {
43 my %b = %{$Backups[$i]};
44 printf(BK_INFO "%s\n", join("\t", @b{@{$self->{BackupFields}}}));
53 my($self, $host) = @_;
54 local(*RESTORE_INFO, *LOCK);
57 flock(LOCK, LOCK_EX) if open(LOCK, "$self->{TopDir}/pc/$host/LOCK");
58 if ( open(RESTORE_INFO, "$self->{TopDir}/pc/$host/restores") ) {
59 while ( <RESTORE_INFO> ) {
61 next if ( !/^(\d+.*)/ );
63 @{$Restores[@Restores]}{@{$self->{RestoreFields}}} = split(/\t/);
73 my($self, $host, @Restores) = @_;
74 local(*RESTORE_INFO, *LOCK);
77 flock(LOCK, LOCK_EX) if open(LOCK, "$self->{TopDir}/pc/$host/LOCK");
78 unlink("$self->{TopDir}/pc/$host/restores.old")
79 if ( -f "$self->{TopDir}/pc/$host/restores.old" );
80 rename("$self->{TopDir}/pc/$host/restores",
81 "$self->{TopDir}/pc/$host/restores.old")
82 if ( -f "$self->{TopDir}/pc/$host/restores" );
83 if ( open(RESTORE_INFO, ">$self->{TopDir}/pc/$host/restores") ) {
84 for ( $i = 0 ; $i < @Restores ; $i++ ) {
85 my %b = %{$Restores[$i]};
86 printf(RESTORE_INFO "%s\n",
87 join("\t", @b{@{$self->{RestoreFields}}}));
96 my($self, $host) = @_;
97 my($ret, $mesg, $config, @configs);
102 push(@configs, "$self->{TopDir}/conf/config.pl");
103 push(@configs, "$self->{TopDir}/pc/$host/config.pl")
104 if ( defined($host) && -f "$self->{TopDir}/pc/$host/config.pl" );
105 foreach $config ( @configs ) {
107 if ( !defined($ret = do $config) && ($! || $@) ) {
108 $mesg = "Couldn't open $config: $!" if ( $! );
109 $mesg = "Couldn't execute $config: $@" if ( $@ );
110 $mesg =~ s/[\n\r]+//;
113 %{$self->{Conf}} = ( %{$self->{Conf} || {}}, %Conf );
116 #$mesg = $self->CheckConfigInfo;
117 #return $mesg if $mesg;
119 return if ( !defined($self->{Conf}{Language}) );
121 my $langFile = "$self->{LibDir}/BackupPC/Lang/$self->{Conf}{Language}.pm";
123 if ( !defined($ret = do $langFile) && ($! || $@) ) {
124 $mesg = "Couldn't open language file $langFile: $!" if ( $! );
125 $mesg = "Couldn't execute language file $langFile: $@" if ( $@ );
126 $mesg =~ s/[\n\r]+//;
131 $self->{Lang} = \%Lang;
138 # Return the mtime of the config file
143 return (stat("$self->{TopDir}/conf/config.pl"))[9];
147 # Returns information from the host file in $self->{TopDir}/conf/hosts.
148 # With no argument a ref to a hash of hosts is returned. Each
149 # hash contains fields as specified in the hosts file. With an
150 # argument a ref to a single hash is returned with information
151 # for just that host.
155 my($self, $host) = @_;
156 my(%hosts, @hdr, @fld);
159 if ( !open(HOST_INFO, "$self->{TopDir}/conf/hosts") ) {
160 print(STDERR $self->timeStamp,
161 "Can't open $self->{TopDir}/conf/hosts\n");
164 while ( <HOST_INFO> ) {
168 next if ( /^\s*$/ || !/^([\w\.-]+\s+.*)/ );
169 @fld = split(/\s+/, $1);
171 if ( defined($host) ) {
172 next if ( lc($fld[0]) ne $host );
173 @{$hosts{lc($fld[0])}}{@hdr} = @fld;
177 @{$hosts{lc($fld[0])}}{@hdr} = @fld;
188 # Return the mtime of the hosts file
193 return (stat("$self->{TopDir}/conf/hosts"))[9];