Commit 862c4750 authored by unknown's avatar unknown

Merge ramayana.hindu.god:/home/tsmith/m/bk/b28460/50

into  ramayana.hindu.god:/home/tsmith/m/bk/build/50


scripts/mysqlhotcopy.sh:
  Auto merged
parents 1bee6a3c 8224d684
...@@ -39,7 +39,7 @@ WARNING: THIS PROGRAM IS STILL IN BETA. Comments/patches welcome. ...@@ -39,7 +39,7 @@ WARNING: THIS PROGRAM IS STILL IN BETA. Comments/patches welcome.
# Documentation continued at end of file # Documentation continued at end of file
my $VERSION = "1.22"; my $VERSION = "1.23";
my $opt_tmpdir = $ENV{TMPDIR} || "/tmp"; my $opt_tmpdir = $ENV{TMPDIR} || "/tmp";
...@@ -132,7 +132,6 @@ GetOptions( \%opt, ...@@ -132,7 +132,6 @@ GetOptions( \%opt,
# 'target' - destination directory of the copy # 'target' - destination directory of the copy
# 'tables' - array-ref to list of tables in the db # 'tables' - array-ref to list of tables in the db
# 'files' - array-ref to list of files to be copied # 'files' - array-ref to list of files to be copied
# (RAID files look like 'nn/name.MYD')
# 'index' - array-ref to list of indexes to be copied # 'index' - array-ref to list of indexes to be copied
# #
...@@ -263,7 +262,6 @@ my $hc_locks = ""; ...@@ -263,7 +262,6 @@ my $hc_locks = "";
my $hc_tables = ""; my $hc_tables = "";
my $num_tables = 0; my $num_tables = 0;
my $num_files = 0; my $num_files = 0;
my $raid_dir_regex = '[A-Za-z0-9]{2}';
foreach my $rdb ( @db_desc ) { foreach my $rdb ( @db_desc ) {
my $db = $rdb->{src}; my $db = $rdb->{src};
...@@ -292,20 +290,12 @@ foreach my $rdb ( @db_desc ) { ...@@ -292,20 +290,12 @@ foreach my $rdb ( @db_desc ) {
or die "Cannot open dir '$db_dir': $!"; or die "Cannot open dir '$db_dir': $!";
my %db_files; my %db_files;
my @raid_dir = ();
while ( defined( my $name = readdir DBDIR ) ) { while ( defined( my $name = readdir DBDIR ) ) {
if ( $name =~ /^$raid_dir_regex$/ && -d "$db_dir/$name" ) { $db_files{$name} = $1 if ( $name =~ /(.+)\.\w+$/ );
push @raid_dir, $name;
}
else {
$db_files{$name} = $1 if ( $name =~ /(.+)\.\w+$/ );
}
} }
closedir( DBDIR ); closedir( DBDIR );
scan_raid_dir( \%db_files, $db_dir, @raid_dir );
unless( keys %db_files ) { unless( keys %db_files ) {
warn "'$db' is an empty database\n"; warn "'$db' is an empty database\n";
} }
...@@ -336,8 +326,6 @@ foreach my $rdb ( @db_desc ) { ...@@ -336,8 +326,6 @@ foreach my $rdb ( @db_desc ) {
my @hc_tables = map { quote_names("$db.$_") } @dbh_tables; my @hc_tables = map { quote_names("$db.$_") } @dbh_tables;
$rdb->{tables} = [ @hc_tables ]; $rdb->{tables} = [ @hc_tables ];
$rdb->{raid_dirs} = [ get_raid_dirs( $rdb->{files} ) ];
$hc_locks .= ", " if ( length $hc_locks && @hc_tables ); $hc_locks .= ", " if ( length $hc_locks && @hc_tables );
$hc_locks .= join ", ", map { "$_ READ" } @hc_tables; $hc_locks .= join ", ", map { "$_ READ" } @hc_tables;
$hc_tables .= ", " if ( length $hc_tables && @hc_tables ); $hc_tables .= ", " if ( length $hc_tables && @hc_tables );
...@@ -411,27 +399,24 @@ if ($opt{method} =~ /^cp\b/) ...@@ -411,27 +399,24 @@ if ($opt{method} =~ /^cp\b/)
retire_directory( @existing ) if @existing && !$opt{addtodest}; retire_directory( @existing ) if @existing && !$opt{addtodest};
foreach my $rdb ( @db_desc ) { foreach my $rdb ( @db_desc ) {
foreach my $td ( '', @{$rdb->{raid_dirs}} ) { my $tgt_dirpath = "$rdb->{target}";
# Remove trailing slashes (needed for Mac OS X)
my $tgt_dirpath = "$rdb->{target}/$td"; substr($tgt_dirpath, 1) =~ s|/+$||;
# Remove trailing slashes (needed for Mac OS X) if ( $opt{dryrun} ) {
substr($tgt_dirpath, 1) =~ s|/+$||; print "mkdir $tgt_dirpath, 0750\n";
if ( $opt{dryrun} ) { }
print "mkdir $tgt_dirpath, 0750\n"; elsif ($opt{method} =~ /^scp\b/) {
} ## assume it's there?
elsif ($opt{method} =~ /^scp\b/) { ## ...
## assume it's there? }
## ... else {
} mkdir($tgt_dirpath, 0750) or die "Can't create '$tgt_dirpath': $!\n"
else { unless -d $tgt_dirpath;
mkdir($tgt_dirpath, 0750) or die "Can't create '$tgt_dirpath': $!\n" if ($^O !~ m/^(NetWare)$/)
unless -d $tgt_dirpath; {
if ($^O !~ m/^(NetWare)$/) my @f_info= stat "$datadir/$rdb->{src}";
{ chown $f_info[4], $f_info[5], $tgt_dirpath;
my @f_info= stat "$datadir/$rdb->{src}"; }
chown $f_info[4], $f_info[5], $tgt_dirpath;
}
}
} }
} }
...@@ -489,7 +474,7 @@ foreach my $rdb ( @db_desc ) ...@@ -489,7 +474,7 @@ foreach my $rdb ( @db_desc )
my @files = map { "$datadir/$rdb->{src}/$_" } @{$rdb->{files}}; my @files = map { "$datadir/$rdb->{src}/$_" } @{$rdb->{files}};
next unless @files; next unless @files;
eval { copy_files($opt{method}, \@files, $rdb->{target}, $rdb->{raid_dirs} ); }; eval { copy_files($opt{method}, \@files, $rdb->{target}); };
push @failed, "$rdb->{src} -> $rdb->{target} failed: $@" push @failed, "$rdb->{src} -> $rdb->{target} failed: $@"
if ( $@ ); if ( $@ );
...@@ -582,7 +567,7 @@ exit 0; ...@@ -582,7 +567,7 @@ exit 0;
# --- # ---
sub copy_files { sub copy_files {
my ($method, $files, $target, $raid_dirs) = @_; my ($method, $files, $target) = @_;
my @cmd; my @cmd;
print "Copying ".@$files." files...\n" unless $opt{quiet}; print "Copying ".@$files." files...\n" unless $opt{quiet};
...@@ -603,15 +588,8 @@ sub copy_files { ...@@ -603,15 +588,8 @@ sub copy_files {
# add recursive option for scp # add recursive option for scp
$cp.= " -r" if $^O =~ /m^(solaris|linux|freebsd|darwin)$/ && $method =~ /^scp\b/; $cp.= " -r" if $^O =~ /m^(solaris|linux|freebsd|darwin)$/ && $method =~ /^scp\b/;
my @non_raid = map { "'$_'" } grep { ! m:/$raid_dir_regex/[^/]+$: } @$files; # perform the actual copy
safe_system( $cp, (map { "'$_'" } @$files), "'$target'" );
# add files to copy and the destination directory
safe_system( $cp, @non_raid, "'$target'" ) if (@non_raid);
foreach my $rd ( @$raid_dirs ) {
my @raid = map { "'$_'" } grep { m:$rd/: } @$files;
safe_system( $cp, @raid, "'$target'/$rd" ) if ( @raid );
}
} }
else else
{ {
...@@ -789,35 +767,6 @@ sub get_row_hash { ...@@ -789,35 +767,6 @@ sub get_row_hash {
return $sth->fetchrow_hashref(); return $sth->fetchrow_hashref();
} }
sub scan_raid_dir {
my ( $r_db_files, $data_dir, @raid_dir ) = @_;
local(*RAID_DIR);
foreach my $rd ( @raid_dir ) {
opendir(RAID_DIR, "$data_dir/$rd" )
or die "Cannot open dir '$data_dir/$rd': $!";
while ( defined( my $name = readdir RAID_DIR ) ) {
$r_db_files->{"$rd/$name"} = $1 if ( $name =~ /(.+)\.\w+$/ );
}
closedir( RAID_DIR );
}
}
sub get_raid_dirs {
my ( $r_files ) = @_;
my %dirs = ();
foreach my $f ( @$r_files ) {
if ( $f =~ m:^($raid_dir_regex)/: ) {
$dirs{$1} = 1;
}
}
return sort keys %dirs;
}
sub get_list_of_tables { sub get_list_of_tables {
my ( $db ) = @_; my ( $db ) = @_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment