--- /dev/null
+.SUFFIXES:
+.SUFFIXES: .qc .o
+CFLAGS= -O
+
+EQLIBS = /usr/rtingres/lib/libqlib /usr/rtingres/lib/compatlib
+
+.qc.o:
+ eqc $*.qc
+ rm -f $*.o
+ cc -c ${CFLAGS} $*.c
+
+all: smsbackup smsrestore
+
+smsbackup: dump_db.o bkup1.o bkup.o dumprest.o
+ cc -o $@ ${CFLAGS} dump_db.o bkup1.o bkup.o dumprest.o ${EQLIBS}
+
+smsrestore: rest_db.o rest1.o rest.o dumprest.o
+ cc -o $@ ${CFLAGS} rest_db.o rest1.o rest.o dumprest.o ${EQLIBS}
+
+bkup.qc: ../db/dbbuild db2bkup.awk
+ cc -E ../db/dbbuild | awk -f db2bkup.awk > bkup.qc
+
+bkup1.qc: bkup.qc
+
+rest.qc: ../db/dbbuild db2rest.awk
+ cc -E ../db/dbbuild | awk -f db2rest.awk > rest.qc
+
+rest1.qc: rest.qc
+
+lint:
+ lint -h dump_db.c bkup.c bkup1.c dumprest.c | egrep -v '^II'
+ lint -h rest_db.c rest.c rest1.c dumprest.c | egrep -v '^II'
+
+clean:
+ rm -f *.c *.o smsbackup bkup.qc bkup1.qc smsrestore rest.qc rest1.qc
+ rm -f core *~
+
+
+
+
+
--- /dev/null
+# $Source$
+# $Header$
+#
+# This converts the file used to originally create the database
+# into a program to restore it from a backup.
+# This is not guaranteed to work for all data types; it may
+# need to be extended.
+
+BEGIN { print "/* This file automatically generated */";
+ print "/* Do not edit */";
+ print "#include <stdio.h>";
+ print "void parse_nl(), parse_str(), parse_sep();"
+ print "/* This file automatically generated */" > "rest1.qc";
+ print "/* Do not edit */"
+ print "#include <stdio.h>" >> "rest1.qc"
+ print "FILE *open_file();" >> "rest1.qc"
+ print "do_restores(prefix)\n\tchar *prefix;\n{" >>"rest1.qc"
+}
+
+/^create/ { printf "restore_%s(f)\nFILE *f;\n", $2;
+ printf "\trestore_%s(open_file(prefix, \"%s\"));\n", $2, $2 >> "rest1.qc"
+ tablename = $2;
+ rangename = substr(tablename, 1, 1);
+ count = 0; }
+
+$2 ~ /\=/ {
+ vname[count] = $1;
+ printf "/* %s */\n", $0
+ if ($3 ~ /i[24]/) {
+ printf "## int t_%s;\n", vname[count]
+ vtype[count]="int"
+ } else if ($3 ~ /text\([0-9]*\)/) {
+ t = split($3, temp, "(")
+ if (t != 2) printf "Can't parse %s\n", $3;
+ t = split(temp[2], temp2, ")")
+ if (t != 2) printf "Can't parse %s\n", temp[2];
+ printf "## char t_%s[%d];\n", vname[count], temp2[1]+1;
+ vsize[count] = temp2[1]+1;
+ vtype[count]="str"
+ } else if ($3 ~ /date/) {
+ printf "## char t_%s[26];\n", vname[count];
+ vtype[count]="str";
+ vsize[count]=26;
+ } else if ($3 ~ /c[0-9]*/) {
+ t = split($3, temp, ",")
+ vsize[count] = substr(temp[1], 2) + 1
+ printf "## char t_%s[%d];\n", vname[count],vsize[count]
+ vtype[count]="str"
+ } else printf "Unknown data type %s\n", $3;
+ count++;
+}
+
+/^\($/ { print "##{" }
+/^\)$/ {
+ print "\twhile(!feof(f)) {"
+ for (i = 0; i < count; i++) {
+ if (i != 0) print "\t\tparse_sep(f);"
+ if (vtype[i] ~ /int/) {
+ printf("\t\tt_%s = parse_int(f);\n", vname[i]);
+ } else printf "\t\tparse_%s(f, t_%s, %d);\n", vtype[i], vname[i], vsize[i]
+ if (i == 0) print "\t\tif (feof(f)) break;"
+ }
+ printf "\t\tparse_nl(f);\n"
+
+ printf "##\t\tappend %s (\n", tablename
+ for (i = 0; i < count; i++) {
+ if (i != 0) printf ",\n";
+ printf "##\t\t\t%s = t_%s", vname[i], vname[i]
+ }
+ printf ")\n"
+ printf "\t}\n"
+ printf "\t(void) fclose(f);\n"
+ printf "##}\n"
+}
+END { print "/* All done */"
+ print "}" >>"rest1.qc"
+}
--- /dev/null
+#define dump_nl(f) { if (putc('\n', f) < 0) wpunt(); }
+#define dump_sep(f) { if (putc(':', f) < 0) wpunt(); }
+
--- /dev/null
+/*
+ * $Source$
+ * $Author$
+ * $Header$
+ *
+ * Copyright (C) 1987 by the Massachusetts Institute of Technology
+ *
+ * $Log$
+ * Revision 1.1 1987-07-13 03:53:09 wesommer
+ * Initial revision
+ *
+ */
+
+#ifndef lint
+static char *rcsid_dumprest_qc = "$Header$";
+#endif lint
+
+#include <stdio.h>
+#include <sys/file.h>
+#include <strings.h>
+
+punt(msg)
+ char *msg;
+{
+ perror(msg);
+## exit
+ exit(1);
+}
+
+
+
+
+/*
+ * Local Variables:
+ * mode: c
+ * c-indent-level: 4
+ * c-continued-statement-offset: 4
+ * c-brace-offset: -4
+ * c-argdecl-indent: 4
+ * c-label-offset: -4
+ * End:
+ */
--- /dev/null
+#!/bin/sh
+#
+# Nightly script for backing up SMS.
+#
+#
+BKUPDIRDIR=/tmp
+
+chdir ${BKUPDIRDIR}
+
+if [ -d in_progress ]
+then
+ echo "Two backups running?"
+ exit 1
+fi
+
+if mkdir in_progress
+then
+ echo "Backup in progress."
+else
+ echo "Cannot create backup directory"
+ exit 1
+fi
+
+if /u1/sms/backup/smsbackup ${BKUPDIRDIR}/in_progress/
+then
+ echo "Backup successful"
+else
+ echo "Backup failed!"
+ exit 1
+fi
+
+if [ -d stale ]
+then
+ echo -n "Stale backup "
+ rm -rf backup_4
+ echo "removed"
+fi
+echo -n "Shifting backups "
+
+mv backup_3 stale
+echo -n "3"
+mv backup_2 backup_3
+echo -n "2"
+mv backup_1 backup_2
+echo -n "1"
+mv in_progress backup_1
+echo
+echo -n "deleting last backup"
+rm -rf stale
+echo "New backup:"
+ls -l backup_1
+exit 0
--- /dev/null
+/*
+ * $Source$
+ * $Author$
+ * $Header$
+ *
+ * Copyright (C) 1987 by the Massachusetts Institute of Technology
+ *
+ * $Log$
+ * Revision 1.1 1987-07-13 03:50:02 wesommer
+ * Initial revision
+ *
+ */
+
+#ifndef lint
+static char *rcsid_rest_db_qc = "$Header$";
+#endif lint
+
+#include <sys/file.h>
+#include <stdio.h>
+#include <ctype.h>
+
+/*ARGSUSED*/
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ char buf[BUFSIZ];
+ char *prefix;
+
+ if (!yes_or_no("Do you *REALLY* want to wipe the SMS database?")) {
+ printf("I didn't think so\n");
+ exit(1);
+ }
+ if (!yes_or_no("Have you initialized an empty database named smstemp?")) {
+ printf("You should have\n");
+ exit(1);
+ }
+
+ printf("Opening database: ");
+ (void) fflush(stdout);
+## ingres smstemp
+
+ printf(" done\n");
+
+ printf("Prefix of backup to restore: ");
+ (void) fflush(stdout);
+ if (gets(buf) == NULL) {
+ return 1;
+ }
+ prefix = buf;
+
+ if (!yes_or_no("Are you SURE?")) {
+ printf("I didn't think so\n");
+ exit(1);
+ }
+ do_restores(prefix);
+ printf("Restore complete\n");
+## exit
+ exit(0);
+ /*NOTREACHED*/
+}
+
+yes_or_no(prompt)
+ char *prompt;
+{
+ char buf[BUFSIZ];
+ int ret;
+
+ int tt = open("/dev/tty", O_RDWR, 0);
+ FILE *o, *i;
+
+ register char *cp;
+
+ if (tt < 0) return 0;
+
+ (void) fflush(stdout);
+ (void) fflush(stderr);
+ o = fdopen(dup(tt), "w");
+ i = fdopen(dup(tt), "r");
+ (void) close(tt);
+
+ for (;;) {
+ fprintf(o, "%s (yes or no): ", prompt);
+ (void) fflush(o);
+ if (fgets(buf, BUFSIZ, i) == NULL) goto err;
+ for (cp = buf; *cp; cp++) {
+ if (isupper(*cp)) *cp=tolower(*cp);
+ }
+ if (strcmp(buf, "yes\n") == 0) {
+ ret = 1; goto out;
+ }
+ if (strcmp(buf, "no\n") == 0) {
+ ret = 0; goto out;
+ }
+ }
+
+err:
+ ret = 0;
+
+out:
+ (void) fclose(o);
+ (void) fclose(i);
+ return ret;
+}
+
+int parse_int(f)
+ register FILE *f;
+{
+ register int c;
+ register int val = 0;
+ register int sign = 1;
+ while ((c = getc(f)) != EOF && c != ':' && c != '\n') {
+ if (c == '-') sign = -1;
+ else if (isdigit(c)) {
+ val *= 10;
+ val += (c - '0');
+ } else (void) fprintf(stderr,"non-digit in numeric field\n");
+ }
+ (void) ungetc(c, f);
+ return(val * sign);
+}
+
+void parse_str(f, buf, len)
+ register FILE *f;
+ register char *buf;
+ register int len; /* incl trailing NULL */
+{
+ register int c;
+
+ while ((c = getc(f)) != EOF && c != ':' && c != '\n' && len > 0) {
+ if (c == '\\') {
+ c = getc(f);
+ if (isdigit(c)) {
+ /* Expect three-digit octal number.. */
+ register int c1, c2;
+ c1 = getc(f);
+ c2 = getc(f);
+ if (!isdigit(c1) || !isdigit(c2))
+ punt("Broken \\###");
+ /* Convert to ASCII code: */
+ *buf++ = (((c-'0')<<6) + ((c1-'0')<<3) + c2-'0');
+ } else if (c == '\\' || c == ':') {
+ *buf++ = c;
+ --len;
+ } else punt ("Broken '\\'");
+ } else {
+ *buf++ = c;
+ --len;
+ }
+ }
+ if (c == EOF)
+ return;
+
+ if (c != EOF && c != ':' && c != '\n')
+ fprintf(stderr, "Field too wide, truncated\n");
+ else {
+ *buf++ = 0;
+ (void) ungetc(c, f);
+ }
+}
+
+void parse_sep(f)
+ FILE *f;
+{
+ if (getc(f) != ':') punt("Expected colon");
+}
+void parse_nl(f)
+ FILE *f;
+{
+ if (getc(f) != '\n') punt("Expected newline");
+}
+
+
+FILE *open_file(prefix, suffix)
+ char *prefix, *suffix;
+{
+ char name[BUFSIZ];
+ int fd;
+ FILE *f;
+
+ (void) strcpy(name, prefix);
+ (void) strcat(name, suffix);
+
+ fd = open(name, O_RDONLY, 0);
+ if (fd < 0) {
+ punt(name);
+ }
+ f = fdopen(fd, "r");
+ if (f == NULL) {
+ fprintf(stderr, "fdopen of ");
+ punt(name);
+ }
+ fprintf(stderr, "Working on %s\n", name);
+ return(f);
+}
+
+/*
+ * Local Variables:
+ * mode: c
+ * c-indent-level: 4
+ * c-continued-statement-offset: 4
+ * c-brace-offset: -4
+ * c-argdecl-indent: 4
+ * c-label-offset: -4
+ * End:
+ */