3 * This program dumps the Moira database to a series of output files
4 * which can be later read back into Moira in the event of a crash.
6 * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology.
7 * For copying and distribution information, please see the file
11 #include <mit-copyright.h>
20 EXEC SQL INCLUDE sqlca;
24 EXEC SQL BEGIN DECLARE SECTION;
26 EXEC SQL END DECLARE SECTION;
28 int main(int argc, char **argv)
34 fprintf(stderr, "Usage: %s prefix\n", argv[0]);
39 EXEC SQL CONNECT :db IDENTIFIED BY :db;
47 void dump_int(FILE *f, int n)
50 sprintf(buf, "%d", n);
56 punt("can't write backup file");
59 void dump_str(FILE *f, char *str)
61 unsigned char *ibp, c;
64 for (ibp = str; (c = *ibp); ibp++)
66 if (c < 32 || c > 126 || c == SEP_CHAR || c == '\\')
68 if (putc('\\', f) < 0)
70 t = ((c >> 6) & 7) + '0';
73 t = ((c >> 3) & 7) + '0';
88 void safe_close(FILE *stream)
90 if (fflush(stream) == EOF)
91 punt("Unable to fflush");
92 if (fsync(fileno(stream)) != 0)
93 punt("Unable to fsync");
97 FILE *open_file(char *prefix, char *suffix)
103 strcpy(name, prefix);
104 strcat(name, suffix);
106 fd = open(name, O_CREAT|O_WRONLY|O_EXCL, 0644);
112 fprintf(stderr, "fdopen of ");
115 fprintf(stderr, "Working on %s\n", name);
120 * Trim whitespace off the tail end of a string
122 char *endtrim(char *save)