Commit 3dc6312d authored by Leigh Stoller's avatar Leigh Stoller

Generate per-experiment DBs on ops for each instance. The DB is dumped

and saved in the archive at run boundries and when the instance is
terminated. No idea yet how this will be used.
parent ecab2742
......@@ -28,6 +28,7 @@ my $TB = "@prefix@";
my $MD5 = "/sbin/md5";
my $makegraph = "$TB/bin/template_graph";
my $TEVC = "$TB/bin/tevc";
my $DBCONTROL = "$TB/sbin/opsdb_control";
# Cache of template instances to avoid regenerating them.
my %templates = ();
......@@ -1832,6 +1833,30 @@ sub LogHole($)
return 0;
}
#
# Dump the instance DB into the archive directory.
#
sub DumpDB($)
{
my ($self) = @_;
# Must be a real reference.
return -1
if (! ref($self));
my $pid = $self->pid();
my $eid = $self->eid();
my $archivedir = libArchive::TBUserFileArchiveDirectory($pid, $eid);
# The file is a gzipped.
my $dumpfile = "$archivedir/dbdump.gz";
system("$DBCONTROL dumpexpdb $pid $eid $dumpfile") == 0
or return -1;
return 0;
}
#
# Grab the current archive tag. I think this info belongs in the instance
# record.
......
......@@ -31,11 +31,13 @@ my $state;
#
my $TBROOT = "@prefix@";
my $TESTMODE = @TESTMODE@;
my $TBLOGS = "@TBLOGSEMAIL@";
my $TBLOGS = "@TBLOGSEMAIL@";
my $OPSDBSUPPORT= @OPSDBSUPPORT@;
my $wrapper = "$TBROOT/libexec/assign_wrapper";
my $batchexp = "$TBROOT/bin/batchexp";
my $template = "$TBROOT/lib/ns2ir/elabinelab.ns";
my $endexp = "$TBROOT/bin/endexp";
my $dbcontrol= "$TBROOT/sbin/opsdb_control";
my $exptidx;
# Untaint the path
......@@ -278,6 +280,14 @@ if (system("gentopofile $pid $eid")) {
fatal("gentopofile failed!");
}
if ($OPSDBSUPPORT) {
TBDebugTimeStamp("opsdb_control started");
if (system("$dbcontrol addexpdb $pid $eid")) {
fatal("$dbcontrol addexpdb failed!");
}
}
if (!$elabinelab) {
TBDebugTimeStamp("verify-ns started");
print "Verifying parse ...\n";
......
......@@ -311,6 +311,10 @@ print "Asking loghole to sync the logfiles ... this will take a minute.\n";
$instance->LogHole() == 0
or fatal(-1, "Loghole failed");
print "Dumping the instance database ... this will take a minute.\n";
$instance->DumpDB() == 0
or fatal(-1, "Dump Database failed");
#
# Commit the archive.
#
......
......@@ -243,6 +243,10 @@ print "Asking loghole to sync the logfiles ... this will take a minute.\n";
$instance->LogHole() == 0
or fatal(-1, "Loghole failed");
print "Dumping the instance database ... this will take a minute.\n";
$instance->DumpDB() == 0
or fatal(-1, "Dump Database failed");
#
# Now do the swapout.
#
......
......@@ -55,6 +55,7 @@ sub DelGroup(@);
sub SetGroups(@);
sub AddExpDB(@);
sub DelExpDB(@);
sub DumpExpDB(@);
sub DoOpsStuff($;$);
sub Initialize();
sub fatal($);
......@@ -134,6 +135,9 @@ elsif ($action eq "addexpdb") {
elsif ($action eq "delexpdb") {
exit(DelExpDB(@ARGV));
}
elsif ($action eq "dumpexpdb") {
exit(DumpExpDB(@ARGV));
}
elsif ($action eq "setup") {
exit(Initialize());
}
......@@ -465,6 +469,7 @@ sub AddExpDB(@)
return 0;
}
sub DelExpDB(@)
{
my ($pid, $eid) = @_;
......@@ -519,6 +524,62 @@ sub DelExpDB(@)
return 0;
}
sub DumpExpDB(@)
{
my ($pid, $eid, $filename) = @_;
usage()
if (@_ != 3);
#
# Untaint args.
#
if ($pid =~ /^([-\w]+)$/) {
$pid = $1;
}
else {
die("Bad data in pid: $pid");
}
if ($eid =~ /^([-\w]+)$/) {
$eid = $1;
}
else {
die("Bad data in eid: $eid");
}
if ($filename =~ /^([-\w\/\.\+,]+)$/) {
$filename = $1;
}
else {
die("Bad data in filename: $filename");
}
my $gid = ExpGroup($pid, $eid);
my $exptidx;
#
# Check to see if the experiment actually wants its own DB.
#
my $query_result =
DBQueryFatal("select dpdbname from experiments ".
"where pid='$pid' and eid='$eid' and dpdb!=0");
return 0
if (!$query_result->numrows);
my ($dbname) = $query_result->fetchrow_array();
return -1
if (!defined($dbname));
return -1
if (!TBExptIDX($pid, $eid, \$exptidx));
print "Dumping mysql DB '$dbname' to $filename on $CONTROL.\n";
my $retval = DoOpsStuff("dumpdb $dbname $filename");
if ($retval) {
fatal("$OPSDBPROXY failed on $CONTROL!");
}
return 0;
}
# Wrapper for ssh.
sub DoOpsStuff($;$)
{
......
......@@ -27,6 +27,8 @@ my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
my $OURDOMAIN= "@OURDOMAIN@";
my $DBCONF = "/usr/testbed/etc/mysqld.pwd";
my $MYSQLDUMP= "/usr/local/bin/mysqldump";
my $GZIP = "/usr/bin/gzip";
#
# Turn off line buffering on output
......@@ -66,6 +68,7 @@ sub DelUser(@);
sub AddDB(@);
sub DelDB(@);
sub SetDBs(@);
sub DumpDB(@);
sub fatal($);
#
......@@ -116,6 +119,9 @@ elsif ($action eq "deldb") {
elsif ($action eq "setdbs") {
exit(SetDBs(@ARGV));
}
elsif ($action eq "dumpdb") {
exit(DumpDB(@ARGV));
}
else {
die("*** $0:\n".
" Do not know what to do with '$action'!\n");
......@@ -374,6 +380,38 @@ sub SetDBs(@)
return 0;
}
#
# Dump a DB to a file.
#
sub DumpDB(@)
{
my ($dbname, $filename) = @_;
usage()
if (@_ != 2);
my $exists = DBExists($dbname);
return -1
if ($exists < 0);
my $isemulab = IsEmulabDB($dbname);
return -1
if ($isemulab < 0);
if (!$exists) {
print "DB '$dbname' does not exist!\n";
return -1;
}
open(DUMP, "| $MYSQLDUMP -u root -p -a -e $dbname | $GZIP > $filename") or
fatal("Could not start $MYSQLDUMP!");
print DUMP "$dbpass\n";
close(DUMP) or
fatal($! ? "Error closing $MYSQLDUMP pipe: $!"
: "Exit status $? from $MYSQLDUMP");
return 0;
}
sub fatal($)
{
my($mesg) = $_[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