]> andersk Git - moira.git/blame - afssync/migrate.qc
Initial revision
[moira.git] / afssync / migrate.qc
CommitLineData
1a4b03d5 1/* $Header$ */
2
3#include <stdio.h>
4#include <ctype.h>
5
6
5a2cfcb4 7int ingerr();
8
1a4b03d5 9main(argc, argv)
10int argc;
11char **argv;
12{
13 int debug = 0;
14 FILE *input = stdin;
15 char buf[1024], junk[129];
16## int cell, quota, cnt, mach, oquota, id, who;
17## char name[81], type[9], volume[81], path[129], quotas[33];
18## char oname[129],otype[9];
19 char **arg = argv, *first_indir(), *second_indir(), *course_indir();
20
21 cnt = 0;
22
23 while (++arg - argv < argc) {
24 if (**arg == '-') {
25 switch ((*arg)[1]) {
26 case 'd':
27 debug = atoi((*arg)[2] ? *arg+2 : *++arg);
28 break;
29 default:
30 fprintf(stderr, "Usage: %s [-d level] [inputfile]\n",
31 argv[0]);
32 exit(1);
33 }
34 } else {
35 input = fopen(*arg, "r");
36 if (input == NULL) {
37 fprintf(stderr, "Unable to open in put file %s\n", *arg);
38 exit(1);
39 }
40 }
41 }
42
43 if (debug > 4)
44 setenv("ING_SET", "set printqry");
5a2cfcb4 45 setlinebuf(stdout);
46 setlinebuf(stderr);
1a4b03d5 47
48 if (debug) { printf("Opening database..."); fflush(stdout);}
5a2cfcb4 49 IIseterr(ingerr);
1a4b03d5 50## ingres sms
51 if (debug) printf("done.\n");
52
53## range of f is filesys
54## range of m is machine
55## range of q is #quota
56## retrieve (cell = machine.mach_id) where machine.#name="ATHENA.MIT.EDU"
57## retrieve (who = users.users_id) where users.login="root"
1a4b03d5 58
59 while (!feof(input)) {
60 fgets(buf, sizeof(buf), input);
61 if (sscanf(buf, "%s %s %s %s %s %s %s %s %s %s %s %s",
62 name, type, junk, junk, junk, junk,
63 quotas, junk, junk, junk, junk, junk) < 12) {
64 fprintf(stderr, "unable to parse line: %s\n", buf);
65 continue;
66 }
67 quota = atoi(quotas);
68 if (!strcmp(type, "HOMEDIR")) {
69 sprintf(path, "/afs/athena.mit.edu/user/%s/%s/%s",
70 first_indir(name), second_indir(name), name);
71 } else if (!strcmp(type, "COURSE")) {
72 sprintf(path, "/afs/athena.mit.edu/course/%s/%s",
73 course_indir(name), name);
74 } else if (!strcmp(type, "ACTIVITY")) {
75 sprintf(path, "/afs/athena.mit.edu/activity/%s/%s",
76 first_indir(name), name);
77 } else if (!strcmp(type, "APROJ")) {
78 sprintf(path, "/afs/athena.mit.edu/astaff/project/%s",
79 name);
80 } else if (!strcmp(type, "PROJECT")) {
81 sprintf(path, "/afs/athena.mit.edu/project/%s",
82 name);
83 } else if (!strcmp(type, "AREF")) {
84 sprintf(path, "/afs/athena.mit.edu/astaff/reference/%s",
85 name);
86 } else if (!strcmp(type, "REF")) {
87 sprintf(path, "/afs/athena.mit.edu/reference/%s",
88 name);
89 } else if (!strcmp(type, "CONTRIB")) {
90 sprintf(path, "/afs/athena.mit.edu/contrib/%s",
91 name);
92 } else if (!strcmp(type, "SW")) {
93 sprintf(path, "/afs/athena.mit.edu/software/%s",
94 name);
95 } else if (!strcmp(type, "SYSTEM")) {
96 sprintf(path, "/afs/athena.mit.edu/system/%s",
97 name);
98 } else {
99 fprintf(stderr, "Don't know how to deal with type %s\n", type);
100 continue;
101 }
102## repeat retrieve (otype = f.#type, mach = f.mach_id, oname = f.#name)
103## where f.label = @name {
104 strtrim(oname);
105 printf("changing FS %s (%s, %s on %d) to (AFS, %s)\n",
106 name, type, oname, mach, path);
107## }
108## repeat replace f (phys_id=0, #type="AFS", mach_id=cell,
109## #name=@path, modtime=date("now"),
110## modby=who, modwith="migrate")
111## where f.label = @name
112## repeat retrieve (type = q.#type, id=q.entity_id, oquota=q.#quota)
113## where q.filsys_id = f.filsys_id and f.label=@name {
114 printf("removing quota (%d (%s %d) on %s)\n",
115 oquota, type, id, name);
116## }
117## repeat delete q where q.filsys_id = f.filsys_id and f.label=@name
118 printf("adding quota of %d on %s\n", quota, name);
119## repeat append #quota (filsys_id = f.filsys_id, #type="ANY",
120## entity_id=0, phys_id=0,
121## #quota=@quota, modtime=date("now"),
122## modby=who, modwith="migrate")
123## where f.label= @name
124 cnt++;
125 }
126
127 if (cnt > 0) {
128## replace tblstats (updates = tblstats.updates + cnt,
129## modtime = date("now"))
130## where tblstats.tbl = "filesys"
131## replace tblstats (updates = tblstats.updates + cnt,
132## modtime = date("now"))
133## where tblstats.tbl = "quota"
134 }
135
1a4b03d5 136 if (debug) printf("Done.\n");
137 exit(0);
138}
139
140
141char *first_indir(name)
142char *name;
143{
144 static char buf[10];
145
146 if (islower(name[0]))
147 sprintf(buf, "%c", name[0]);
148 else
149 sprintf(buf, "other");
150 return(buf);
151}
152
153char *second_indir(name)
154char *name;
155{
156 static char buf[10];
157
158 if (islower(name[1]))
159 sprintf(buf, "%c", name[1]);
160 else
161 sprintf(buf, "other");
162 return(buf);
163}
164
165char *course_indir(name)
166char *name;
167{
168 static char buf[10];
169 char *src, *dst;
170
171 dst = buf;
172 for (src = name; *src && isdigit(*src); src++)
173 *dst++ = *src;
174
175 if (dst == buf)
176 strcpy(buf, "other");
177 else
178 *dst = 0;
179
180 return(buf);
181}
5a2cfcb4 182
183
184ingerr(num)
185int *num;
186{
187 fprintf(stderr, "An ingres error ocurred, code %d\n", *num);
188 switch (*num) {
189 case 4700:
190 fprintf(stderr, "Deadlock**************************\n");
191 break;
192 default:
193 fprintf(stderr, "Aborting\n");
194 exit(1);
195 }
196 return(0);
197}
This page took 0.435904 seconds and 5 git commands to generate.