]> andersk Git - moira.git/blame - backup/dump_db.qc
changed backup hosts & user
[moira.git] / backup / dump_db.qc
CommitLineData
6fb7536b 1/*
2 * $Source$
3 * $Author$
4 * $Header$
5 *
f0a492af 6 * (c) Copyright 1988 by the Massachusetts Institute of Technology.
7 * For copying and distribution information, please see the file
8 * <mit-copyright.h>.
6fb7536b 9 *
10 * This program dumps the SMS database to a series of output files
11 * which can be later read back into SMS in the event of a crash.
12 *
6fb7536b 13 */
14
15#ifndef lint
16static char *rcsid_dump_db_c = "$Header$";
17#endif lint
18
19#include <stdio.h>
20#include <sys/file.h>
d55654f4 21#include <ctype.h>
f0a492af 22#include <mit-copyright.h>
2e29fd6d 23#include "dump_db.h"
d55654f4 24
25/* putc without the line buffer hair */
26
27#define putc1(x, p) (--(p)->_cnt >= 0 ?\
28 (int)(*(unsigned char *)(p)->_ptr++ = (x)) :\
29 _flsbuf((unsigned char)(x), p))
6fb7536b 30
31FILE *open_file();
32
d55654f4 33char act[128];
34
6fb7536b 35main(argc, argv)
36 int argc;
37 char **argv;
38{
39 char *prefix;
d55654f4 40 register int i;
6fb7536b 41
42 if (argc != 2) {
43 fprintf(stderr, "Usage: smsbackup prefix\n");
44 exit(1);
45 }
46 prefix = argv[1];
47
d55654f4 48 bzero(act, 128);
49
2e29fd6d 50 act[SEP_CHAR]=1;
d55654f4 51 act['\\']=1;
52 act[127]=2;
53 for (i=0; i<' '; i++) act[i]=2;
54
6fb7536b 55## ingres sms
51641848 56## set lockmode session where level = table
57## begin transaction
58
6fb7536b 59 do_backups(prefix);
51641848 60
61## end transaction
6fb7536b 62## exit
63 exit(0);
64}
65
6fb7536b 66dump_int(f, n)
67 FILE *f;
68 int n;
69{
70 char buf[1024];
d55654f4 71 (void) sprintf(buf, "%d", n);
6fb7536b 72 dump_str(f, buf);
73}
74
d55654f4 75wpunt()
6fb7536b 76{
d55654f4 77 punt("can't write backup file");
6fb7536b 78}
79
6fb7536b 80dump_str(f, str)
d55654f4 81 register FILE *f;
82 register char *str;
6fb7536b 83{
d6224b2e 84 char *strtrim();
85 register char *ibp = strtrim(str);
d55654f4 86 register int c; /* PCC doesn't put chars in registers.. */
87 for (; c = *ibp; ibp++) {
88 c = toascii(c); /* punt 8th bit */
89 switch(act[c]) {
90 register int t;
91 case 1:
92 if (putc1('\\', f) < 0) wpunt();
93 /* fall thru.. */
94 case 0:
95 if (putc1(c, f) < 0) wpunt();
96
97 break;
98 case 2:
99 if (putc1('\\', f) < 0) wpunt();
100 t = ((c>>6)&7) + '0';
101 if (putc1(t,f) < 0) wpunt();
102 t = ((c>>3)&7) + '0';
103 if (putc1(t,f) < 0) wpunt();
104 t = (c&7) + '0';
105 if (putc1(t,f) < 0) wpunt();
106 fprintf(stderr, "control character \\%03o\n", c);
107 break;
108
109 default:
110 punt("Can't get here");
111 }
112 }
6fb7536b 113}
114
115safe_close(stream)
116 FILE *stream;
117{
118 if (fflush(stream) == EOF)
119 punt("Unable to fflush");
120 if (fsync(fileno(stream)) != 0)
121 punt("Unable to fsync");
d55654f4 122 (void) fclose(stream);
6fb7536b 123}
124
d55654f4 125FILE *open_file(prefix, suffix)
126 char *prefix, *suffix;
127{
128 char name[BUFSIZ];
129 int fd;
130 FILE *f;
131
132 (void) strcpy(name, prefix);
133 (void) strcat(name, suffix);
134
135 fd = open(name, O_CREAT|O_WRONLY|O_EXCL, 0644);
136 if (fd < 0) {
137 punt(name);
138 }
139 f = fdopen(fd, "w");
140 if (f == NULL) {
141 fprintf(stderr, "fdopen of ");
142 punt(name);
143 }
144 fprintf(stderr, "Working on %s\n", name);
145 return(f);
146}
147
d6224b2e 148
149/*
150 * Trim whitespace off both ends of a string.
151 */
152char *strtrim(save)
153 register char *save;
154{
155 register char *t, *s;
156
157 s = save;
158 while (isspace(*s)) s++;
159 /* skip to end of string */
160 if (*s == '\0') {
161 *save = '\0';
162 return(save);
163 }
164
165 for (t = s; *t; t++) continue;
166 while (t > s) {
167 --t;
168 if (!isspace(*t)) {
169 t++;
170 break;
171 }
172 }
173 *t = '\0';
174 return s;
175}
This page took 0.413095 seconds and 5 git commands to generate.