Last active
December 19, 2015 23:29
-
-
Save macintux/6035102 to your computer and use it in GitHub Desktop.
For use with large cluster-info files generated via riak-admin. Will split them into more manageable file sizes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use strict; | |
use warnings; | |
sub usage { | |
my ($errmsg) = @_; | |
my $msg = <<END; | |
Usage: split-info <info file> <output directory> | |
Takes a file with the output from `riak-admin cluster info` as the | |
first argument and a directory into which to dump new files as the | |
second argument. | |
END | |
$msg .= "\n Error: $errmsg\n" if (defined $errmsg && $errmsg); | |
$msg; | |
} | |
die usage() unless @ARGV == 2; | |
my $input_file = $ARGV[0]; | |
my $datadir = $ARGV[1]; | |
die usage("$input_file is not a readable file") unless -r $input_file; | |
die usage("$datadir is not a writeable directory") unless -d $datadir && -w $datadir; | |
my $node_name = 'unknown'; | |
my $node_ip = 'unknown'; | |
my $fh = undef; | |
open(IN, $input_file) || die "Cannot open $input_file for processing\n"; | |
while(<IN>) { | |
if (/^== Node.*'(.*)@(.*)'/) { | |
$node_name = $1; | |
$node_ip = $2; | |
next; | |
} | |
if (/^= (.*)/) { | |
my $filename = $1; | |
$filename =~ s/\W+/_/g; | |
$filename =~ s/_$//; # Drop any trailing _ | |
close($fh) if $fh; | |
$fh = undef; | |
$filename = sprintf("%s/%s-%s-%s.info", | |
$datadir, $node_ip, $node_name, $filename); | |
print "Opening $filename\n"; | |
open($fh, ">$filename"); | |
print $fh $_; | |
next; | |
} | |
if ($fh) { | |
print $fh $_; | |
} | |
} | |
close(IN); | |
close($fh) if $fh; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment