6
#include <mystrings/m_ctype.h>
7
#include <mystrings/m_string.h>
8
#include <mysys/my_getopt.h>
9
#include <mysql_version.h>
10
11
#define BUFFER_LEN 1024
11
12
#define ARCHIVE_ROW_HEADER_SIZE 4
17
18
static void usage(void);
18
19
static const char *opt_tmpdir;
19
20
static const char *new_auto_increment;
20
uint64_t new_auto_increment_value;
21
unsigned long long new_auto_increment_value;
21
22
static const char *load_default_groups[]= { "archive_reader", 0 };
22
23
static char **default_argv;
23
24
int opt_check, opt_force, opt_quiet, opt_backup= 0, opt_extract_frm;
41
if (!(ret= azopen(&reader_handle, argv[0], O_RDONLY, AZ_METHOD_BLOCK)))
42
if (!(ret= azopen(&reader_handle, argv[0], O_RDONLY|O_BINARY, AZ_METHOD_BLOCK)))
43
44
printf("Could not open Archive file\n");
61
62
new_auto_increment_value= reader_handle.auto_increment + 1;
64
if (!(ret= azopen(&writer_handle, argv[0], O_CREAT|O_RDWR,
65
if (!(ret= azopen(&writer_handle, argv[0], O_CREAT|O_RDWR|O_BINARY,
67
68
printf("Could not open file for update: %s\n", argv[0]);
78
79
if (reader_handle.version > 2)
80
81
printf("\tMinor version %u\n", reader_handle.minor_version);
81
printf("\tStart position %"PRIu64"\n", (uint64_t)reader_handle.start);
82
printf("\tStart position %lu\n", (unsigned long long)reader_handle.start);
82
83
printf("\tBlock size %u\n", reader_handle.block_size);
83
printf("\tRows %"PRIu64"\n", reader_handle.rows);
84
printf("\tAutoincrement %"PRIu64"\n", reader_handle.auto_increment);
85
printf("\tCheck Point %"PRIu64"\n", reader_handle.check_point);
86
printf("\tForced Flushes %"PRIu64"\n", reader_handle.forced_flushes);
84
printf("\tRows %lu\n", reader_handle.rows);
85
printf("\tAutoincrement %lu\n", reader_handle.auto_increment);
86
printf("\tCheck Point %lu\n", reader_handle.check_point);
87
printf("\tForced Flushes %lu\n", reader_handle.forced_flushes);
87
88
printf("\tLongest Row %u\n", reader_handle.longest_row);
88
89
printf("\tShortest Row %u\n", reader_handle.shortest_row);
89
90
printf("\tState %s\n", ( reader_handle.dirty ? "dirty" : "clean"));
128
129
if (read > reader_handle.longest_row)
130
printf("Table is damaged, row %"PRIu64" is invalid\n", row_count);
131
printf("Table is damaged, row %lu is invalid\n", row_count);
135
printf("Found %"PRIu64" rows\n", row_count);
136
printf("Found %lu rows\n", row_count);
141
142
unsigned int read;
142
uint64_t row_count= 0;
143
unsigned long long row_count= 0;
145
146
azio_stream writer_handle;
147
148
buffer= (char *)malloc(reader_handle.longest_row);
148
149
if (buffer == NULL)
150
printf("Could not allocate memory for row %"PRIu64"\n", row_count);
151
printf("Could not allocate memory for row %lu\n", row_count);
155
if (!(ret= azopen(&writer_handle, argv[1], O_CREAT|O_RDWR,
156
if (!(ret= azopen(&writer_handle, argv[1], O_CREAT|O_RDWR|O_BINARY,
156
157
AZ_METHOD_BLOCK)))
158
159
printf("Could not open file for backup: %s\n", argv[1]);
166
167
ptr= (char *)my_malloc(sizeof(char) * reader_handle.frm_length, MYF(0));
167
168
azread_frm(&reader_handle, ptr);
168
169
azwrite_frm(&writer_handle, ptr, reader_handle.frm_length);
170
my_free(ptr, MYF(0));
172
173
if (reader_handle.comment_length)
175
176
ptr= (char *)my_malloc(sizeof(char) * reader_handle.comment_length, MYF(0));
176
177
azread_comment(&reader_handle, ptr);
177
178
azwrite_comment(&writer_handle, ptr, reader_handle.comment_length);
179
my_free(ptr, MYF(0));
181
182
while ((read= azread_row(&reader_handle, &error)))
210
frm_file= my_open(argv[1], O_CREAT|O_RDWR, MYF(0));
211
frm_file= my_open(argv[1], O_CREAT|O_RDWR|O_BINARY, MYF(0));
211
212
ptr= (char *)my_malloc(sizeof(char) * reader_handle.frm_length, MYF(0));
212
213
azread_frm(&reader_handle, ptr);
213
my_write(frm_file, (unsigned char*) ptr, reader_handle.frm_length, MYF(0));
214
my_write(frm_file, (uchar*) ptr, reader_handle.frm_length, MYF(0));
214
215
my_close(frm_file, MYF(0));
216
my_free(ptr, MYF(0));
273
284
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
274
285
{"check", 'c', "Check table for errors.",
275
286
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
289
"Output debug log. Often this is 'd:t:o,filename'.",
290
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
276
292
{"extract-frm", 'e',
277
293
"Extract the frm file.",
278
294
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
288
304
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
289
305
{"set-auto-increment", 'A',
290
306
"Force auto_increment to start at this or higher value. If no value is given, then sets the next auto_increment value to the highest used value for the auto key + 1.",
291
(char**) &new_auto_increment,
292
(char**) &new_auto_increment,
307
(uchar**) &new_auto_increment,
308
(uchar**) &new_auto_increment,
293
309
0, GET_ULL, OPT_ARG, 0, 0, 0, 0, 0, 0},
295
311
"Only print errors. One can use two -s to make archive_reader very silent.",
296
312
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
298
314
"Path for temporary files.",
299
(char**) &opt_tmpdir,
315
(uchar**) &opt_tmpdir,
300
316
0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
302
318
"Print version and exit.",
320
336
static void print_version(void)
322
printf("%s Ver %s, for %s (%s)\n", my_progname, SHOW_VERSION,
323
SYSTEM_TYPE, MACHINE_TYPE);
338
printf("%s Ver %s Distrib %s, for %s (%s)\n", my_progname, SHOW_VERSION,
339
MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE);
326
342
static void get_options(int *argc, char ***argv)