From cd3d13a70b02243cfa8c60abf6a549057e7adba5 Mon Sep 17 00:00:00 2001
From: Andrew Yates <ayates@ebi.ac.uk>
Date: Thu, 1 Dec 2011 11:55:12 +0000
Subject: [PATCH] Adding a dry mode which just reports the databases it would
 have dumped

---
 misc-scripts/db/dump_mysql.pl | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/misc-scripts/db/dump_mysql.pl b/misc-scripts/db/dump_mysql.pl
index 5892dd8bd0..35d10dbaba 100755
--- a/misc-scripts/db/dump_mysql.pl
+++ b/misc-scripts/db/dump_mysql.pl
@@ -26,7 +26,8 @@ sub run {
   $self->logging();
   $self->check();
   $self->defaults();
-  $self->process();
+  $self->dry() if $self->opts()->{dry};
+  $self->process() if ! $self->opts()->{dry};
 
   if ($self->{oldfh}) {
     select($self->{oldfh});
@@ -41,6 +42,7 @@ sub args {
     $opts, qw/
       defaults=s
       version=i
+      dry
       host=s
       port=i
       username=s
@@ -219,10 +221,20 @@ sub defaults {
   $self->v(q{Working %d database(s)}, $db_count);
 
   $o->{databases} = [ sort { $a cmp $b } @{ $o->{databases} } ];
+  
+  $o->{verbose} = 1 if $o->{dry};
 
   return;
 }
 
+sub dry {
+  my ($self) = @_;
+  my $databases = $self->opts()->{databases};
+  my $list = join(q{,}, @{$databases});
+  $self->v(q{The following databases would have been dumped [%s]}, $list);
+  return;
+}
+
 sub process {
   my ($self) = @_;
   my $databases = $self->opts()->{databases};
@@ -495,7 +507,6 @@ sub _set_opts_from_hostname {
   $o->{port}     = $settings->{port};
 
   if (!$o->{databases}) {
-    warn $settings->{pattern};
     $o->{databases} = $self->_all_dbs($settings->{pattern});
   }
 
@@ -597,6 +608,8 @@ dump_mysql.pl
   #Using defaults ini file
   ./dump_mysql.pl --defaults my.ini --username root --password p --version 64
   
+  ./dump_mysql.pl --defaults my.ini --username root --password p --version 64 -dry
+  
   ./dump_mysql.pl --defaults my.ini --username root --password p --version 64 --tables dna
   
   ./dump_mysql.pl --defaults my.ini --username root --password p --version 64 --tables meta,meta_coord --tables analysis --groups core,otherfeatures --groups vega
@@ -707,6 +720,11 @@ If given the script will write all logs to output. Switches on C<--verbose>
 Force the use of Perl's GZip libraries rather than using external zipping 
 like pigz.
 
+=item B<--dry>
+
+If specified the script will list all databases which have been found and
+will be dumped but will not run any dumping process.
+
 =item B<--help>
 
 Help message
-- 
GitLab