From: danw Date: Mon, 20 Jan 1997 18:14:06 +0000 (+0000) Subject: Oracle and Solaris/POSIX changes X-Git-Tag: MOIRA4_INITIAL~8 X-Git-Url: http://andersk.mit.edu/gitweb/moira.git/commitdiff_plain/3d058c8a1efe77a6adec3450f7e2bc1f5c494e46 Oracle and Solaris/POSIX changes Source tree should only have Imakefiles, not Makefiles. Added ;s to awk scripts so Emacs will indent them properly. Removed ancient files --- diff --git a/backup/Imakefile b/backup/Imakefile index c2fc345c..51fcdd52 100644 --- a/backup/Imakefile +++ b/backup/Imakefile @@ -8,25 +8,25 @@ # Imakefile for backup directory. # -SRCS= dump_db.c bkup1.c bkup.c dumprest.c rest_db.c rest1.c rest.c +SRCS= dump_db.h dump_db.c bkup1.c bkup.c dumprest.c rest_db.c rest1.c rest.c SRCDIR=${SRCTOP}/backup CODE= db2bkup.awk db2rest.awk dump_db.h dump_db.dc dumprest.dc \ - nightly.sh report.sh rest_db.dc esqlc_fix.pl -BOBJS= dump_db.o bkup1.o bkupfix.o dumprest.o + nightly.sh report.sh rest_db.dc +BOBJS= dump_db.o bkup1.o bkup.o dumprest.o ROBJS= rest_db.o rest1.o rest.o dumprest.o sqlrule() program(mrbackup, ${BOBJS},${MR_LIBDEP}, ${CLIBS} ${SQL_LIB}, ${PROGDIR}) program(mrrestore, ${ROBJS},${MR_LIBDEP}, ${CLIBS} ${SQL_LIB}, ${PROGDIR}) -bkup.dc: ../db/schema db2bkup.awk - cc -E ../db/schema | awk -f db2bkup.awk > bkup.dc +bkup.dc: ../db/schema.sql db2bkup.awk + awk -f db2bkup.awk < ../db/schema.sql > bkup.dc bkup1.dc: bkup.dc -rest.dc: ../db/schema db2rest.awk - cc -E ../db/schema | awk -f db2rest.awk > rest.dc +rest.dc: ../db/schema.sql db2rest.awk + awk -f db2rest.awk < ../db/schema.sql > rest.dc rest1.dc: rest.dc clean:: - $(RM) bkup.dc bkup1.dc rest.dc rest1.dc bkupfix.c + $(RM) bkup.dc bkup1.dc rest.dc rest1.dc sqlfile(dump_db) sqlfile(rest_db) sqlfile(dumprest) @@ -34,6 +34,3 @@ sqlfile(bkup) sqlfile(bkup1) sqlfile(rest) sqlfile(rest1) - -bkupfix.c: bkup.c esqlc_fix.pl - perl esqlc_fix.pl < bkup.c > bkupfix.c diff --git a/backup/Makefile b/backup/Makefile deleted file mode 100644 index 1d1558f7..00000000 --- a/backup/Makefile +++ /dev/null @@ -1,70 +0,0 @@ -# $Header$ -# -# (c) Copyright 1988 by the Massachusetts Institute of Technology. -# For copying and distribution information, please see the file -# . - -.SUFFIXES: -.SUFFIXES: .qc .c .o -CFLAGS= -O - -SRCS = dump_db.c bkup1.c bkup.c dumprest.c rest_db.c rest1.c rest.c -EQLIBS = /usr/rtingres/lib/libqlib /usr/rtingres/lib/compatlib - -.qc.c: - /usr/rtingres/bin/eqc $*.qc - -all: mrbackup mrrestore - -mrbackup: dump_db.o bkup1.o bkup.o dumprest.o - cc -o $@ ${CFLAGS} dump_db.o bkup1.o bkup.o dumprest.o ${EQLIBS} - -mrrestore: rest_db.o rest1.o rest.o dumprest.o - cc -o $@ ${CFLAGS} rest_db.o rest1.o rest.o dumprest.o ${EQLIBS} - -copy_backups: copy_backups.c - cc -o $@ ${CFLAGS} -I../include copy_backups.c \ - ../update/mr_update.o -L../lib \ - -lmoira -lgdb -lkrb -ldes -lmisc - -bkup.qc: ../db/newdb db2bkup.awk - cc -E ../db/newdb | awk -f db2bkup.awk > bkup.qc - -bkup1.qc: bkup.qc - -rest.qc: ../db/newdb db2rest.awk - cc -E ../db/newdb | 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 *.o mrbackup bkup.qc bkup1.qc mrrestore rest.qc rest1.qc - rm -f core *~ - rm -f copy_backups counts - rm -f bkup.c bkup1.c counts.c dump_db.c dumprest.c - rm -f rest.c rest1.c rest_db.c - -install: - install -c mrbackup ../bin/mrbackup - install -c mrrestore ../bin/mrrestore - install -c nightly.sh ../bin/nightly.sh - -depend: ${SRCS} - mkdep ${CFLAGS} ${SRCS} - -# DO NOT DELETE THIS LINE -- mkdep uses it. - -dump_db.o: dump_db.c /usr/include/stdio.h /usr/include/sys/file.h -dump_db.o: /usr/include/ctype.h /usr/include/mit-copyright.h dump_db.h -bkup1.o: bkup1.c /usr/include/stdio.h -bkup.o: bkup.c /usr/include/stdio.h dump_db.h -dumprest.o: dumprest.c /usr/include/stdio.h /usr/include/sys/file.h -dumprest.o: /usr/include/strings.h /usr/include/mit-copyright.h -rest_db.o: rest_db.c /usr/include/sys/file.h /usr/include/stdio.h -rest_db.o: /usr/include/ctype.h /usr/include/mit-copyright.h dump_db.h -rest1.o: rest1.c /usr/include/stdio.h -rest.o: rest.c /usr/include/stdio.h diff --git a/backup/copy_backups.c b/backup/copy_backups.c deleted file mode 100644 index a92eb7e0..00000000 --- a/backup/copy_backups.c +++ /dev/null @@ -1,108 +0,0 @@ -/* - * $Source$ - * $Author$ - * $Header$ - * - * Copyright (C) 1987 by the Massachusetts Institute of Technology - * - * $Log$ - * Revision 1.1 1987-08-22 17:03:18 wesommer - * Initial revision - * - */ - -#ifndef lint -static char *rcsid_copy_backups_c = "$Header$"; -#endif lint -#include -#include -#include -#include "update.h" - -char *whoami; -char host[BUFSIZ]; -char buf[BUFSIZ]; - -static struct update_desc info = { - 42, /* last_time_tried */ - 1, /* success */ - 12, /* interval */ - "backup", /* service_name */ - "ZEUS.MIT.EDU", /* host_name */ - "/tmp/frobnicate", /* target_path */ - 2, /* override */ - 1, /* enable */ - "/dev/null" - /* instructions */ -}; - -extern char *error_message(); -#include - -main(argc,argv) - int argc; - char **argv; -{ - int rc; - DIR *pd, *sd; - struct direct *pde, *sde; - - whoami = rindex(argv[0], '/'); - if (whoami) - whoami++; - else - whoami = argv[0]; - whoami = argv[0]; - if (chdir ("/u3/sms_backup") < 0) { - perror("can't change to /u3/sms_backup"); - exit(1); - } - - pd = opendir("."); - if (pd == NULL) { - perror("can't open sms_backup directory"); - exit(1); - } - - while ( (pde = readdir(pd)) != NULL ) { - char *dir_name = pde->d_name; - printf("Directory: %s\n", dir_name); - - if (dir_name[0] == '.') continue; /* ignore hidden files */ - - if (chdir(dir_name) < 0) { - perror(dir_name); - continue; - } - sd = opendir ("."); - if (sd == NULL) { - perror("Can't open ."); - goto dotdot; - } - while ( (sde = readdir(sd)) != NULL ) { - if (sde->d_name[0] == '.') continue; - - sprintf(buf, "/site/sms/sms_backup/%s/%s", dir_name, sde->d_name); - printf("Updating: %s\n", buf); - info.target_path = buf; - rc = sms_update_server(&info, sde->d_name); - if (rc) printf("return code: %s\n", error_message(rc)); - } - closedir(sd); - - dotdot: - chdir(".."); - } - closedir(pd); -} - -/* - * 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: - */ diff --git a/backup/db2bkup.awk b/backup/db2bkup.awk index 3a8e3999..db057023 100644 --- a/backup/db2bkup.awk +++ b/backup/db2bkup.awk @@ -6,48 +6,54 @@ # 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 */"; +BEGIN { + print "/* This file automatically generated */"; + print "/* Do not edit */\n"; print "#include "; print "EXEC SQL INCLUDE sqlca;"; print "#include \"dump_db.h\""; - print; + print "#define dump_date dump_str\n"; + print "/* This file automatically generated */" > "bkup1.dc"; - print "/* Do not edit */" >> "bkup1.dc" - print "#include " >> "bkup1.dc" - print "FILE *open_file();" >> "bkup1.dc" - print "do_backups(prefix)\n\tchar *prefix;\n{" >>"bkup1.dc" + print "/* Do not edit */\n" >> "bkup1.dc"; + print "#include " >> "bkup1.dc"; + print "FILE *open_file();" >> "bkup1.dc"; + print "do_backups(prefix)\n\tchar *prefix;\n{" >> "bkup1.dc"; } $1=="#" { next; } -/^create/ { printf "dump_%s(f)\nFILE *f;\n{\n\tEXEC SQL BEGIN DECLARE SECTION;\n", $3; - printf "\tdump_%s(open_file(prefix, \"%s\"));\n", $3, $3 >> "bkup1.dc" +/^create/ { + printf "dump_%s(f)\nFILE *f;\n{\n\tEXEC SQL BEGIN DECLARE SECTION;\n", $3; + printf "\tdump_%s(open_file(prefix, \"%s\"));\n", $3, $3 >> "bkup1.dc"; + tablename = $3; rangename = substr(tablename, 1, 1); count = 0; - next;} + next; +} NF>=2 { vname[count] = $1; - printf "/* %s */\n", $0 + printf "/* %s */\n", $0; if ($2 ~ /INTEGER/ || $2 ~ /SMALLINT/ || $2 ~ /INTEGER1/) { - printf "\tint\tt_%s;\n", vname[count] - vtype[count]="int" + printf "\tint\tt_%s;\n", vname[count]; + vtype[count]="int"; } else if ($2 ~ /CHAR\([0-9]*\)/) { - t = split($2, temp, "(") + t = split($2, temp, "("); if (t != 2) printf "Can't parse %s\n", $2; - t = split(temp[2], temp2, ")") + t = split(temp[2], temp2, ")"); if (t != 2) printf "Can't parse %s\n", temp[2]; printf "\tchar\tt_%s[%d];\n", vname[count], temp2[1]+1; if ($1 == "signature") { - vtype[count]="bin" + vtype[count]="bin"; } else { - vtype[count]="str" + vtype[count]="str"; } + vsize[count] = temp2[1]+1; } else if ($2 ~ /DATE/) { - printf "\tchar\tt_%s[26];\n", vname[count] - vtype[count]="str" + printf "\tchar\tt_%s[26];\n", vname[count]; + vtype[count]="date"; } else printf "Unknown data type %s\n", $2; count++; } @@ -55,25 +61,41 @@ NF>=2 { /^\);$/ { printf "\tEXEC SQL END DECLARE SECTION;\n"; printf "\tEXEC SQL DECLARE c_%s CURSOR FOR\n", tablename; - printf "\t\tSELECT * FROM %s;\n", tablename; + printf "\t\tSELECT\n"; + for (i = 0; i < count; i++) { + if (i != 0) { + print ","; + } + if(vtype[i] ~ /date/) { + printf "\t\t\tTO_CHAR(%s, 'DD-mon-YYYY HH24:MI:SS')", vname[i]; + } else printf "\t\t\t%s", vname[i]; + } + printf " FROM %s;\n", tablename; + printf "\tEXEC SQL OPEN c_%s;\n", tablename; - printf "\twhile(1) {\n\tEXEC SQL FETCH c_%s INTO\n", tablename; + printf "\twhile(1) {\n\t\tEXEC SQL FETCH c_%s INTO\n", tablename; for (i = 0; i < count; i++) { if (i != 0) printf ",\n"; - printf "\t\t:t_%s", vname[i]; + printf "\t\t\t:t_%s", vname[i]; } printf ";\n"; - printf "\tif(sqlca.sqlcode != 0) break;\n"; + printf "\t\tif(sqlca.sqlcode != 0) break;\n"; for (i = 0; i < count; i++) { - if (i != 0) print "\tdump_sep(f);" - printf "\tdump_%s(f, t_%s);\n", vtype[i], vname[i]; + if (i != 0) print "\t\tdump_sep(f);"; + if (vtype[i] ~ /str/) { + printf "\t\tdump_str(f, strtrim(t_%s));\n", vname[i]; + } else { + printf "\t\tdump_%s(f, t_%s);\n", vtype[i], vname[i]; + } } printf "\t\tdump_nl(f);\n"; printf "\t}\n"; printf "\tEXEC SQL CLOSE c_%s;\n", tablename; printf "\tsafe_close(f);\n"; - printf "}\n"; + printf "}\n\n"; } -END { print "/* All done */" - print "}" >>"bkup1.dc" + +END { + print "/* All done */"; + print "}" >> "bkup1.dc"; } diff --git a/backup/db2rest.awk b/backup/db2rest.awk index fd07bb68..37531a4e 100644 --- a/backup/db2rest.awk +++ b/backup/db2rest.awk @@ -6,59 +6,73 @@ # 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 */"; +BEGIN { + print "/* This file automatically generated */"; + print "/* Do not edit */\n"; print "#include "; print "EXEC SQL INCLUDE sqlca;"; - print "void parse_nl(), parse_str(), parse_sep();" + print "void parse_nl(), parse_str(FILE *, char *, int), parse_sep();\n"; + print "/* This file automatically generated */" > "rest1.dc"; - print "/* Do not edit */" >> "rest1.dc"; + print "/* Do not edit */\n" >> "rest1.dc"; print "#include " >> "rest1.dc"; print "FILE *open_file();" >> "rest1.dc"; - print "do_restores(prefix)\n\tchar *prefix;\n{" >>"rest1.dc"; + print "do_restores(prefix)\n\tchar *prefix;\n{" >> "rest1.dc"; } $1=="#" { next; } -/^create/ { printf "restore_%s(f)\nFILE *f;\n", $3; +/^create/ { + printf "restore_%s(f)\nFILE *f;\n", $3; print "{\n\tEXEC SQL BEGIN DECLARE SECTION;"; printf "\trestore_%s(open_file(prefix, \"%s\"));\n", $3, $3 >> "rest1.dc"; + tablename = $3; rangename = substr(tablename, 1, 1); count = 0; - next; } + next; +} NF >= 2 { vname[count] = $1; - printf "/* %s */\n", $0 + printf "/* %s */\n", $0; if ($2 ~ /INTEGER/ || $2 ~ /SMALLINT/ || $2 ~ /INTEGER1/) { - printf "\tint\tt_%s;\n", vname[count] - vtype[count]="int" + printf "\tint\tt_%s;\n", vname[count]; + vtype[count]="int"; } else if ($2 ~ /CHAR\([0-9]*\)/) { - t = split($2, temp, "(") + t = split($2, temp, "("); if (t != 2) printf "Can't parse %s\n", $2; - t = split(temp[2], temp2, ")") + t = split(temp[2], temp2, ")"); if (t != 2) printf "Can't parse %s\n", temp[2]; printf "\tchar\tt_%s[%d];\n", vname[count], temp2[1]+1; + if ($1 == "signature") { + vtype[count]="bin"; + printf "\tEXEC SQL VAR t_signature IS STRING(%d);\n", temp2[1]+1; + } else vtype[count]="str"; vsize[count] = temp2[1]+1; - vtype[count]="str" } else if ($2 ~ /DATE/) { printf "\tchar\tt_%s[26];\n", vname[count]; - vtype[count]="str"; - vsize[count]=26; + vtype[count]="date"; } else printf "Unknown data type %s\n", $2; count++; } /^\);$/ { - print "\tEXEC SQL END DECLARE SECTION;\n"; - print "\twhile(!feof(f)) {" + printf "\tEXEC SQL END DECLARE SECTION;\n\tint count=0;\n"; + + print "\twhile(!feof(f)) {"; + print "\t\tif(!(++count%100)) {\n\t\t\tEXEC SQL COMMIT;\n\t\t}\n"; + for (i = 0; i < count; i++) { - if (i != 0) print "\t\tparse_sep(f);" + 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;" + } else if (vtype[i] ~ /date/) { + printf "\t\tparse_str(f, t_%s, 26);\n", vname[i]; + } else { + printf "\t\tparse_str(f, t_%s, %d);\n", vname[i], vsize[i]; + } + if (i == 0) print "\t\tif (feof(f)) break;"; } printf "\t\tparse_nl(f);\n" @@ -70,14 +84,26 @@ NF >= 2 { printf ")\n\t\tVALUES (\n"; for (i = 0; i < count; i++) { if (i != 0) printf ",\n"; - printf "\t\t\t:t_%s", vname[i]; + if (vtype[i] ~ /date/) { + printf "\t\t\tTO_DATE(NVL(:t_%s,TO_CHAR(SYSDATE, 'DD_mon-YYYY HH24:MI:SS')), 'DD-mon-YYYY HH24:MI:SS')", vname[i]; + } else if(vtype[i] ~ /int/) { + printf "\t\t\t:t_%s", vname[i]; + } else { + printf "\t\t\tNVL(:t_%s,CHR(0))", vname[i]; + } } - printf ");\n\t\tif (sqlca.sqlcode != 0) {\n" - printf "\t\t\tcom_err(\"restore\", 0, \"insert failed\");\n" - printf "\t\t\texit(2);\n\t\t}\n\t}\n" - printf "\t(void) fclose(f);\n" - printf "}\n" + printf ");\n\t\tif (sqlca.sqlcode != 0) {\n"; + printf "\t\t\tsqlca.sqlerrm.sqlerrmc[sqlca.sqlerrm.sqlerrml]=0;\n"; + printf "\t\t\tprintf(\"%%s\\n\", sqlca.sqlerrm.sqlerrmc);\n"; + printf "\t\t\tcom_err(\"restore\", 0, \"insert failed\");\n"; + printf "\t\t\texit(2);\n\t\t}\n\t}\n"; + printf "\t(void) fclose(f);\n"; + printf "\tEXEC SQL COMMIT;\n"; + printf "}\n\n"; } -END { print "/* All done */" - print "}" >>"rest1.dc"; + + +END { + print "/* All done */"; + print "}" >> "rest1.dc"; } diff --git a/backup/dump_db.dc b/backup/dump_db.dc index f915e8a0..b0dcecbc 100644 --- a/backup/dump_db.dc +++ b/backup/dump_db.dc @@ -18,6 +18,7 @@ static char *rcsid_dump_db_c = "$Header$"; #include #include +#include #include #include EXEC SQL INCLUDE sqlca; @@ -32,6 +33,9 @@ EXEC SQL INCLUDE sqlca; FILE *open_file(); char act[257]; +EXEC SQL BEGIN DECLARE SECTION; +char *db="moira"; +EXEC SQL END DECLARE SECTION; main(argc, argv) int argc; @@ -46,7 +50,7 @@ main(argc, argv) } prefix = argv[1]; - bzero(act, 256); + memset(act, 0, 256); for (i=0; i<' '; i++) act[i]=2; for (i=128; i<256; i++) act[i]=2; @@ -54,12 +58,11 @@ main(argc, argv) act['\\']=1; act[127]=2; - EXEC SQL CONNECT moira; - EXEC SQL set lockmode session where level = table; + EXEC SQL CONNECT :db IDENTIFIED BY :db; do_backups(prefix); - EXEC SQL DISCONNECT; + EXEC SQL COMMIT; exit(0); } @@ -81,12 +84,11 @@ dump_str(f, str) register FILE *f; register char *str; { - char *strtrim(); - register char *ibp = strtrim(str); + register char *ibp; register int c; /* PCC doesn't put chars in registers.. */ register int t; - for (; c = (unsigned char) *ibp; ibp++) { + for (ibp = str; c = (unsigned char) *ibp; ibp++) { switch(act[c]) { case 1: if (putc1('\\', f) < 0) wpunt(); diff --git a/backup/dumprest.dc b/backup/dumprest.dc index fa523c2d..1de153dd 100644 --- a/backup/dumprest.dc +++ b/backup/dumprest.dc @@ -14,14 +14,11 @@ static char *rcsid_dumprest_qc = "$Header$"; #endif lint #include -#include -#include #include punt(msg) char *msg; { perror(msg); - EXEC SQL DISCONNECT; exit(1); } diff --git a/backup/esqlc_fix.pl b/backup/esqlc_fix.pl deleted file mode 100644 index 559ba729..00000000 --- a/backup/esqlc_fix.pl +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/athena/bin/perl -i.bak - -# Limitations: -# 1. Schema must have "create table tablename" all on one line -# 2. Fields (columns) must be declared "NOT NULL WITH DEFAULT" -# 3. C variables corresponding to database fields must use the -# database field name with "t_" prefixed. -# 4. Field names, table names, and C "t_" variable names are of the same case -# 5. Only references within CURSOR loops are corrected. - - -# Step 1. Read the schema, so we know the proper field lengths -open(SCHEMA,"../db/schema") || die "Could not open schema, stopped\n"; - -while() { - if(/create\s+table\s+/) { - ($table,$ignore) = split(' ',$'); - next; - } - if(/\s+(\w+)\s+(VAR)?CHAR\((\d+)\)\s+NOT NULL WITH DEFAULT/) { - $fields{$table . "." . $1} = $3; - } -} - - -# Step 2. Read the code to be cleaned up - -# Pass through most lines. -# Note the opening and closing of cursors. -# Play with IIcsGetio. Change 4th argument if it's wrong. - -while(<>) { - if(/IIwritio\(.*"select.*from\s+(\w+)"\);/) { - $table = $1; - next; - } - if(/IIcsGetio\((.*,.*,.*,(\d+),&?t_(\w+))\);/) { - $width = $2; - $field = $3; - - $tablefield = $table . "." . $field; - $shouldbe = $fields{$tablefield}; - - if( $shouldbe && $shouldbe != $width ) { - s/(\(.*,.*,.*,)(\d+),/\1$shouldbe,/; - } - } -} continue { - print; -} - diff --git a/backup/nightly.sh b/backup/nightly.sh index 8b7bb9a6..1732c01c 100644 --- a/backup/nightly.sh +++ b/backup/nightly.sh @@ -4,12 +4,11 @@ # # BKUPDIRDIR=/backup -PATH=/bin:/athena/bin:/usr/athena/bin:/usr/bin:/usr/ucb:/usr/new; export PATH -. /usr/ingres/sqluser.profile +PATH=/usr/athena/bin:/bin:/usr/bin:/usr/ucb; export PATH +ORACLE_HOME=/usr/oracle; export ORACLE_HOME +ORACLE_SID=moira; export ORACLE_SID chdir ${BKUPDIRDIR} -# /moira/bin/counts #include +#include #include #include EXEC SQL INCLUDE sqlca; @@ -38,7 +39,7 @@ main(argc, argv) } db = argv[1]; - if (!yes_or_no("Do you *REALLY* want to wipe the SMS database?")) { + if (!yes_or_no("Do you *REALLY* want to wipe the moira database?")) { printf("I didn't think so\n"); exit(1); } @@ -50,13 +51,11 @@ main(argc, argv) printf("Opening database: "); (void) fflush(stdout); - EXEC SQL CONNECT :db; + EXEC SQL CONNECT :db IDENTIFIED BY :db; if (sqlca.sqlcode != 0) { com_err(argv[0], 0, "Ingres database open failed"); exit(1); } - EXEC SQL SET AUTOCOMMIT ON; - printf(" done\n"); printf("Prefix of backup to restore: "); @@ -73,7 +72,6 @@ main(argc, argv) do_restores(prefix); printf("Restore complete\n"); EXEC SQL COMMIT; - EXEC SQL DISCONNECT; exit(0); /*NOTREACHED*/ } @@ -138,14 +136,14 @@ int parse_int(f) return(val * sign); } -void parse_str(f, buf, len) +void parse_str(f, buf, maxlen) register FILE *f; register char *buf; - register int len; /* incl trailing NULL */ + register int maxlen; { - register int c; + register int c, len=0; - while ((c = getc(f)) != EOF && c != SEP_CHAR && c != '\n' && len > 0) { + while ((c = getc(f)) != EOF && c != SEP_CHAR && c != '\n' && len < maxlen) { if (c == '\\') { c = getc(f); if (isdigit(c)) { @@ -157,15 +155,17 @@ void parse_str(f, buf, len) punt("Broken \\###"); /* Convert to ASCII code: */ *buf++ = (((c-'0')<<6) + ((c1-'0')<<3) + c2-'0'); + len++; } else if (c == '\\' || c == SEP_CHAR) { *buf++ = c; - --len; + len++; } else punt ("Broken '\\'"); } else { *buf++ = c; - --len; + len++; } } + *buf='\0'; if (c == EOF) return; @@ -174,7 +174,6 @@ void parse_str(f, buf, len) while ((c = getc(f)) != EOF && c != SEP_CHAR && c != '\n'); (void) ungetc(c, f); } else { - *buf++ = 0; (void) ungetc(c, f); } } diff --git a/backup/restore_from_backup b/backup/restore_from_backup deleted file mode 100644 index d987cd43..00000000 --- a/backup/restore_from_backup +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/csh - -set path=(. /bin /usr/bin ~rtingres/bin) - -if ($user != smsdba) then - echo "This script must be run as smsdba" - exit 1 -endif - -createdb smstemp -if ($status) then - echo "unable to create database" - exit 2 -endif - -cd /mit/smsdev/backup - -ingres smstemp < dodbbuild - -smsrestore - -ingres smstemp < dodbopt - -sysmod smstemp - -echo "When you are satisfied that this is correct, rename the smstemp database" -echo "to sms by renaming directories under ~rtingres/data/default, then run" -echo "'finddbs -r' to fix the ingres database database." - -exit 0