for my $db (keys %{$db_ds}) { if (!@{$db_ds->{$db}} && !$opts{database}) { ### Our data stuctur says there is no native mysql tables. ### So we skip this database. next; } $dbh->do(qq{use $db}); ### The table list in our data structure is empty. The database ### option has been passed, so look them up. if (!@{$db_ds->{$db}}) { $queries{get_table_names}->execute(); while (my $rec = $queries{get_table_names}->fetchrow_hashref() +) { push @{$db_ds->{$db}}, $rec->{Name}; } debug(qq{Got table list for $db\n}); } ### This block makes sure we can actually access the tables. my @valid_tables; for my $table (@{$db_ds->{$db}}) { $queries{verify_table_name}->execute($table); if ($queries{verify_table_name}->rows()) { my ($rec) = $queries{verify_table_name}->fetchrow_array(); push @valid_tables, $rec; } else { debug(qq{There was a problem finding database/table $db $t +able\n}); } } ### Make sure we aren't running out of filesystem space. chk_space($max_disk_space); my $current_date = strftime("%Y-%m-%d", localtime); my $current_time = strftime("%H:%M:%S", localtime); my $dumpfile = '/backups/table_dumps/' . $db . '.' . $current_date . '.' . $current_time; my $valid_table_list = join ' ', @valid_tables; my $cmd = 'mysqldump -q --single-transaction --complete-insert -e' . ' ' . $db . ' ' . $valid_table_list . $bar_cmd . ' |'; debug(qq{Beginning dump of database: $db\n}); debug(qq{Running command: $cmd\n}); debug(qq{Logging to: $dumpfile\n}); open MYSQLDUMP, "$cmd" or die $!; open DUMPFILE, ">$dumpfile" or die $!; my $total_bytes = 0; while (my $bytes_read = read(MYSQLDUMP, my $buffer, 4096)) { $total_bytes += $bytes_read; print DUMPFILE $buffer; } close DUMPFILE; debug(qq{Finished dumping $db\n\n}); }
In reply to Using simultaneous threads by mhearse
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |