2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <sys/types.h>
14 #include <sys/statfs.h>
17 #include <sys/errno.h>
19 #include <netinet/in.h>
22 #include <rx/rx_globals.h>
24 #include <afs/vlserver.h>
26 #include <afs/cellconfig.h>
29 #include <afs/afsint.h>
32 #include <afs/tcdata.h>
37 #define SERVERNAME "server1"
38 extern struct rx_securityClass *rxnull_NewClientSecurityObject();
41 struct tc_tapeSet ttapeSet;
42 char tdumpSetName[TC_MAXNAMELEN];
43 tc_dumpArray tdumps; /*defined by rxgen */
44 tc_restoreArray trestores;/*defined by rxgen */
46 struct tc_dumpStat tstatus;
49 struct rx_connection *UV_Bind(aserver, port)
50 afs_int32 aserver, port;
52 register struct rx_connection *tc;
53 struct rx_securityClass *uvclass;
55 uvclass = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
56 tc = rx_NewConnection(aserver, htons(port), TCSERVICE_ID, uvclass, 0);
61 /* return host address in network byte order */
62 afs_int32 GetServer(aname)
64 register struct hostent *th;
67 register afs_int32 code;
69 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
71 addr = (b1<<24) | (b2<<16) | (b3<<8) | b4;
72 return htonl(addr); /* convert to network order (128 in byte 0) */
74 th = gethostbyname(aname);
76 bcopy(th->h_addr, &addr, sizeof(addr));
81 static PerformDump(as)
82 register struct cmd_syndesc *as;
84 struct rx_connection *aconn;
87 struct tc_dumpDesc *ptr;
89 afs_int32 parentDumpID,dumpLevel;
91 server = GetServer(SERVERNAME);
93 printf("cant get server id \n");
98 strcpy(tdumpSetName,"Test");
100 ttapeSet.maxTapes = 10;
101 fp = fopen("dumpScr","r");
102 fscanf(fp,"%u %u %u\n",&tdumps.tc_dumpArray_len,&ttapeSet.a,&ttapeSet.b);
103 strcpy(ttapeSet.format,"tapeName%u");
104 strcpy(ttapeSet.tapeServer,"diskTapes");
105 tdumps.tc_dumpArray_val = (struct tc_dumpDesc *) (malloc(tdumps.tc_dumpArray_len*sizeof(struct tc_dumpDesc)));
106 ptr = tdumps.tc_dumpArray_val;
107 for(i = 0; i < tdumps.tc_dumpArray_len; i++){
108 fscanf(fp,"%s\n",ptr->name);
109 fscanf(fp,"%s\n",ptr->hostAddr);
110 fscanf(fp,"%u %u %u\n",&ptr->vid,&ptr->partition,&ptr->date);
114 aconn = UV_Bind(server, TCPORT);
115 code = TC_PerformDump(aconn, tdumpSetName, &ttapeSet,&tdumps,parentDumpID,dumpLevel,&tdumpID);
116 free(tdumps.tc_dumpArray_val);
118 printf("call to TC_PerformDump failed %u\n",code);
121 printf("dumpid returned %u\n",tdumpID);
124 static PerformRestore(as)
125 register struct cmd_syndesc *as;
127 struct rx_connection *aconn;
131 struct tc_restoreDesc *ptr;
133 server = GetServer(SERVERNAME);
135 printf("cant get server id \n");
138 aconn = UV_Bind(server, TCPORT);
139 strcpy(tdumpSetName,"");
140 strcpy(tdumpSetName,"Test");
141 fp = fopen("restoreScr","r");
142 fscanf(fp,"%u\n",&trestores.tc_restoreArray_len);
143 trestores.tc_restoreArray_val = (struct tc_restoreDesc *) malloc(trestores.tc_restoreArray_len*sizeof(struct tc_restoreDesc));
144 ptr = trestores.tc_restoreArray_val;
145 for(i = 0; i < trestores.tc_restoreArray_len; i++){
146 fscanf(fp,"%s\n",ptr->oldName);
147 fscanf(fp,"%s\n",ptr->newName);
148 fscanf(fp,"%s\n",ptr->tapeName);
149 fscanf(fp,"%s\n",ptr->hostAddr);
150 fscanf(fp,"%u %u %u %u %d %u\n",&ptr->origVid,&ptr->vid,&ptr->partition,&ptr->flags,&ptr->frag,&ptr->position);
154 code = TC_PerformRestore(aconn, tdumpSetName, &trestores,&tdumpID);
156 printf("call to TC_PerformRestore failed %u\n",code);
159 printf("dumpid returned %u\n",tdumpID);
162 register struct cmd_syndesc *as;
164 struct rx_connection *aconn;
166 server = GetServer(SERVERNAME);
168 printf("cant get server id \n");
171 tdumpID = atol(as->parms[0].items->data);
172 aconn = UV_Bind(server, TCPORT);
173 code = TC_CheckDump(aconn,tdumpID, &tstatus);
175 printf("call to TC_CheckDump failed %u\n",code);
181 register struct cmd_syndesc *as;
183 struct rx_connection *aconn;
185 server = GetServer(SERVERNAME);
187 printf("cant get server id \n");
190 tdumpID = atol(as->parms[0].items->data);
191 aconn = UV_Bind(server, TCPORT);
192 code = TC_AbortDump(aconn,tdumpID);
194 printf("call to TC_AbortDump failed %u\n",code);
199 static WaitForDump(as)
200 register struct cmd_syndesc *as;
202 struct rx_connection *aconn;
204 server = GetServer(SERVERNAME);
206 printf("cant get server id \n");
209 tdumpID = atol(as->parms[0].items->data);
210 aconn = UV_Bind(server, TCPORT);
211 code = TC_WaitForDump(aconn,tdumpID);
213 printf("call to TC_WaitForDump failed %u\n",code);
219 register struct cmd_syndesc *as;
221 struct rx_connection *aconn;
223 server = GetServer(SERVERNAME);
225 printf("cant get server id \n");
228 tdumpID = atol(as->parms[0].items->data);
229 aconn = UV_Bind(server, TCPORT);
230 code = TC_EndDump(aconn,tdumpID);
232 printf("call to TC_EndDump failed %u\n",code);
237 static MyBeforeProc(as,arock)
238 struct cmd_syndesc *as;
244 printf("Could not initialize rx.\n");
248 rx_SetRxDeadTime(50);
252 #include "AFS_component_version_number.c"
257 register afs_int32 code;
259 register struct cmd_syndesc *ts;
263 * The following signal action for AIX is necessary so that in case of a
264 * crash (i.e. core is generated) we can include the user's data section
265 * in the core dump. Unfortunately, by default, only a partial core is
266 * generated which, in many cases, isn't too useful.
268 struct sigaction nsa;
270 sigemptyset(&nsa.sa_mask);
271 nsa.sa_handler = SIG_DFL;
272 nsa.sa_flags = SA_FULLDUMP;
273 sigaction(SIGABRT, &nsa, NULL);
274 sigaction(SIGSEGV, &nsa, NULL);
276 cmd_SetBeforeProc(MyBeforeProc, (char *) 0);
278 ts = cmd_CreateSyntax("dump",PerformDump,0,"perform a dump");
280 ts = cmd_CreateSyntax("restore",PerformRestore,0,"perform a restore");
282 ts = cmd_CreateSyntax("check",CheckDump,0,"check a dump");
283 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "dump id");
285 ts = cmd_CreateSyntax("abort",AbortDump,0,"abort a dump");
286 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "dump id");
288 ts = cmd_CreateSyntax("wait",WaitForDump,0,"wait for a dump");
289 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "dump id");
291 ts = cmd_CreateSyntax("end",EndDump,0,"end a dump");
292 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "dump id");
294 code = cmd_Dispatch(argc, argv);
295 if (rxInitDone) rx_Finalize();