int ctdb_dumpdb_record(struct ctdb_context *ctdb, TDB_DATA key, TDB_DATA data, void *p)
{
int i;
- FILE *f = (FILE *)p;
+ struct ctdb_dump_db_context *c = (struct ctdb_dump_db_context *)p;
+ FILE *f = c->f;
struct ctdb_ltdb_header *h = (struct ctdb_ltdb_header *)data.dptr;
fprintf(f, "key(%u) = \"", (unsigned)key.dsize);
/*
convenience function to list all keys to stdout
*/
-int ctdb_dump_db(struct ctdb_db_context *ctdb_db, FILE *f)
+int ctdb_dump_db(struct ctdb_db_context *ctdb_db,
+ struct ctdb_dump_db_context *ctx)
{
- return ctdb_traverse(ctdb_db, ctdb_dumpdb_record, f);
+ return ctdb_traverse_ext(ctdb_db, ctdb_dumpdb_record,
+ ctx->printemptyrecords, ctx);
}
/*
typedef int (*ctdb_traverse_func)(struct ctdb_context *, TDB_DATA, TDB_DATA, void *);
int ctdb_traverse(struct ctdb_db_context *ctdb_db, ctdb_traverse_func fn, void *private_data);
+struct ctdb_dump_db_context {
+ FILE *f;
+ bool printemptyrecords;
+};
+
int ctdb_dumpdb_record(struct ctdb_context *ctdb, TDB_DATA key, TDB_DATA data, void *p);
-int ctdb_dump_db(struct ctdb_db_context *ctdb_db, FILE *f);
+int ctdb_dump_db(struct ctdb_db_context *ctdb_db,
+ struct ctdb_dump_db_context *ctx);
/*
get the pid of a ctdb daemon
int machinereadable;
int verbose;
int maxruntime;
+ int printemptyrecords;
} options;
#define TIMELIMIT() timeval_current_ofs(options.timelimit, 0)
struct ctdb_db_context *ctdb_db;
int ret;
bool persistent;
+ struct ctdb_dump_db_context c;
if (argc < 1) {
usage();
return -1;
}
+ ZERO_STRUCT(c);
+ c.f = stdout;
+ c.printemptyrecords = (bool)options.printemptyrecords;
+
/* traverse and dump the cluster tdb */
- ret = ctdb_dump_db(ctdb_db, stdout);
+ ret = ctdb_dump_db(ctdb_db, &c);
if (ret == -1) {
DEBUG(DEBUG_ERR, ("Unable to dump database\n"));
DEBUG(DEBUG_ERR, ("Maybe try 'ctdb getdbstatus %s'"
static int cattdb_traverse(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *private_data)
{
struct cattdb_data *d = private_data;
+ struct ctdb_dump_db_context c;
d->count++;
-
- return ctdb_dumpdb_record(d->ctdb, key, data, stdout);
+
+ ZERO_STRUCT(c);
+ c.f = stdout;
+ c.printemptyrecords = (bool)options.printemptyrecords;
+
+ return ctdb_dumpdb_record(d->ctdb, key, data, &c);
}
/*
char tbuf[100];
struct ctdb_rec_data *rec = NULL;
struct ctdb_marshall_buffer *m;
+ struct ctdb_dump_db_context c;
if (argc != 1) {
DEBUG(DEBUG_ERR,("Invalid arguments\n"));
printf("Backup of database name:'%s' dbid:0x%x08x from @ %s\n",
dbhdr.name, m->db_id, tbuf);
+ ZERO_STRUCT(c);
+ c.f = stdout;
+ c.printemptyrecords = (bool)options.printemptyrecords;
+
for (i=0; i < m->count; i++) {
uint32_t reqid = 0;
TDB_DATA key, data;
rec = ctdb_marshall_loop_next(m, rec, &reqid,
NULL, &key, &data);
- ctdb_dumpdb_record(ctdb, key, data, stdout);
+ ctdb_dumpdb_record(ctdb, key, data, &c);
}
printf("Dumped %d records\n", i);
{ "machinereadable", 'Y', POPT_ARG_NONE, &options.machinereadable, 0, "enable machinereadable output", NULL },
{ "verbose", 'v', POPT_ARG_NONE, &options.verbose, 0, "enable verbose output", NULL },
{ "maxruntime", 'T', POPT_ARG_INT, &options.maxruntime, 0, "die if runtime exceeds this limit (in seconds)", "integer" },
+ { "print-emptyrecords", 0, POPT_ARG_NONE, &options.printemptyrecords, 0, "print the empty records when dumping databases (catdb, cattdb, dumpdbbackup)", NULL },
POPT_TABLEEND
};
int opt;