int main(int argc, char **argv) { int fn = 0, ch; setbuf(stdout, NULL); while ((ch = getopt(argc, argv, "45hdDUVf:T:")) != -1) { switch (ch) { case 'd': deleted_pages_only = 1; break; case 'D': deleted_records_only = 1; break; case 'U': undeleted_records_only = 1; break; case 'f': fn = open_ibfile(optarg); break; case 'V': debug = 1; break; case '4': process_redundant = 1; break; case '5': process_compact = 1; break; case 'T': set_filter_id(optarg); break; default: case '?': case 'h': usage(); } } if (fn != 0) { process_ibfile(fn); close(fn); } else usage(); if (!process_compact && !process_redundant) { printf("Error: Please, specify what format your datafile in. Use -4 for mysql 4.1 and below and -5 for 5.X+\n"); usage(); } return 0; }
int main(int argc, char **argv) { int fn = 0, ch; int is_dir = 0; struct stat st; char src[256]; int fileSize = 0; int chunk=-1; char *result_file_n=""; char buffer[16*1024]; char *cwd; setvbuf(stdout, buffer, _IOFBF, sizeof(buffer)); f_result = stdout; while ((ch = getopt(argc, argv, "456hdDUVf:T:b:p:s:o:S:")) != -1) { switch (ch) { case 'd': deleted_pages_only = 1; break; case 'D': deleted_records_only = 1; undeleted_records_only = 0; break; case 'U': undeleted_records_only = 1; break; case 'o': strncpy(result_file, optarg, sizeof(result_file)); /*if(NULL == (f_result = fopen(result_file, "w"))){ fprintf(stderr, "Can't open file %s for writing\n", result_file); exit(-1); }*/ break; case 'f': strncpy(src, optarg, sizeof(src)); if(stat(src, &st) == 0){ if(S_ISDIR(st.st_mode)){ is_dir = 1; } } else{ perror("stat"); fprintf(stderr, "Can't stat %s\n", src); exit(-1); } break; case 'V': debug = 1; break; case '4': process_redundant = 1; break; case '5': process_compact = 1; break; case '6': process_56 = 1; break; case 'T': set_filter_id(optarg); break; case 'b': strncpy(blob_dir, optarg, sizeof(blob_dir)); break; case 'p': strncpy(dump_prefix, optarg, sizeof(dump_prefix)); break; case 's': strncpy(schema, optarg, sizeof(schema)); break; case 'S': chunk_size = atoi(optarg); break; default: case '?': case 'h': usage(); } } char buffpath[2048 + 1]; cwd=getcwd( buffpath, 2048 ); if (cwd != NULL){ if(result_file[0] !='\0'){ if(result_file[0] !='/'){ asprintf(&result_file_n,"%s/%s",cwd,result_file); strcpy(result_file,result_file_n); result_file_n=""; // fprintf(stdout, "Current path %s\n", result_file); fflush(stdout); } } } else{ perror("getcwd() error"); exit(-1); } if(chunk_size > 0){ chunk_size = (chunk_size * 1024)*1024; chunk = 0; } if(is_dir){ DIR *src_dir; char src_file[256]; struct dirent *de; src_dir = opendir(src); int file_count = 0; /* while(NULL != (de = readdir(src_dir))){ if(!strncmp(de->d_name, ".", sizeof(de->d_name))) continue; if(!strncmp(de->d_name, "..", sizeof(de->d_name))) continue; snprintf(src_file, sizeof(src_file), "%s/%s", src, de->d_name); if(debug) { fprintf(stderr, "Processing %s\n", src_file); } fprintf(stderr, "Processing %s\n", src_file); if(0 == (fn = open_ibfile(src_file))){ fprintf(stderr, "Can't open %s\n", src_file); perror("open_ibfile"); exit(-1); } process_ibfile(fn); close(fn); } */ /*The pages are NOT read from the readdir function in sorted order * To have them sorted we have to process them first * * Below we first identify the number of files to parse * * then we create an array with all the names and we sort it * * Then we process it. * * Process can be optimize, but at least is not presenting the pages in sparse order in the result file. * * Use debug option to enable the progress view */ /* * Start Patch \/ */ while(NULL != (de = readdir(src_dir))){ if(!strncmp(de->d_name, ".", sizeof(de->d_name))) continue; if(!strncmp(de->d_name, "..", sizeof(de->d_name))) continue; file_count++; } //fprintf(stderr, "File to process %d\n", file_count); char result[file_count][1024]; int indexres = 0; src_dir = opendir(src); while(NULL != (de = readdir(src_dir))){ if(!strncmp(de->d_name, ".", sizeof(de->d_name))) continue; if(!strncmp(de->d_name, "..", sizeof(de->d_name))) continue; snprintf(src_file, sizeof(src_file), "%s/%s", src, de->d_name); strcpy(result[indexres++], src_file) ; // if(debug){ // fprintf(stderr, "Loading %s\n", src_file); // } } closedir(src_dir); int i,j; char t[1024]; for(i=0;i<file_count;i++){ for(j=0;j<file_count;j++) { if(i == 0 && j == 0){ //fprintf(stderr, "First element %d %s\n", j,result[j]); } else{ //fprintf(stderr, "value %d\n", strcmp(result[j-1],result[j])>0); if(strcmp(result[j-1],result[j])>0) { strcpy(t,result[j-1]); strcpy(result[j-1],result[j]); strcpy(result[j],t); } } } } indexres = 0; struct stat st; //if(debug){ //fprintf(stderr, "Processing, \nTotal pages to process %d %s",file_count, ":"); //} if((result_file[0] !='\0') && chunk_size > 0 ){ asprintf(&result_file_n,"%s_chunk_0.csv",result_file); if(NULL == (f_result = fopen(result_file_n, "w"))){ fprintf(stderr, "Can't open file %s for writing\n", result_file); exit(-1); } } else if((result_file[0] !='\0') && chunk_size == 0 ){ asprintf(&result_file_n,"%s.csv",result_file); if(NULL == (f_result = fopen(result_file, "w"))){ fprintf(stderr, "Can't open file %s for writing\n", result_file); exit(-1); } } while(indexres<file_count){ if(debug){fprintf(stderr, "%s", ".");} //fprintf(stderr, "\nOpening file %s \n", result[indexres]); if(0 == (fn = open_ibfile(result[indexres]))){ fprintf(stderr, "Can't open %s\n", result[indexres]); perror("open_ibfile"); exit(-1); } process_ibfile(fn); fflush(f_result); if(chunk == 0){ print_load(result_file_n); chunk=1; } stat(result_file_n,&st); fileSize = st.st_size; //fprintf(stderr,"File dimension of %s = %d",result_file_n,fileSize); if(result_file_n[0] !='\0' && chunk_size > 0 && fileSize > chunk_size) { fclose(f_result); result_file_n=""; asprintf(&result_file_n,"%s_chunk_%d.csv",result_file,chunk++); if(NULL == (f_result = fopen(result_file_n, "w"))){ fprintf(stderr, "Can't open file %s for writing\n", result_file); exit(-1); } print_load(result_file_n); } indexres++; close(fn); } if(result_file[0] =='\0'){ print_load(""); } else if(chunk_size == 0){ print_load(result_file_n); } if(debug){fprintf(stderr, "%s\n", "END Processing\n");} /* * END Patch /\ */ } else{ if(0 == (fn = open_ibfile(src))){ fprintf(stderr, "Can't open %s\n", src); perror("open_ibfile"); exit(-1); } process_ibfile(fn); close(fn); } if (!process_compact && !process_redundant) { printf("Error: Please, specify what format your datafile in. Use -4 for mysql 4.1 and below and -5 for 5.X+\n"); usage(); } return 0; }
int main(int argc, char **argv) { int fn = 0, ch; while ((ch = getopt(argc, argv, "45VhdcCf:T:")) != -1) { switch (ch) { case 'd': deleted_pages_only = 1; break; case 'f': fn = open_ibfile(optarg); break; case 'V': debug = 1; break; case '4': process_redundant = 1; break; case '5': process_compact = 1; break; case 'T': set_filter_id(optarg); break; case 'c': count_pages = 1; ignore_crap = 0; init_page_counters(); break; case 'C': count_pages = 1; ignore_crap = 1; init_page_counters(); break; default: case '?': case 'h': usage(); } } if (!process_compact && !process_redundant) { printf("Error: Please, specify what format your datafile in. Use -4 for mysql 4.1 and below and -5 for 5.X+\n"); usage(); } if (fn != 0) { process_ibfile(fn); close(fn); if (count_pages) { dump_page_counters(); } } else usage(); return 0; }