add wip buildscripts for automated experiment execution
This commit is contained in:
62
scripts/dropdb.pl
Executable file
62
scripts/dropdb.pl
Executable file
@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use diagnostics;
|
||||
|
||||
use Net::OpenSSH;
|
||||
use DBI;
|
||||
|
||||
use feature 'say';
|
||||
|
||||
my $local_root = '/home/christoph/Notes/TU/MastersThesis/FailNix';
|
||||
|
||||
my $remote_host = 'mars'; # smchurla@mars.cs.tu-dortmund.de
|
||||
|
||||
# The mars db is bound to local port 3306 over SSH.
|
||||
# - This requires using the configured 'mars'
|
||||
# remote_host instead of smchurla@mars
|
||||
# or setting up another tunnel here
|
||||
my $db_host = "127.0.0.1";
|
||||
my $db_port = "3306";
|
||||
my $db_user = "smchurla";
|
||||
|
||||
# Database password
|
||||
open( my $fhandle, '<', "$local_root/mars-db.conf" )
|
||||
or die "Failed to read mars-db.conf: $!";
|
||||
chomp( my $db_password = <$fhandle> );
|
||||
close($fhandle);
|
||||
|
||||
# Initialize SSH connection
|
||||
# - This connection also sets up the database tunnel
|
||||
my $ssh = Net::OpenSSH->new(
|
||||
$remote_host,
|
||||
timeout => 30,
|
||||
master_opts => [
|
||||
-o => 'BatchMode=yes',
|
||||
-o => 'StrictHostKeyChecking=accept-new',
|
||||
],
|
||||
);
|
||||
$ssh->error and die 'SSH connection failed: ' . $ssh->error;
|
||||
say 'Connected to mars.cs.tu-dortmund.de';
|
||||
|
||||
# Initialize db connection
|
||||
my $dbh = DBI->connect( "DBI:MariaDB:host=$db_host;port=$db_port",
|
||||
$db_user, $db_password )
|
||||
or die 'Failed to connect to database: ' . $DBI::errstr;
|
||||
say 'Connected to database';
|
||||
|
||||
say 'Existing databases:';
|
||||
my @db_names =
|
||||
sort
|
||||
map { s/DBI:MariaDB://r }
|
||||
grep { !/information_schema|smchurla_ll/ } $dbh->data_sources();
|
||||
foreach (@db_names) { say " - $_"; }
|
||||
|
||||
print 'Enter name to delete: ';
|
||||
my $db_sel = <STDIN>;
|
||||
chomp $db_sel;
|
||||
$dbh->do("drop database `$db_sel`")
|
||||
or die "Failed to drop database: " . $dbh->errstr;
|
||||
|
||||
$dbh->disconnect or warn $dbh->errstr;
|
||||
Reference in New Issue
Block a user