Commit b0b17ec9 authored by Leigh Stoller's avatar Leigh Stoller

Convert from Mysql to DBI; all of these scripts are non-critical and

they can just convert directly over.
parent 7f775c7d
#!/usr/bin/perl -wT
#
# EMULAB-COPYRIGHT
# Copyright (c) 2005 University of Utah and the Flux Group.
# Copyright (c) 2005-2011 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
use Mysql;
use libtbdb;
#
# usage: dumperrorlog.proxy
......@@ -78,17 +78,10 @@ else {
fatal("Bad characters in password!");
}
my $DB = Mysql->connect('localhost', $DBNAME, $DBUSER, $pwd);
fatal("Could not connect to errorlog DB!")
if (!defined($DB));
my $query_result =
$DB->query("load data infile '${tempfile}.${tablename}' ".
"replace into table $tablename");
if (! defined($query_result)) {
fatal("DB Error: " . $DB->errstr . "\n");
if (TBDBConnect($DBNAME, $DBUSER, $pwd) < 0) {
fatal("Could not connect to errorlog database!");
}
DBQueryFatal("load data infile '${tempfile}.${tablename}' ".
"replace into table $tablename");
exit(0);
......@@ -42,6 +42,8 @@ sub TBDBConnect($) { return emdbi::TBDBConnect($_[0], $DBNAME); }
sub TBDBReconnect($) { return emdbi::TBDBReconnect($_[0]); }
sub TBDBDisconnect() { return emdbi::TBDBDisconnect(); }
sub NewTBDBHandle() { return emdbi::NewTBDBHandle($DBNAME); }
sub DBHandle() { return emdbi::DBHandleN(0); }
sub DBHandleN($) { return emdbi::DBHandleN($_[0]); }
sub DBQueryN($$) { return emdbi::DBQueryN($_[0], $_[1]); }
sub DBQuery($) { return emdbi::DBQuery($_[0]); }
sub DBQueryFatalN($$) { return emdbi::DBQueryFatalN($_[0], $_[1]); }
......
......@@ -753,6 +753,17 @@ sub DBKeyExistsN($$$)
}
sub DBKeyExists($$) { return DBKeyExistsN(0,$_[0],$_[1]); }
sub DBHandleN($)
{
my ($dbnum) = @_;
my $dbw = $DB[$dbnum];
my $db = $dbw->dbh();
return $db;
}
sub DBHandle() { return DBHandleN(0); }
END {
# Call it here otherwise may get:
# (in cleanup) Can't call method "FETCH" on an undefined value at
......
......@@ -2,7 +2,7 @@
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2002 University of Utah and the Flux Group.
# Copyright (c) 2000-2011 University of Utah and the Flux Group.
# All rights reserved.
#
......@@ -27,18 +27,17 @@ if ($#ARGV >= 1 || $#ARGV < 0) {
print "parameter (like 'myhost:0') on the command line, and it will \n";
print "attempt to open it.\n";
die("\n");
} else {
use Mysql;
require "ctime.pl";
}
use lib '@prefix@/lib';
use libtestbed;
use emdb;
require "ctime.pl";
my $display = shift;
my $v = 0; # Verbose
my $dbh = Mysql->connect("localhost","@TBDBNAME@","script","none");
my @tbls = $dbh->listtables;
my @tbls = map { $_ =~ s/.*\.//; $_ } emdb::DBHandle()->tables();
my $date = &ctime(time);
......@@ -79,7 +78,7 @@ my %forkeys=();
foreach $tbl ( @tbls ) {
push(@tablelist,$tbl);
print "Found $tbl:\n" if $v;
if ($sth = $dbh->query("describe $tbl") ) {
if ($sth = DBQueryFatal("describe $tbl") ) {
while ( @data = $sth->fetchrow()) {
$col = $data[0];
$col =~ s/[0-9\-]+$//;
......
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2010 University of Utah and the Flux Group.
# Copyright (c) 2000-2011 University of Utah and the Flux Group.
# All rights reserved.
#
use strict;
......@@ -38,30 +38,6 @@ my $extraopts = ($isvers5 ? "--skip-opt" : "");
#
my $mysqldump = "mysqldump $extraopts -t $DBNAME sitevariables";
#
# We use Mysql module instead of the testbed libraries, so that we can get
# a more precise feel for what the error is.
#
use Mysql;
#
# Check to see if the mysqld is running by trying to connect to it.
#
my $dbh = Mysql->connect(undef,undef,undef,undef);
if (!$dbh) {
fatal("Unable to connect to mysqld - Either it's not running or \n" .
"permission was denied.\n");
}
#
# Check to see if the database exists
#
my @dbs = $dbh->listdbs();
if (! grep (/^$DBNAME$/,@dbs)) {
fatal("Database $DBNAME does not exist in the running database\n");
}
undef $dbh;
#
# Make sure we can write the temporary file
#
......
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2002 University of Utah and the Flux Group.
# Copyright (c) 2000-2011 University of Utah and the Flux Group.
# All rights reserved.
#
......@@ -14,7 +14,6 @@ my $CLIENT_ETCDIR = "@CLIENT_ETCDIR@";
use lib '@prefix@/lib';
use libdb;
#use Mysql;
use English;
use Getopt::Long;
use strict;
......
......@@ -2,7 +2,7 @@
#
# EMULAB-COPYRIGHT
# Copyright (c) 2004, 2005, 2006, 2008 University of Utah and the Flux Group.
# Copyright (c) 2004-2011 University of Utah and the Flux Group.
# All rights reserved.
#
......@@ -220,8 +220,6 @@ if ($mode eq "record") {
# Sleep for the duration of the run, then
sleep($duration + 3);
$query_result->dataseek(0);
print STDOUT "Pulling logs...\n";
$vhost_logs = "";
......
......@@ -2,7 +2,7 @@
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2004, 2006 University of Utah and the Flux Group.
# Copyright (c) 2000-2011 University of Utah and the Flux Group.
# All rights reserved.
#
......@@ -28,24 +28,26 @@ my $extraopts = ($isvers5 ? "--skip-opt" : "");
my $mysqldump = "mysqldump $extraopts";
#
# We use the bare Mysql module instead of the testbed libdb, so that this
# We use the bare module instead of the testbed libdb, so that this
# script can run from a first-time installation, before the latter is
# installed.
#
use Mysql;
use DBI;
#
# Build a list of tables to export
#
my $dbh = Mysql->connect('localhost',$DBNAME,undef,undef);
my $dbh = DBI->connect("DBI:mysql:database=$DBNAME;host=localhost",
undef, "none",
{'PrintError' => 0});
if (!$dbh) {
die("Unable to connect to mysqld - Either it's not running or \n" .
"permission was denied.\n");
}
my $result = $dbh->query("select table_name from exported_tables");
my $sth = $dbh->prepare("select table_name from exported_tables");
$sth->execute();
my $table_names;
while (my ($table_name) = $result->fetchrow()) {
while (my ($table_name) = $sth->fetchrow()) {
$table_names .= "$table_name ";
}
......
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2010 University of Utah and the Flux Group.
# Copyright (c) 2000-2011 University of Utah and the Flux Group.
# All rights reserved.
#
# Set the version and build info into the DB, at a toplevel install.
......@@ -17,16 +17,18 @@ my $DBNAME = '@TBDBNAME@';
my $SRCDIR = "@top_srcdir@";
#
# We use the bare Mysql module instead of the testbed libdb, so that this
# We use the bare module instead of the testbed libdb, so that this
# script can run from a first-time installation, before the latter is
# installed.
#
use Mysql;
use DBI;
#
# Build a list of tables to export
#
my $dbh = Mysql->connect('localhost', $DBNAME, undef, undef);
my $dbh = DBI->connect("DBI:mysql:database=$DBNAME;host=localhost",
undef, "none",
{'PrintError' => 0});
if (!$dbh) {
die("*** $0:\n".
" Unable to connect to mysqld\n");
......@@ -41,21 +43,15 @@ $buildinfo = $dbh->quote($buildinfo);
#
# And store into the appropriate sitevar.
#
my $query_result =
$dbh->query("update sitevariables set value=$buildinfo ".
"where name='general/version/build'");
if (!$query_result) {
die("*** $0:\n".
" Unable to set sitevar 'general/version/build' to $buildinfo\n");
}
$dbh->do("update sitevariables set value=$buildinfo ".
"where name='general/version/build'")
or die("*** $0:\n".
" Unable to set sitevar 'general/version/build' to $buildinfo\n");
$query_result =
$dbh->query("replace into version_info set ".
" name='buildinfo', value=$buildinfo");
if (!$query_result) {
die("*** $0:\n".
" Unable to set version_info 'buildinfo' to $buildinfo\n");
}
$dbh->do("replace into version_info set ".
" name='buildinfo', value=$buildinfo")
or die("*** $0:\n".
" Unable to set version_info 'buildinfo' to $buildinfo\n");
#
# Also store the Git hash into the DB so we can inspect it.
......@@ -73,12 +69,9 @@ else {
}
$hash = $dbh->quote($hash);
$query_result =
$dbh->query("replace into version_info set ".
" name='commithash', value=$hash");
if (!$query_result) {
die("*** $0:\n".
" Unable to set version_info 'commithash' to $hash\n");
}
$dbh->do("replace into version_info set ".
" name='commithash', value=$hash")
or die("*** $0:\n".
" Unable to set version_info 'commithash' to $hash\n");
exit(0);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment