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"
40 struct tc_tapeSet ttapeSet;
41 char tdumpSetName[TC_MAXNAMELEN];
42 tc_dumpArray tdumps; /*defined by rxgen */
43 tc_restoreArray trestores;/*defined by rxgen */
45 struct tc_dumpStat tstatus;
48 struct rx_connection *UV_Bind(aserver, port)
49 afs_int32 aserver, port;
51 register struct rx_connection *tc;
52 struct rx_securityClass *uvclass;
54 uvclass = rxnull_NewClientSecurityObject();
55 tc = rx_NewConnection(aserver, htons(port), TCSERVICE_ID, uvclass, 0);
60 /* return host address in network byte order */
61 afs_int32 GetServer(aname)
63 register struct hostent *th;
66 register afs_int32 code;
68 code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
70 addr = (b1<<24) | (b2<<16) | (b3<<8) | b4;
71 return htonl(addr); /* convert to network order (128 in byte 0) */
73 th = gethostbyname(aname);
75 memcpy(&addr, th->h_addr, sizeof(addr));
80 static PerformDump(as)
81 register struct cmd_syndesc *as;
83 struct rx_connection *aconn;
86 struct tc_dumpDesc *ptr;
88 afs_int32 parentDumpID,dumpLevel;
90 server = GetServer(SERVERNAME);
92 printf("cant get server id \n");
97 strcpy(tdumpSetName,"Test");
99 ttapeSet.maxTapes = 10;
100 fp = fopen("dumpScr","r");
101 fscanf(fp,"%u %u %u\n",&tdumps.tc_dumpArray_len,&ttapeSet.a,&ttapeSet.b);
102 strcpy(ttapeSet.format,"tapeName%u");
103 strcpy(ttapeSet.tapeServer,"diskTapes");
104 tdumps.tc_dumpArray_val = (struct tc_dumpDesc *) (malloc(tdumps.tc_dumpArray_len*sizeof(struct tc_dumpDesc)));
105 ptr = tdumps.tc_dumpArray_val;
106 for(i = 0; i < tdumps.tc_dumpArray_len; i++){
107 fscanf(fp,"%s\n",ptr->name);
108 fscanf(fp,"%s\n",ptr->hostAddr);
109 fscanf(fp,"%u %u %u\n",&ptr->vid,&ptr->partition,&ptr->date);
113 aconn = UV_Bind(server, TCPORT);
114 code = TC_PerformDump(aconn, tdumpSetName, &ttapeSet,&tdumps,parentDumpID,dumpLevel,&tdumpID);
115 free(tdumps.tc_dumpArray_val);
117 printf("call to TC_PerformDump failed %u\n",code);
120 printf("dumpid returned %u\n",tdumpID);
123 static PerformRestore(as)
124 register struct cmd_syndesc *as;
126 struct rx_connection *aconn;
130 struct tc_restoreDesc *ptr;
132 server = GetServer(SERVERNAME);
134 printf("cant get server id \n");
137 aconn = UV_Bind(server, TCPORT);
138 strcpy(tdumpSetName,"");
139 strcpy(tdumpSetName,"Test");
140 fp = fopen("restoreScr","r");
141 fscanf(fp,"%u\n",&trestores.tc_restoreArray_len);
142 trestores.tc_restoreArray_val = (struct tc_restoreDesc *) malloc(trestores.tc_restoreArray_len*sizeof(struct tc_restoreDesc));
143 ptr = trestores.tc_restoreArray_val;
144 for(i = 0; i < trestores.tc_restoreArray_len; i++){
145 fscanf(fp,"%s\n",ptr->oldName);
146 fscanf(fp,"%s\n",ptr->newName);
147 fscanf(fp,"%s\n",ptr->tapeName);
148 fscanf(fp,"%s\n",ptr->hostAddr);
149 fscanf(fp,"%u %u %u %u %d %u\n",&ptr->origVid,&ptr->vid,&ptr->partition,&ptr->flags,&ptr->frag,&ptr->position);
153 code = TC_PerformRestore(aconn, tdumpSetName, &trestores,&tdumpID);
155 printf("call to TC_PerformRestore failed %u\n",code);
158 printf("dumpid returned %u\n",tdumpID);
161 register struct cmd_syndesc *as;
163 struct rx_connection *aconn;
165 server = GetServer(SERVERNAME);
167 printf("cant get server id \n");
170 tdumpID = atol(as->parms[0].items->data);
171 aconn = UV_Bind(server, TCPORT);
172 code = TC_CheckDump(aconn,tdumpID, &tstatus);
174 printf("call to TC_CheckDump failed %u\n",code);
180 register struct cmd_syndesc *as;
182 struct rx_connection *aconn;
184 server = GetServer(SERVERNAME);
186 printf("cant get server id \n");
189 tdumpID = atol(as->parms[0].items->data);
190 aconn = UV_Bind(server, TCPORT);
191 code = TC_AbortDump(aconn,tdumpID);
193 printf("call to TC_AbortDump failed %u\n",code);
198 static WaitForDump(as)
199 register struct cmd_syndesc *as;
201 struct rx_connection *aconn;
203 server = GetServer(SERVERNAME);
205 printf("cant get server id \n");
208 tdumpID = atol(as->parms[0].items->data);
209 aconn = UV_Bind(server, TCPORT);
210 code = TC_WaitForDump(aconn,tdumpID);
212 printf("call to TC_WaitForDump failed %u\n",code);
218 register struct cmd_syndesc *as;
220 struct rx_connection *aconn;
222 server = GetServer(SERVERNAME);
224 printf("cant get server id \n");
227 tdumpID = atol(as->parms[0].items->data);
228 aconn = UV_Bind(server, TCPORT);
229 code = TC_EndDump(aconn,tdumpID);
231 printf("call to TC_EndDump failed %u\n",code);
236 static MyBeforeProc(as,arock)
237 struct cmd_syndesc *as;
243 printf("Could not initialize rx.\n");
247 rx_SetRxDeadTime(50);
251 #include "AFS_component_version_number.c"
256 register afs_int32 code;
258 register struct cmd_syndesc *ts;
262 * The following signal action for AIX is necessary so that in case of a
263 * crash (i.e. core is generated) we can include the user's data section
264 * in the core dump. Unfortunately, by default, only a partial core is
265 * generated which, in many cases, isn't too useful.
267 struct sigaction nsa;
269 sigemptyset(&nsa.sa_mask);
270 nsa.sa_handler = SIG_DFL;
271 nsa.sa_flags = SA_FULLDUMP;
272 sigaction(SIGABRT, &nsa, NULL);
273 sigaction(SIGSEGV, &nsa, NULL);
275 cmd_SetBeforeProc(MyBeforeProc, NULL);
277 ts = cmd_CreateSyntax("dump",PerformDump,0,"perform a dump");
279 ts = cmd_CreateSyntax("restore",PerformRestore,0,"perform a restore");
281 ts = cmd_CreateSyntax("check",CheckDump,0,"check a dump");
282 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "dump id");
284 ts = cmd_CreateSyntax("abort",AbortDump,0,"abort a dump");
285 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "dump id");
287 ts = cmd_CreateSyntax("wait",WaitForDump,0,"wait for a dump");
288 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "dump id");
290 ts = cmd_CreateSyntax("end",EndDump,0,"end a dump");
291 cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "dump id");
293 code = cmd_Dispatch(argc, argv);
294 if (rxInitDone) rx_Finalize();