]> andersk Git - moira.git/blob - backup/dump_db.qc
Initial revision
[moira.git] / backup / dump_db.qc
1 /*
2  *      $Source$
3  *      $Author$
4  *      $Header$
5  *
6  *      Copyright (C) 1987 by the Massachusetts Institute of Technology
7  *
8  *      This program dumps the SMS database to a series of output files
9  * which can be later read back into SMS in the event of a crash.
10  * 
11  *      $Log$
12  *      Revision 1.1  1987-07-11 19:51:05  wesommer
13  *      Initial revision
14  *
15  *
16  */
17
18 #ifndef lint
19 static char *rcsid_dump_db_c = "$Header$";
20 #endif lint
21
22 #include <stdio.h>
23 #include <sys/file.h>
24
25 FILE *open_file();
26
27 main(argc, argv)
28     int argc;
29     char **argv;
30 {
31     char *prefix;
32     
33     if (argc != 2) {
34         fprintf(stderr, "Usage: smsbackup prefix\n");
35         exit(1);
36     }
37     prefix = argv[1];
38
39 ##  ingres sms 
40     
41     do_backups(prefix);
42     
43 ##  exit
44     exit(0);
45 }
46
47 FILE *open_file(prefix, suffix)
48     char *prefix, *suffix;
49 {
50     char name[BUFSIZ];
51     int fd;
52     FILE *f;
53     
54     strcpy(name, prefix);
55     strcat(name, suffix);
56
57     fd = open(name, O_CREAT|O_WRONLY|O_EXCL, 0644);
58     if (fd < 0) {
59         punt(name);
60     }
61     f = fdopen(fd, "w");
62     if (f == NULL) {
63         fprintf(stderr, "fdopen of ");
64         punt(name);
65     }
66     fprintf(stderr, "Working on %s\n", name);
67     return(f);
68 }
69
70 dump_int(f, n)
71     FILE *f;
72     int n;
73 {
74     char buf[1024];
75     sprintf(buf, "%d", n);
76     dump_str(f, buf);
77 }
78
79 dump_nl(f)
80 {
81     dump_str(f, "\n");
82 }
83
84 /*
85  * Should check that we're not printing non-printing characters or
86  * ':' characters here (??? recovery if we do??)
87  */
88
89 dump_str(f, str)
90     FILE *f;
91     char *str;
92 {
93     register int len = strlen(str);
94
95     if (fwrite(str, 1, len, f) != len) punt("short write");
96 }
97
98
99 punt(msg)
100         char *msg;
101 {
102         perror(msg);
103 ##      exit
104         exit(1);
105 }
106
107 safe_close(stream)
108         FILE *stream;
109 {
110         if (fflush(stream) == EOF)
111                 punt("Unable to fflush");
112         if (fsync(fileno(stream)) != 0) 
113                 punt("Unable to fsync");
114         fclose(stream);
115 }       
116
117 /*
118  * Local Variables:
119  * mode: c
120  * c-indent-level: 4
121  * c-continued-statement-offset: 4
122  * c-brace-offset: -4
123  * c-argdecl-indent: 4
124  * c-label-offset: -4
125  * End:
126  */
This page took 0.060192 seconds and 5 git commands to generate.