From b90be6b492e7e7533bdd83fb7f9dee36c6c2d8c3 Mon Sep 17 00:00:00 2001 From: Monika Komorowska <mk8@sanger.ac.uk> Date: Thu, 19 May 2011 09:24:02 +0000 Subject: [PATCH] *** empty log message *** --- .../populate_production_db_tables_v2.pl | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/misc-scripts/production_database/scripts/populate_production_db_tables_v2.pl b/misc-scripts/production_database/scripts/populate_production_db_tables_v2.pl index 59151175e5..0a54e629c0 100644 --- a/misc-scripts/production_database/scripts/populate_production_db_tables_v2.pl +++ b/misc-scripts/production_database/scripts/populate_production_db_tables_v2.pl @@ -205,16 +205,23 @@ my %data; if ($dumpout) { - my $file_path = $dumpout . "/" . $dbname . $table .'_bak.sql'; - open(BKUPFILE, ">$file_path") or die("Can't write to file $file_path\n"); - my $cmd = "mysqldump -h $host -u $user -p$pass $dbname $table"; - my $result = `$cmd`; - print BKUPFILE $result; - close BKUPFILE; - if ($result !~ /Dump completed/) { - print("back up failed, check file $file_path for details\n"); - } else { - print("$full_table_name_bak dumped out to file $file_path\n"); + # check if file exists + my $test_sql = "select count(1) from information_schema.tables where table_schema = ? and table_name = ?"; + my $test_sth = $dbh->prepare($test_sql); + $test_sth->execute($dbname, $table.'_bak'); + my ($table_exists) = $test_sth->fetchrow_array(); + if ($table_exists) { + my $file_path = $dumpout . "/" . $dbname . $table .'_bak.sql'; + open(BKUPFILE, ">$file_path") or die("Can't write to file $file_path\n"); + my $cmd = "mysqldump -h $host -u $user -p$pass $dbname $table". "_bak"; + my $result = `$cmd`; + print BKUPFILE $result; + close BKUPFILE; + if ($result !~ /Dump completed/) { + print("back up failed, check file $file_path for details\n"); + } else { + print("$full_table_name_bak dumped out to file $file_path\n"); + } } next; } -- GitLab