Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
emulab
emulab-devel
Commits
53e4e868
Commit
53e4e868
authored
Nov 10, 2009
by
Leigh B. Stoller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add an opsmode (-o) mode to flush/roll the DB logs on ops.
parent
0612de16
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
15 deletions
+70
-15
db/GNUmakefile.in
db/GNUmakefile.in
+1
-1
db/backup.in
db/backup.in
+69
-14
No files found.
db/GNUmakefile.in
View file @
53e4e868
...
@@ -30,7 +30,7 @@ LIB_SCRIPTS = libdb.pm Node.pm libdb.py libadminctrl.pm Experiment.pm \
...
@@ -30,7 +30,7 @@ LIB_SCRIPTS = libdb.pm Node.pm libdb.py libadminctrl.pm Experiment.pm \
emdb.pm emutil.pm Firewall.pm VirtExperiment.pm libGeni.pm
emdb.pm emutil.pm Firewall.pm VirtExperiment.pm libGeni.pm
# Stuff installed on plastic.
# Stuff installed on plastic.
USERSBINS = genelists.proxy dumperrorlog.proxy
USERSBINS = genelists.proxy dumperrorlog.proxy
backup
USERLIBS = libtbdb.pm libdb.py
USERLIBS = libtbdb.pm libdb.py
# These scripts installed setuid, with sudo.
# These scripts installed setuid, with sudo.
...
...
db/backup.in
View file @
53e4e868
#!/usr/bin/perl -wT
#!/usr/bin/perl -wT
#
#
# EMULAB-COPYRIGHT
# EMULAB-COPYRIGHT
# Copyright (c) 2000-200
8
University of Utah and the Flux Group.
# Copyright (c) 2000-200
9
University of Utah and the Flux Group.
# All rights reserved.
# All rights reserved.
#
#
use
strict
;
use
English
;
use
English
;
use
Getopt::
Std
;
#
#
# Back up the DB, rolling the base and update logs. The approach is to
# Back up the DB, rolling the base and update logs. The approach is to
...
@@ -20,7 +21,15 @@ use English;
...
@@ -20,7 +21,15 @@ use English;
# made since backup.XXX was made). This should give you a DB that is the
# made since backup.XXX was made). This should give you a DB that is the
# same as backup.XXX+1. You can go back further, and just apply all the
# same as backup.XXX+1. You can go back further, and just apply all the
# subsequent update.XXX files.
# subsequent update.XXX files.
#
#
sub
usage
()
{
print
("
Usage: backup [-o]
\n
");
exit
(
-
1
);
}
my
$optlist
=
"
do
";
my
$debug
=
0
;
my
$opsmode
=
0
;
#
#
# Configure variables
# Configure variables
...
@@ -34,6 +43,7 @@ my $LOGDIR = "$TB/log/mysql";
...
@@ -34,6 +43,7 @@ my $LOGDIR = "$TB/log/mysql";
my
$HOTCOPY
=
"
/usr/local/bin/mysqlhotcopy
";
my
$HOTCOPY
=
"
/usr/local/bin/mysqlhotcopy
";
my
$MYSQLDUMP
=
"
/usr/local/bin/mysqldump
";
my
$MYSQLDUMP
=
"
/usr/local/bin/mysqldump
";
my
$SETSITEVAR
=
"
$TB
/sbin/setsitevar
";
my
$SETSITEVAR
=
"
$TB
/sbin/setsitevar
";
my
$DBCONF
=
"
$TB
/etc/mysqld.pwd
";
my
$TAR
=
"
/usr/bin/tar
";
my
$TAR
=
"
/usr/bin/tar
";
my
$BASE
=
"
base
";
my
$BASE
=
"
base
";
my
$UPD
=
"
update
";
my
$UPD
=
"
update
";
...
@@ -41,6 +51,9 @@ my $SLOW = "slowqueries";
...
@@ -41,6 +51,9 @@ my $SLOW = "slowqueries";
my
$BACK
=
"
tbdb
";
my
$BACK
=
"
tbdb
";
my
$extension
;
my
$extension
;
my
$dohotcopy
=
0
;
my
$dohotcopy
=
0
;
my
$dbname
=
"
mysql
";
my
$dbuser
=
"
root
";
my
$dbpass
;
# un-taint path
# un-taint path
$ENV
{'
PATH
'}
=
'
/bin:/usr/bin:/usr/local/bin:/usr/site/bin
';
$ENV
{'
PATH
'}
=
'
/bin:/usr/bin:/usr/local/bin:/usr/site/bin
';
...
@@ -68,6 +81,23 @@ if ($UID != 0) {
...
@@ -68,6 +81,23 @@ if ($UID != 0) {
exit
(
-
1
);
exit
(
-
1
);
}
}
#
# Parse command arguments.
#
my
%options
=
();
if
(
!
getopts
(
$optlist
,
\
%options
))
{
usage
();
}
if
(
defined
(
$options
{"
d
"}))
{
$debug
=
1
;
}
if
(
defined
(
$options
{"
o
"}))
{
$opsmode
=
1
;
}
if
(
$opsmode
&&
$dohotcopy
)
{
fatal
("
Cannot do hotcopy mode on ops
");
}
#
#
# Create a temporary name for a log file and untaint it.
# Create a temporary name for a log file and untaint it.
#
#
...
@@ -89,15 +119,30 @@ if ($logname =~ /^([-\@\w.\/]+)$/) {
...
@@ -89,15 +119,30 @@ if ($logname =~ /^([-\@\w.\/]+)$/) {
open
(
STDERR
,
"
>>
$logname
")
or
die
("
opening
$logname
for STDERR: $!
");
open
(
STDERR
,
"
>>
$logname
")
or
die
("
opening
$logname
for STDERR: $!
");
open
(
STDOUT
,
"
>>
$logname
")
or
die
("
opening
$logname
for STDOUT: $!
");
open
(
STDOUT
,
"
>>
$logname
")
or
die
("
opening
$logname
for STDOUT: $!
");
if
(
!
chdir
(
$BACKUPDIR
)
)
{
if
(
$opsmode
)
{
fatal
("
Could not chdir to
$BACKUPDIR
: $!
")
;
require
libtbdb
;
}
import
libtbdb
;
#
if
(`
cat
$DBCONF
`
=~
/^([\w]*)$/
)
{
# Let people know the system will be sluggish.
$dbpass
=
$
1
;
#
}
system
("
$SETSITEVAR
web/message '<font color=red>
"
.
else
{
"
Nightly backup in progress; system might be sluggish</font>'
");
fatal
("
Could not get mysql password from
$DBCONF
!
");
}
if
(
TBDBConnect
(
$dbname
,
$dbuser
,
$dbpass
)
<
0
)
{
fatal
("
Could not connect to ops database!
");
}
}
else
{
if
(
!
chdir
(
$BACKUPDIR
))
{
fatal
("
Could not chdir to
$BACKUPDIR
: $!
");
}
#
# Let people know the system will be sluggish.
#
system
("
$SETSITEVAR
web/message '<font color=red>
"
.
"
Nightly backup in progress; system might be sluggish</font>'
");
}
#
#
# Open up the index file to see what the current update file extension is.
# Open up the index file to see what the current update file extension is.
...
@@ -138,7 +183,8 @@ my $basename = "$BASE.$extension";
...
@@ -138,7 +183,8 @@ my $basename = "$BASE.$extension";
my
$updname
=
"
$UPD
.
$extension
";
my
$updname
=
"
$UPD
.
$extension
";
my
$slowname
=
"
$SLOW
.
$extension
";
my
$slowname
=
"
$SLOW
.
$extension
";
print
"
Backup file name:
$backname
\n
";
print
"
Backup file name:
$backname
\n
"
if
(
!
$opsmode
);
print
"
Base file name:
$basename
\n
";
print
"
Base file name:
$basename
\n
";
print
"
Update file name:
$updname
\n
";
print
"
Update file name:
$updname
\n
";
print
"
Slow file name:
$slowname
\n
";
print
"
Slow file name:
$slowname
\n
";
...
@@ -157,7 +203,15 @@ if (-e "$LOGDIR/$SLOW") {
...
@@ -157,7 +203,15 @@ if (-e "$LOGDIR/$SLOW") {
}
}
}
}
if
(
$dohotcopy
)
{
if
(
$opsmode
)
{
#
# This will reset the log files.
#
if
(
!
DBQueryWarn
("
flush logs
"))
{
fatal
("
mysqladmin failed!
");
}
}
elsif
(
$dohotcopy
)
{
#
#
# Do a hotcopy. This will reset the log files.
# Do a hotcopy. This will reset the log files.
#
#
...
@@ -226,7 +280,8 @@ if ($dohotcopy && -e "$BACKUPDIR/tbdb") {
...
@@ -226,7 +280,8 @@ if ($dohotcopy && -e "$BACKUPDIR/tbdb") {
#SENDMAIL("stoller@flux.utah.edu",
#SENDMAIL("stoller@flux.utah.edu",
# "DB Backup Finished", "", undef, undef, ($logname));
# "DB Backup Finished", "", undef, undef, ($logname));
system
("
$SETSITEVAR
web/message -
");
system
("
$SETSITEVAR
web/message -
")
if
(
!
$opsmode
);
unlink
("
$logname
");
unlink
("
$logname
");
exit
0
;
exit
0
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment