mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / ndb / tools / ndb_error_reporter
blob7fb9845dba0d403fd3f2dadcce7849b4d218d825
1 #!/usr/bin/perl -w
3 # Copyright (c) 2005-2007 MySQL AB
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; version 2 of the License.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18 use strict;
20 if(@ARGV < 1)
22 print STDERR "Usage:\n";
23 print STDERR "\tndb_error_reporter config.ini [username] [--fs]\n\n";
24 print STDERR "\tusername is a user that you can use to ssh into\n";
25 print STDERR "\t all of your nodes with.\n\n";
26 print STDERR "\t--fs means include the filesystems in the report\n";
27 print STDERR "\t WARNING: This may require a lot of disk space.\n";
28 print STDERR "\t Only use this option when asked to.\n\n";
29 exit(1);
32 my $config_file= $ARGV[0];
33 my $config_get_fs= 0;
34 my $config_username= '';
35 if(defined($ARGV[1]))
37 $config_get_fs= 1 if $ARGV[1] eq '--fs';
38 $config_username= $ARGV[1].'@' if $ARGV[1] ne '--fs';
39 $config_get_fs= (defined $ARGV[2] && $ARGV[2] eq '--fs')?1:$config_get_fs;
42 if(!stat($config_file))
44 print STDERR "Cannot open configuration file.\n\n";
45 exit(1);
48 my @nodes= split ' ',`ndb_config --config-file=$ARGV[0] --nodes --query=id --type=ndbd`;
50 push @nodes, split ' ',`ndb_config --config-file=$ARGV[0] --nodes --query=id --type=ndb_mgmd`;
52 sub config {
53 my $nodeid= shift;
54 my $query= shift;
55 my $res= `ndb_config --config-file=$ARGV[0] --id=$nodeid --query=$query`;
56 chomp $res;
57 $res;
60 my @t= localtime();
61 my $reportdir= sprintf('ndb_error_report_%u%02u%02u%02u%02u%02u',
62 ($t[5]+1900),($t[4]+1),$t[3],$t[2],$t[1],$t[0]);
64 if(stat($reportdir) || stat($reportdir.'tar.bz2'))
66 print STDERR "It looks like another ndb_error_report process is running.\n";
67 print STDERR "If that is not the case, remove the ndb_error_report directory";
68 print STDERR " and run ndb_error_report again.\n\n";
69 exit(1);
72 mkdir($reportdir);
74 foreach my $node (@nodes)
76 print "\n\n Copying data from node $node".
77 (($config_get_fs)?" with filesystem":"").
78 "\n\n";
79 my $recurse= ($config_get_fs)?'-r ':'';
80 system 'scp -p '.$recurse.$config_username.config($node,'host').
81 ':'.config($node,'datadir')."/ndb_".$node."* ".
82 "$reportdir/\n";
85 print "\n\n Copying configuration file...\n\n\t$config_file\n\n";
86 system "cp -p $config_file $reportdir/";
88 my $r = system 'bzip2 2>&1 > /dev/null < /dev/null';
89 my $outfile;
90 if($r==0)
92 $outfile= "$reportdir.tar.bz2";
93 system "tar c $reportdir|bzip2 > $outfile";
95 else
97 $outfile= "$reportdir.tar.gz";
98 system "tar c $reportdir|gzip > $outfile";
101 system "rm -rf $reportdir";
103 print "\n\nPlease attach $outfile to your error report\n\n";