00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "jsoc_main.h"
00027 #include "drms.h"
00028 #include "drms_names.h"
00029 #include <unistd.h>
00030 #include <strings.h>
00031
00032
00033 #define NOTSPECIFIED "***NOTSPECIFIED***"
00034
00035 ModuleArgs_t module_args[] = {
00036 {ARG_STRING, "pname", "", "prog: name to store the dir into"},
00037 {ARG_STRING, "lname", "", "level: name to store the dir into"},
00038 {ARG_INT, "lnum", "0", ""},
00039 {ARG_STRING, "sname", "", "series: name to store the dir into"},
00040 {ARG_INT, "snum", "-1", ""},
00041 {ARG_STRING, "dsdsseries", "", "orig name of dsds series prog: etc."},
00042 {ARG_STRING, "dirname", "", "Dir to store into SUMS"},
00043 {ARG_STRING, "note", "N/A", "comment field"},
00044 {ARG_STRING, "namespace", "dsds", "namespace of output ds"},
00045 {ARG_FLAG, "v", "0", "verbose flag"},
00046 {ARG_FLAG, "j", "0", "only print the jsd"},
00047 {ARG_END}
00048 };
00049
00050 char *outputseries = "su_production.dsds_migrate";
00051
00052
00053 char *module_name = "store_dsds_migrate";
00054
00055
00056 int verbose = 0;
00057 int jsdflg = 0;
00058 char *pname, *lname, *sname, *namespace;
00059 char *dsdsseries;
00060
00061 static char * make_series_jsd(char *series);
00062
00063
00064 int nice_intro () {
00065 verbose = cmdparams_get_int (&cmdparams, "v", NULL);
00066 if (verbose) cmdparams_printall (&cmdparams);
00067 return(0);
00068 }
00069
00070
00071 int DoIt (void) {
00072 int status = 0;
00073 int lnum, snum;
00074
00075 char *in, *note, *dirname, *cptr;
00076 char path[DRMS_MAXPATHLEN];
00077 char drmsseries[256];
00078 char cmd[DRMS_MAXPATHLEN+1024];
00079 DRMS_Record_t *rec, *template;
00080
00081 if (nice_intro())
00082 return(0);
00083
00084 jsdflg = cmdparams_get_int (&cmdparams, "j", NULL);
00085 pname = cmdparams_get_str(&cmdparams, "pname", NULL);
00086 lname = cmdparams_get_str(&cmdparams, "lname", NULL);
00087 sname = cmdparams_get_str(&cmdparams, "sname", NULL);
00088 note = cmdparams_get_str(&cmdparams, "note", NULL);
00089 lnum = cmdparams_get_int (&cmdparams, "lnum", NULL);
00090 snum = cmdparams_get_int (&cmdparams, "snum", NULL);
00091 dsdsseries = cmdparams_get_str(&cmdparams, "dsdsseries", NULL);
00092 namespace = cmdparams_get_str(&cmdparams, "namespace", NULL);
00093 if(!dsdsseries) {
00094 printf("Must give a dsdsseries= %s\n");
00095 return(1);
00096 }
00097 in = cmdparams_get_str(&cmdparams, "dirname", NULL);
00098
00099 if (access(in, R_OK) != 0)
00100 {
00101 printf("The requested dir can not be accessed. %s\n", in);
00102 return(1);
00103 }
00104 dirname = in;
00105
00106
00107 cptr = (char *)index(lname, '.');
00108 if(cptr) {
00109 *cptr = '_';
00110 }
00111 sprintf(drmsseries, "%s.%s__%s__%s", namespace, pname, lname, sname);
00112 if(jsdflg) {
00113 printf("%s", make_series_jsd(drmsseries));
00114 return(1);
00115 }
00116 template = drms_template_record(drms_env, drmsseries, &status);
00117 if (template==NULL && status == DRMS_ERROR_UNKNOWNSERIES)
00118 {
00119 int create_series(char *series);
00120 printf("Going to make series: %s\n", drmsseries);
00121 if (create_series(drmsseries))
00122 {
00123 printf("Series '%s' does not exist. Create_series failed. Give up.\n", drmsseries);
00124 return(1);
00125 }
00126 }
00127 else
00128 if(status)
00129 {
00130 fprintf(stderr, "DRMS problem looking up drmsseries.\n");
00131 return(status);
00132 }
00133
00134
00135 rec = drms_create_record(drms_env, drmsseries, DRMS_PERMANENT, &status);
00136 if (!rec || status)
00137 {
00138 printf("drms_create_record failed, series=%s, status=%d. Aborting.\n", drmsseries,status);
00139 return(status);
00140 }
00141 if ((status = drms_setkey_string(rec, "dirname", dirname)))
00142 {
00143 printf("ERROR: drms_setkey_string failed for 'dirname'\n");
00144 return(1);
00145 }
00146 if ((status = drms_setkey_int(rec, "lnum", lnum)))
00147 {
00148 printf("ERROR: drms_setkey_int failed for 'lnum'\n");
00149 return(1);
00150 }
00151 if ((status = drms_setkey_int(rec, "snum", snum)))
00152 {
00153 printf("ERROR: drms_setkey_int failed for 'snum'\n");
00154 return(1);
00155 }
00156 if ((status = drms_setkey_string(rec, "note", note)))
00157 {
00158 printf("WARNING: drms_setkey_string failed for 'note'\n");
00159 printf("Your note was not saved: %s\n",note);
00160 }
00161
00162 drms_record_directory(rec, path, 1);
00163 if (! *path)
00164 {
00165 fprintf(stderr,"no path found\n");
00166 return(1);
00167 }
00168 sprintf(cmd, "cd %s; cp -rp . %s", in, path);
00169 status = system(cmd);
00170 if (status)
00171 {
00172 printf("Copy failed: %s\n", cmd);
00173 return(status);
00174 }
00175 else
00176 printf("Command success: %s\n", cmd);
00177 if ((status = drms_close_record(rec, DRMS_INSERT_RECORD)))
00178 printf("drms_close_record failed!\n");
00179
00180 return(status);
00181 }
00182
00183 char * make_series_jsd(char *series)
00184 {
00185 char *user = getenv("USER");
00186 char jsd[2048];
00187 if(!strcmp(namespace, "dsds_bak")) {
00188 sprintf(jsd,
00189 "Seriesname: %s\n"
00190 "Author: %s\n"
00191 "Owners: %s\n"
00192 "Unitsize: 1\n"
00193 "Archive: 1\n"
00194 "Retention: 1\n"
00195 "Tapegroup: 200\n"
00196 "PrimeKeys: snum\n"
00197 "DBIndex: snum,lnum\n"
00198 "Description: \"%s\"\n"
00199 "Keyword: dirname, string, variable, record, \" \", %%s, none, \"Original dirname\"\n"
00200 "Keyword: note, string, variable, record, \" \", %%s, none, \" \"\n"
00201 "Keyword: lnum, int, variable, record, \"0\", %%d, none, \"level: number\"\n"
00202 "Keyword: snum, int, variable, record, \"-1\", %%d, none, \"series: number\"\n"
00203 "Data: dir, constant, int, 0, none, generic, \" \"\n",
00204 series, user, user, dsdsseries);
00205 }
00206 else {
00207 sprintf(jsd,
00208 "Seriesname: %s\n"
00209 "Author: %s\n"
00210 "Owners: %s\n"
00211 "Unitsize: 1\n"
00212 "Archive: 1\n"
00213 "Retention: 270\n"
00214 "Tapegroup: 9\n"
00215 "PrimeKeys: snum\n"
00216 "DBIndex: snum,lnum\n"
00217 "Description: \"%s\"\n"
00218 "Keyword: dirname, string, variable, record, \" \", %%s, none, \"Original dirname\"\n"
00219 "Keyword: note, string, variable, record, \" \", %%s, none, \" \"\n"
00220 "Keyword: lnum, int, variable, record, \"0\", %%d, none, \"level: number\"\n"
00221 "Keyword: snum, int, variable, record, \"-1\", %%d, none, \"series: number\"\n"
00222 "Data: dir, constant, int, 0, none, generic, \" \"\n",
00223 series, user, user, dsdsseries);
00224 }
00225 return (strdup(jsd));
00226 }
00227
00228
00229 int create_series(char *series)
00230 {
00231 char *jsd;
00232 int perm = cmdparams_get_int(&cmdparams, "perm", NULL);
00233 DRMS_Record_t *template;
00234 jsd = make_series_jsd(series);
00235 template = drms_parse_description(drms_env, jsd);
00236 if (template==NULL)
00237 {
00238 fprintf(stderr, "Failed to parse series description. JSD was:\n%s\n",jsd);
00239 return(1);
00240 }
00241 if (drms_create_series(template, perm))
00242 {
00243 fprintf(stderr, "Failed to create series. JSD was:\n%s\n", jsd);
00244 return(1);
00245 }
00246 if (verbose)
00247 printf("Create_series successful, JSD was:\n%s\n", jsd);
00248 drms_free_record_struct(template);
00249 free(template);
00250 free(jsd);
00251 return(0);
00252 }
00253