"Fossies" - the Fresh Open Source Software Archive

Member "BackupPC-4.4.0/lib/BackupPC/Storage.pm" (20 Jun 2020, 2918 Bytes) of package /linux/privat/BackupPC-4.4.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Storage.pm" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 4.3.2_vs_4.4.0.

    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-2020  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 3 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, see <http://www.gnu.org/licenses/>.
   28 #
   29 #========================================================================
   30 #
   31 # Version 4.4.0, released 20 Jun 2020.
   32 #
   33 # See http://backuppc.sourceforge.net.
   34 #
   35 #========================================================================
   36 
   37 package BackupPC::Storage;
   38 
   39 use strict;
   40 use BackupPC::Storage::Text;
   41 use Data::Dumper;
   42 
   43 sub new
   44 {
   45     my $class  = shift;
   46     my($paths) = @_;
   47     my $flds   = {
   48         BackupFields => [qw(
   49             num type startTime endTime nFiles size nFilesExist sizeExist
   50             nFilesNew sizeNew xferErrs xferBadFile xferBadShare tarErrs
   51             compress sizeExistComp sizeNewComp noFill fillFromNum mangle
   52             xferMethod level charset version inodeLast keep share2path
   53             comment
   54         )],
   55         RestoreFields => [qw(
   56             num startTime endTime result errorMsg nFiles size
   57             tarCreateErrs xferErrs
   58         )],
   59         ArchiveFields => [qw(
   60             num startTime endTime result errorMsg
   61         )],
   62     };
   63 
   64     return BackupPC::Storage::Text->new($flds, $paths, @_);
   65 }
   66 
   67 #
   68 # Writes per-backup information into the pc/nnn/backupInfo
   69 # file to allow later recovery of the pc/backups file in
   70 # cases when it is corrupted.
   71 #
   72 # Also updates the directory mtime to reflect the backup
   73 # finish time.
   74 #
   75 sub backupInfoWrite
   76 {
   77     my($class, $pcDir, $bkupNum, $bkupInfo, $force) = @_;
   78     my $bkupFd;
   79 
   80     return if ( !$force && -f "$pcDir/$bkupNum/backupInfo" );
   81     my($dump) = Data::Dumper->new([$bkupInfo], [qw(*backupInfo)]);
   82     $dump->Indent(1);
   83     $dump->Sortkeys(1);
   84     if ( open($bkupFd, ">", "$pcDir/$bkupNum/backupInfo") ) {
   85         print($bkupFd $dump->Dump);
   86         close($bkupFd);
   87     } else {
   88         print("backupInfoWrite: can't open/create $pcDir/$bkupNum/backupInfo\n");
   89     }
   90     utime($bkupInfo->{endTime}, $bkupInfo->{endTime}, "$pcDir/$bkupNum")
   91       if ( defined($bkupInfo->{endTime}) );
   92 }
   93 
   94 1;