2007-11-29 14:18:54 +00:00
|
|
|
/* -*- mode: C; c-basic-offset: 4 -*- */
|
|
|
|
#ident "Copyright (c) 2007 Tokutek Inc. All rights reserved."
|
|
|
|
|
2007-11-23 18:27:50 +00:00
|
|
|
/* Recover an env. The logs are in argv[1]. The new database is created in the cwd. */
|
|
|
|
|
|
|
|
// Test:
|
|
|
|
// cd ../src/tests/tmpdir
|
|
|
|
// ../../../newbrt/recover ../dir.test_log2.c.tdb
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2007-11-23 20:36:03 +00:00
|
|
|
#include <fcntl.h>
|
2007-11-23 18:27:50 +00:00
|
|
|
|
|
|
|
#include "log_header.h"
|
|
|
|
#include "log-internal.h"
|
2007-11-23 20:36:03 +00:00
|
|
|
#include "cachetable.h"
|
|
|
|
#include "key.h"
|
|
|
|
|
2007-11-23 18:27:50 +00:00
|
|
|
int main (int argc, char *argv[]) {
|
|
|
|
const char *dir;
|
|
|
|
int r;
|
2007-12-26 16:52:55 +00:00
|
|
|
int entrycount=0;
|
2007-11-23 18:27:50 +00:00
|
|
|
assert(argc==2);
|
|
|
|
dir = argv[1];
|
|
|
|
int n_logfiles;
|
|
|
|
char **logfiles;
|
2007-11-29 18:14:40 +00:00
|
|
|
r = toku_logger_find_logfiles(dir, &n_logfiles, &logfiles);
|
2007-11-23 18:27:50 +00:00
|
|
|
if (r!=0) exit(1);
|
|
|
|
int i;
|
2008-01-11 03:09:14 +00:00
|
|
|
toku_recover_init();
|
2007-11-23 18:27:50 +00:00
|
|
|
for (i=0; i<n_logfiles; i++) {
|
2007-12-22 20:56:20 +00:00
|
|
|
//fprintf(stderr, "Opening %s\n", logfiles[i]);
|
2007-11-23 18:27:50 +00:00
|
|
|
FILE *f = fopen(logfiles[i], "r");
|
|
|
|
struct log_entry le;
|
|
|
|
u_int32_t version;
|
2007-11-28 19:09:24 +00:00
|
|
|
r=toku_read_and_print_logmagic(f, &version);
|
2007-11-23 18:27:50 +00:00
|
|
|
assert(r==0 && version==0);
|
2007-11-29 18:14:40 +00:00
|
|
|
while ((r = toku_log_fread(f, &le))==0) {
|
2007-12-05 20:28:33 +00:00
|
|
|
//printf("%lld: Got cmd %c\n", le.u.commit.lsn.lsn, le.cmd);
|
2008-01-10 13:41:58 +00:00
|
|
|
logtype_dispatch(&le, toku_recover_);
|
2007-12-29 19:27:01 +00:00
|
|
|
entrycount++;
|
2007-11-23 18:27:50 +00:00
|
|
|
}
|
|
|
|
if (r!=EOF) {
|
|
|
|
if (r==DB_BADFORMAT) {
|
|
|
|
fprintf(stderr, "Bad log format\n");
|
|
|
|
exit(1);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Huh? %s\n", strerror(r));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
}
|
2008-01-11 03:09:14 +00:00
|
|
|
toku_recover_cleanup();
|
2007-11-23 18:27:50 +00:00
|
|
|
for (i=0; i<n_logfiles; i++) {
|
|
|
|
toku_free(logfiles[i]);
|
|
|
|
}
|
|
|
|
toku_free(logfiles);
|
|
|
|
return 0;
|
|
|
|
}
|