Commit 4c646de6 authored by Leigh Stoller's avatar Leigh Stoller

DB backup script to be run from cron everynight.

parent b52ac391
......@@ -41,6 +41,7 @@ install-mkdirs:
-mkdir -p $(INSTALL_TOPDIR)/locks
-mkdir -p $(INSTALL_TOPDIR)/log
-mkdir -p $(INSTALL_TOPDIR)/lists
-mkdir -p $(INSTALL_TOPDIR)/backup
clean: clean-subdirs
distclean: distclean-subdirs
......
......@@ -921,7 +921,7 @@ esac
outfiles="$outfiles Makeconf GNUmakefile \
assign/GNUmakefile \
capture/GNUmakefile \
db/GNUmakefile db/nalloc db/nfree db/if2port \
db/GNUmakefile db/nalloc db/nfree db/if2port db/backup \
discvr/GNUmakefile \
lib/GNUmakefile \
os/GNUmakefile os/imagezip/GNUmakefile \
......@@ -935,7 +935,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
tbsetup/ir/assign_wrapper tbsetup/ns2ir/GNUmakefile \
tbsetup/ns2ir/postparse tbsetup/ir/handle_os tbsetup/ir/handle_ip \
tbsetup/ns2ir/parse.tcl \
tbsetup/tbprerun tbsetup/tbrun tbsetup/tbend \
tbsetup/tbprerun tbsetup/tbrun tbsetup/tbend tbsetup/tbreport \
tbsetup/checkpass/GNUmakefile \
tip/GNUmakefile \
tmcd/GNUmakefile tmcd/tmcd.restart \
......
......@@ -87,7 +87,7 @@ esac]
outfiles="$outfiles Makeconf GNUmakefile \
assign/GNUmakefile \
capture/GNUmakefile \
db/GNUmakefile db/nalloc db/nfree db/if2port \
db/GNUmakefile db/nalloc db/nfree db/if2port db/backup \
discvr/GNUmakefile \
lib/GNUmakefile \
os/GNUmakefile os/imagezip/GNUmakefile \
......
......@@ -9,7 +9,7 @@ SUBDIR = db
include $(OBJDIR)/Makeconf
BIN_SCRIPTS = mac2if nalloc nfree nodeip
SBIN_SCRIPTS = avail inuse showgraph if2port
SBIN_SCRIPTS = avail inuse showgraph if2port backup
LIBEXEC_SCRIPTS = ptopgen
#
......
#!/usr/bin/perl -wT
use English;
#
# Configure variables
#
my $TB = "@prefix@";
my $DBNAME = "@TBDBNAME@";
my $BACKUPDIR = "$TB/backup";
# un-taint path
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# Only real root can call this.
#
if ($UID != 0) {
print STDERR "You must be root to run this script!\n";
exit(-1);
}
if (! chdir($BACKUPDIR)) {
print STDERR "Could not chdir to $BACKUPDIR!\n";
exit(-1);
}
#
# Format the name of the backup with date.
# Untaint it since it was constructed with date. Dopey.
#
my $name = "tbdb-" . `date +20%y%m%d-%H.%M.%S`;
if ($name =~ /^([-\@\w.]+)$/) {
$name = $1;
}
#
# Do a mysqldump. This will reset the log files.
#
if (system("mysqldump --all --flush-logs --lock-tables $DBNAME > $name")) {
print STDERR "mysqldump failed!\n";
exit(1);
}
#
# Compress it.
#
if (system("gzip $name")) {
print STDERR "gzip failed!\n";
exit(1);
}
print STDOUT "DB backup ($DBNAME) complete!\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