diff --git a/GNUmakefile.in b/GNUmakefile.in index edf260f4b39d83bfba992ea4e842ad9024ea4e86..d4892005e8f47c6a9b8ad8b4a43c09b88d9cf06a 100644 --- a/GNUmakefile.in +++ b/GNUmakefile.in @@ -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 diff --git a/configure b/configure index 2142d9d7d971dbf4cd550f0981ef0b803a9c7c4c..a6f2707c1ed8bfeb4e142e4dfe1607ef95ac303a 100755 --- a/configure +++ b/configure @@ -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 \ diff --git a/configure.in b/configure.in index 21dc4dca87f7ed46007ed4977d5b01e31128a287..f798e09b82f1900b2c52c9945fd484a1d7da0b5a 100755 --- a/configure.in +++ b/configure.in @@ -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 \ diff --git a/db/GNUmakefile.in b/db/GNUmakefile.in index eee3c268beb8f4daae9db0f86d69f587bfaa8935..d7bb730d518a2eee1ae3a92741fe13a30335eb12 100644 --- a/db/GNUmakefile.in +++ b/db/GNUmakefile.in @@ -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 # diff --git a/db/backup.in b/db/backup.in new file mode 100755 index 0000000000000000000000000000000000000000..659ca0df8b54777035dafa7f9cb59994c4b66b8d --- /dev/null +++ b/db/backup.in @@ -0,0 +1,56 @@ +#!/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;