Changeset 213

Show
Ignore:
Timestamp:
01/14/11 21:27:49 (3 years ago)
Author:
brian
Message:

tid14898 - add tablespace support to Backup

Files:

Legend:

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

    r210 r213  
    11=head1 OmniPITR 
     2 
     3=head2 2011-01-14 
     4 
     5=over 
     6 
     7=item * Locate any tablespaces in the data dir and include them in the backup 
     8for both masters and slaves.  In the tar file these will be placed under the 
     9'tablespace' directory. 
     10 
     11=back 
    212 
    313=head2 2011-01-12 
  • trunk/omnipitr/lib/OmniPITR/Program/Backup.pm

    r210 r213  
    135135} 
    136136 
     137=head1 get_tablespaces_and_transforms() 
     138 
     139Helper function.  Takes no arguments.  Uses pg_tblspc directory and returns 
     140a listref of the physical locations for tar to include in the backup as well 
     141as a listref of the transform regexs that it will need to apply in order for 
     142those directories to get untarred to the correct location from pg_tblspc's 
     143perspective. 
     144 
     145=cut 
     146 
     147sub get_tablespaces_and_transforms { 
     148    my $self = shift; 
     149 
     150    # Identify any tablespaces and get those 
     151    my $tablespace_dir = File::Spec->catfile( $self->{ 'data-dir' }, "pg_tblspc" ); 
     152    my (%tablespaces, @transform_regexs); 
     153    if( -e $tablespace_dir ) { 
     154        my @pgfiles; 
     155        opendir( my $dh, $tablespace_dir ) or $self->log->fatal( "Unable to open tablespace directory $tablespace_dir" ); 
     156        # Push onto our list the locations that are pointed to by the pg_tblspc symlinks 
     157        foreach my $filename ( readdir $dh ) { 
     158            next if $filename !~ /^\d+$/; # Filename should be all numeric 
     159            my $full_name = File::Spec->catfile( $tablespace_dir, $filename ); 
     160            next if ! -l $full_name;  # It should be a symbolic link 
     161            my $link = readlink $full_name; 
     162            push @pgfiles, $link if $link;  # If it's a valid link, put it onto the list 
     163        } 
     164        closedir $dh; 
     165        # At this point pgfiles contains a list of the destinations.  Some of THOSE might be links however and need 
     166        # to be identified since we need to pass the actual location bottom location to tar 
     167        %tablespaces = map { $_ => Cwd::abs_path($_) } @pgfiles; 
     168        # Populate the regexes to put these directories under tablespaces with transforms so that the actual physical location 
     169        # 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 
     174    return ( [ values %tablespaces ], \@transform_regexs ); 
     175} 
     176 
    137177=head1 get_archive_filename() 
    138178 
     
    209249 
    210250    if ( $ARGS{ 'transform' } ) { 
    211         push @compression_command, '--transform=' . $ARGS{ 'transform' }; 
     251        if( ref $ARGS{ 'transform' } ) { 
     252            push @compression_command, map { '--transform=' . $_ } @{ $ARGS{ 'transform' } }; 
     253        } else { 
     254            push @compression_command, '--transform=' . $ARGS{ 'transform' }; 
     255        } 
    212256    } 
    213257 
  • trunk/omnipitr/lib/OmniPITR/Program/Backup/Master.pm

    r186 r213  
    154154    } 
    155155 
     156    my ($tablespaces, $transforms) = $self->get_tablespaces_and_transforms(); 
     157    push @{ $tablespaces }, basename( $self->{ 'data-dir' } ); 
     158 
    156159    $self->tar_and_compress( 
    157160        'work_dir' => dirname( $self->{ 'data-dir' } ), 
    158         'tar_dir'  => [ basename( $self->{ 'data-dir' } ) ]
     161        'tar_dir'  => $tablespaces
    159162        'excludes' => \@excludes, 
     163        'transform'=> $transforms, 
    160164    ); 
    161165 
  • trunk/omnipitr/lib/OmniPITR/Program/Backup/Slave.pm

    r179 r213  
    269269    } 
    270270 
     271    my ($tablespaces, $transforms) = $self->get_tablespaces_and_transforms(); 
     272    push @{ $tablespaces }, basename( $self->{ 'data-dir' } ), File::Spec->catfile( $self->{ 'temp-dir' }, 'backup_label' ); 
     273    push @{ $transforms }, $transform_command; 
     274 
    271275    $self->tar_and_compress( 
    272276        'work_dir'  => dirname( $self->{ 'data-dir' } ), 
    273         'tar_dir'   => [ basename( $self->{ 'data-dir' } ), File::Spec->catfile( $self->{ 'temp-dir' }, 'backup_label' ) ]
     277        'tar_dir'   => $tablespaces
    274278        'excludes'  => [ map { sprintf( '%s/%s', basename( $self->{ 'data-dir' } ), $_ ) } @excludes ], 
    275         'transform' => $transform_command
     279        'transform' => $transforms
    276280    ); 
    277281