]> andersk Git - moira.git/commitdiff
Initial revision
authorwesommer <wesommer>
Sat, 11 Jul 1987 19:51:05 +0000 (19:51 +0000)
committerwesommer <wesommer>
Sat, 11 Jul 1987 19:51:05 +0000 (19:51 +0000)
backup/db2bkup.awk [new file with mode: 0644]
backup/dump_db.qc [new file with mode: 0644]

diff --git a/backup/db2bkup.awk b/backup/db2bkup.awk
new file mode 100644 (file)
index 0000000..173a80e
--- /dev/null
@@ -0,0 +1,68 @@
+#      $Source$
+#      $Header$
+#
+#      This converts the file used to originally create the database
+#      into a program to back it up.
+#      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 "/* This file automatically generated */" > "bkup1.qc";
+       print "/* Do not edit */" >> "bkup1.qc"
+       print "do_backups(prefix)\n\tchar *prefix;\n{" >>"bkup1.qc"
+}
+
+/^create/ { printf "dump_%s(f)\nFILE *f;\n", $2;
+       printf "\tdump_%s(open_file(prefix, \"%s\"));\n", $2, $2 >> "bkup1.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;
+               vtype[count]="str"
+       } else if ($3 ~ /date/) {
+               printf "##      char    t_%s[26];\n", vname[count]
+               vtype[count]="str"
+       } else if ($3 ~ /c[0-9]*/) {
+               t = split($3, temp, ",")
+               printf "##      char    t_%s[%d];\n", vname[count], substr(temp[1], 2) + 1
+               vtype[count]="str"
+       } else printf "Unknown data type %s\n", $3;
+       count++;
+}
+
+/^\($/ { print "##{" }
+/^\)$/ { 
+       printf "##      range of %s is %s\n", rangename, tablename
+       printf "##      retrieve(\n"
+       for (i = 0; i < count; i++) {
+               if (i != 0) printf ",\n";
+               printf "##\t\tt_%s = %s.%s", vname[i], rangename, vname[i]
+       }
+       printf ")\n"
+       printf "##      {\n"
+       for (i = 0; i < count; i++) {
+               if (i != 0) print "\t\tdump_str(f, \":\");"
+               printf "\t\tdump_%s(f, t_%s);\n", vtype[i], vname[i]
+       }
+       printf "\t\tdump_nl(f);\n"
+       printf "##      }\n"
+       printf "\tsafe_close(f);\n"
+       printf "##}\n"
+}
+END { print "/* All done */"
+       print "}" >>"bkup1.qc"
+}
diff --git a/backup/dump_db.qc b/backup/dump_db.qc
new file mode 100644 (file)
index 0000000..820f9e5
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+ *     $Source$
+ *     $Author$
+ *     $Header$
+ *
+ *     Copyright (C) 1987 by the Massachusetts Institute of Technology
+ *
+ *     This program dumps the SMS database to a series of output files
+ * which can be later read back into SMS in the event of a crash.
+ * 
+ *     $Log$
+ *     Revision 1.1  1987-07-11 19:51:05  wesommer
+ *     Initial revision
+ *
+ *
+ */
+
+#ifndef lint
+static char *rcsid_dump_db_c = "$Header$";
+#endif lint
+
+#include <stdio.h>
+#include <sys/file.h>
+
+FILE *open_file();
+
+main(argc, argv)
+    int argc;
+    char **argv;
+{
+    char *prefix;
+    
+    if (argc != 2) {
+       fprintf(stderr, "Usage: smsbackup prefix\n");
+       exit(1);
+    }
+    prefix = argv[1];
+
+##  ingres sms 
+    
+    do_backups(prefix);
+    
+##  exit
+    exit(0);
+}
+
+FILE *open_file(prefix, suffix)
+    char *prefix, *suffix;
+{
+    char name[BUFSIZ];
+    int fd;
+    FILE *f;
+    
+    strcpy(name, prefix);
+    strcat(name, suffix);
+
+    fd = open(name, O_CREAT|O_WRONLY|O_EXCL, 0644);
+    if (fd < 0) {
+       punt(name);
+    }
+    f = fdopen(fd, "w");
+    if (f == NULL) {
+       fprintf(stderr, "fdopen of ");
+       punt(name);
+    }
+    fprintf(stderr, "Working on %s\n", name);
+    return(f);
+}
+
+dump_int(f, n)
+    FILE *f;
+    int n;
+{
+    char buf[1024];
+    sprintf(buf, "%d", n);
+    dump_str(f, buf);
+}
+
+dump_nl(f)
+{
+    dump_str(f, "\n");
+}
+
+/*
+ * Should check that we're not printing non-printing characters or
+ * ':' characters here (??? recovery if we do??)
+ */
+
+dump_str(f, str)
+    FILE *f;
+    char *str;
+{
+    register int len = strlen(str);
+
+    if (fwrite(str, 1, len, f) != len) punt("short write");
+}
+
+
+punt(msg)
+       char *msg;
+{
+       perror(msg);
+##     exit
+       exit(1);
+}
+
+safe_close(stream)
+       FILE *stream;
+{
+       if (fflush(stream) == EOF)
+               punt("Unable to fflush");
+       if (fsync(fileno(stream)) != 0) 
+               punt("Unable to fsync");
+       fclose(stream);
+}      
+
+/*
+ * 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:
+ */
This page took 0.062911 seconds and 5 git commands to generate.