Changeset 214 for trunk

Show
Ignore:
Timestamp:
01/14/11 21:31:01 (3 years ago)
Author:
depesz
Message:

1. Fix typo in changes.pod
2. perltidy over sources

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/omnipitr/doc/changes.pod

    r213 r214  
    77=item * Locate any tablespaces in the data dir and include them in the backup 
    88for both masters and slaves.  In the tar file these will be placed under the 
    9 'tablespace' directory. 
     9'tablespaces' directory. 
    1010 
    1111=back 
  • trunk/omnipitr/lib/OmniPITR/Pidfile.pm

    r117 r214  
    66require File::Spec; 
    77 
    8 sub new 
    9 
     8sub new { 
    109    my $class = shift; 
    11     my %args = @_; 
    12     my $self = bless \%args, $class; 
    13     unless ( $self->{pidfile} ) 
    14     { 
     10    my %args  = @_; 
     11    my $self  = bless \%args, $class; 
     12    unless ( $self->{ pidfile } ) { 
    1513        my $basename = basename( $0 ); 
    1614        my $dir = -w "/var/run" ? "/var/run" : File::Spec->tmpdir(); 
     
    1816        $pidfile = "$dir/$basename.pid"; 
    1917        $self->_verbose( "pidfile: $pidfile\n" ); 
    20         $self->{pidfile} = $pidfile; 
     18        $self->{ pidfile } = $pidfile; 
    2119    } 
    2220    $self->_create_pidfile(); 
     
    2422} 
    2523 
    26 sub DESTROY 
    27 
     24sub DESTROY { 
    2825    my $self = shift; 
    2926    $self->_destroy_pidfile(); 
    3027} 
    3128 
    32 sub pidfile 
    33 
    34     my $self = shift; 
    35     return $self->{pidfile}; 
    36 
    37  
    38 sub _verbose 
    39 
    40     my $self = shift; 
    41     return unless $self->{verbose}; 
     29sub pidfile { 
     30    my $self = shift; 
     31    return $self->{ pidfile }; 
     32
     33 
     34sub _verbose { 
     35    my $self = shift; 
     36    return unless $self->{ verbose }; 
    4237    print STDERR @_; 
    4338} 
    4439 
    45 sub _get_pid 
    46 
    47     my $self = shift; 
    48     my $pidfile = $self->{pidfile}; 
     40sub _get_pid { 
     41    my $self    = shift; 
     42    my $pidfile = $self->{ pidfile }; 
    4943    $self->_verbose( "get pid from $pidfile\n" ); 
    5044    open( PID, $pidfile ) or die "can't read pid file $pidfile\n"; 
     
    5852} 
    5953 
    60 sub _is_running 
    61 
     54sub _is_running { 
    6255    my $pid = shift; 
    63     return kill(0, $pid); 
    64 
    65  
    66 sub _create_pidfile 
    67 
    68     my $self = shift; 
    69     my $pidfile = $self->{pidfile}; 
    70     if ( -e $pidfile ) 
    71     { 
     56    return kill( 0, $pid ); 
     57
     58 
     59sub _create_pidfile { 
     60    my $self    = shift; 
     61    my $pidfile = $self->{ pidfile }; 
     62    if ( -e $pidfile ) { 
    7263        $self->_verbose( "pidfile $pidfile exists\n" ); 
    7364        my $pid = $self->_get_pid(); 
    7465        $self->_verbose( "pid in pidfile $pidfile = $pid\n" ); 
    75         if ( _is_running( $pid ) ) 
    76         { 
    77             if ( $self->{silent} ) 
    78             { 
     66        if ( _is_running( $pid ) ) { 
     67            if ( $self->{ silent } ) { 
    7968                exit; 
    8069            } 
    81             else 
    82             { 
     70            else { 
    8371                die "$0 already running: $pid ($pidfile)\n"; 
    8472            } 
    8573        } 
    86         else 
    87         { 
     74        else { 
    8875            $self->_verbose( "$pid has died - replacing pidfile\n" ); 
    8976            open( PID, ">$pidfile" ) or die "Can't write to $pidfile\n"; 
     
    9279        } 
    9380    } 
    94     else 
    95     { 
     81    else { 
    9682        $self->_verbose( "no pidfile $pidfile\n" ); 
    9783        open( PID, ">$pidfile" ) or die "Can't write to $pidfile\n"; 
     
    10288        $self->_verbose( "pidfile $pidfile created\n" ); 
    10389    } 
    104     $self->{created} = 1; 
    105 
    106  
    107 sub _destroy_pidfile 
    108 
    109     my $self = shift; 
    110  
    111     return unless $self->{created}; 
    112     my $pidfile = $self->{pidfile}; 
     90    $self->{ created } = 1; 
     91
     92 
     93sub _destroy_pidfile { 
     94    my $self = shift; 
     95 
     96    return unless $self->{ created }; 
     97    my $pidfile = $self->{ pidfile }; 
    11398    $self->_verbose( "destroy $pidfile\n" ); 
    114     unless ( $pidfile and -e $pidfile ) 
    115     { 
     99    unless ( $pidfile and -e $pidfile ) { 
    116100        die "pidfile $pidfile doesn't exist\n"; 
    117101    } 
    118102    my $pid = $self->_get_pid(); 
    119103    $self->_verbose( "pid in $pidfile = $pid\n" ); 
    120     if ( $pid == $$ ) 
    121     { 
     104    if ( $pid == $$ ) { 
    122105        $self->_verbose( "remove pidfile: $pidfile\n" ); 
    123106        unlink( $pidfile ) if $pidfile and -e $pidfile; 
    124107    } 
    125     else 
    126     { 
    127         $self->_verbose(  "$pidfile not my pidfile - maybe my parents?\n" ); 
     108    else { 
     109        $self->_verbose( "$pidfile not my pidfile - maybe my parents?\n" ); 
    128110        my $ppid = getppid(); 
    129         $self->_verbose(  "parent pid = $ppid\n" ); 
    130         if ( $ppid != $pid ) 
    131         { 
     111        $self->_verbose( "parent pid = $ppid\n" ); 
     112        if ( $ppid != $pid ) { 
    132113            die "pid $pid in $pidfile is not mine ($$) - I am $0 - or my parents ($ppid)\n"; 
    133114        } 
     
    213194#------------------------------------------------------------------------------ 
    214195 
    215  
    216196#------------------------------------------------------------------------------ 
    217197# 
  • trunk/omnipitr/lib/OmniPITR/Program.pm

    r185 r214  
    172172 
    173173sub get_control_data { 
    174     my $self = shift; 
     174    my $self         = shift; 
    175175    my $control_data = {}; 
    176176 
  • trunk/omnipitr/lib/OmniPITR/Program/Backup.pm

    r213 r214  
    150150    # Identify any tablespaces and get those 
    151151    my $tablespace_dir = File::Spec->catfile( $self->{ 'data-dir' }, "pg_tblspc" ); 
    152     my (%tablespaces, @transform_regexs); 
    153     if( -e $tablespace_dir ) { 
     152    my ( %tablespaces, @transform_regexs ); 
     153    if ( -e $tablespace_dir ) { 
    154154        my @pgfiles; 
    155155        opendir( my $dh, $tablespace_dir ) or $self->log->fatal( "Unable to open tablespace directory $tablespace_dir" ); 
     156 
    156157        # Push onto our list the locations that are pointed to by the pg_tblspc symlinks 
    157158        foreach my $filename ( readdir $dh ) { 
    158             next if $filename !~ /^\d+$/; # Filename should be all numeric 
     159            next if $filename !~ /^\d+$/;    # Filename should be all numeric 
    159160            my $full_name = File::Spec->catfile( $tablespace_dir, $filename ); 
    160             next if ! -l $full_name;  # It should be a symbolic link 
     161            next if !-l $full_name;          # It should be a symbolic link 
    161162            my $link = readlink $full_name; 
    162             push @pgfiles, $link if $link;  # If it's a valid link, put it onto the list 
     163            push @pgfiles, $link if $link;    # If it's a valid link, put it onto the list 
    163164        } 
    164165        closedir $dh; 
     166 
    165167        # At this point pgfiles contains a list of the destinations.  Some of THOSE might be links however and need 
    166168        # to be identified since we need to pass the actual location bottom location to tar 
    167         %tablespaces = map { $_ => Cwd::abs_path($_) } @pgfiles; 
     169        %tablespaces = map { $_ => Cwd::abs_path( $_ ) } @pgfiles; 
     170 
    168171        # Populate the regexes to put these directories under tablespaces with transforms so that the actual physical location 
    169172        # is transformed into the 1-level deep link that the pg_tblspc files are pointing at.  We substr becase tar strips leading / 
    170         push @transform_regexs, map {"s,^" . substr($tablespaces{$_},1) . ",tablespaces$_," } keys %tablespaces
    171     } 
    172     $self->log->log("Including tablespaces: " . (join ", ",(keys %tablespaces))  . "\n") if $self->verbose && keys %tablespaces; 
     173        push @transform_regexs, map { "s,^" . substr( $tablespaces{ $_ }, 1 ) . ",tablespaces$_," } keys %tablespaces
     174    } 
     175    $self->log->log( "Including tablespaces: " . ( join ", ", ( keys %tablespaces ) ) . "\n" ) if $self->verbose && keys %tablespaces; 
    173176 
    174177    return ( [ values %tablespaces ], \@transform_regexs ); 
     
    249252 
    250253    if ( $ARGS{ 'transform' } ) { 
    251         if( ref $ARGS{ 'transform' } ) { 
     254        if ( ref $ARGS{ 'transform' } ) { 
    252255            push @compression_command, map { '--transform=' . $_ } @{ $ARGS{ 'transform' } }; 
    253         } else { 
     256        } 
     257        else { 
    254258            push @compression_command, '--transform=' . $ARGS{ 'transform' }; 
    255259        } 
  • trunk/omnipitr/lib/OmniPITR/Program/Backup/Master.pm

    r213 r214  
    154154    } 
    155155 
    156     my ($tablespaces, $transforms) = $self->get_tablespaces_and_transforms(); 
     156    my ( $tablespaces, $transforms ) = $self->get_tablespaces_and_transforms(); 
    157157    push @{ $tablespaces }, basename( $self->{ 'data-dir' } ); 
    158158 
    159159    $self->tar_and_compress( 
    160         'work_dir' => dirname( $self->{ 'data-dir' } ), 
    161         'tar_dir'  => $tablespaces, 
    162         'excludes' => \@excludes, 
    163         'transform'=> $transforms, 
     160        'work_dir' => dirname( $self->{ 'data-dir' } ), 
     161        'tar_dir'  => $tablespaces, 
     162        'excludes' => \@excludes, 
     163        'transform' => $transforms, 
    164164    ); 
    165165 
     
    379379 
    380380    $self->log->fatal( 'Data-dir was not provided!' ) unless defined $self->{ 'data-dir' }; 
    381     $self->{'data-dir'} =~ s{/+$}{}; 
     381    $self->{ 'data-dir' } =~ s{/+$}{}; 
    382382    $self->log->fatal( 'Provided data-dir (%s) does not exist!',   $self->{ 'data-dir' } ) unless -e $self->{ 'data-dir' }; 
    383383    $self->log->fatal( 'Provided data-dir (%s) is not directory!', $self->{ 'data-dir' } ) unless -d $self->{ 'data-dir' }; 
  • trunk/omnipitr/lib/OmniPITR/Program/Backup/Slave.pm

    r213 r214  
    269269    } 
    270270 
    271     my ($tablespaces, $transforms) = $self->get_tablespaces_and_transforms(); 
     271    my ( $tablespaces, $transforms ) = $self->get_tablespaces_and_transforms(); 
    272272    push @{ $tablespaces }, basename( $self->{ 'data-dir' } ), File::Spec->catfile( $self->{ 'temp-dir' }, 'backup_label' ); 
    273273    push @{ $transforms }, $transform_command;