From: oetiker Date: Fri, 16 May 2008 12:18:05 +0000 (+0000) Subject: added no-header option to rrd_dump X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=161ecf9c20dbf285f7746aad42327edb8bfeeccc;p=rrdtool.git added no-header option to rrd_dump git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@1357 a5681a0c-68f1-0310-ab6d-d61299d08faa --- diff --git a/NEWS b/NEWS index 26c92a1..c482d22 100644 --- a/NEWS +++ b/NEWS @@ -2,10 +2,17 @@ RRDTOOL NEWS ============ Major Changes between 1.2.x and 1.3.x -see http://oss.oetiker.ch/rrdtool-trac/wiki/RRDtool13 -for up to date information +RRdtool dump / restore Incompatibilities +---------------------------------------- +rrdtool dump 1.3 does emit completely legal xml. Basically this means that +it contains an xml header and a DOCTYPE definition. Unfortunately this +causes older versions of rrdtool restore to be unhappy. -File access methods (Bernhard Fischer) +To restore a new dump with ann old rrdtool restore version, either remove +the xml header and the doctype by hand (both on the first line of the dump) +or use rrdtool dump --no-header. + +NEW File access methods (Bernhard Fischer) ------------------- * introduced file-accessor functions rrd_read/rrd_seek/rrd_write * implemented full mmap-based file access with madvise hints for improved @@ -13,7 +20,7 @@ File access methods (Bernhard Fischer) disk * implemented optional full file-descriptor access instead of FILE* access -Graphing (Tobi Oetiker) +NEW Graphing (Tobi Oetiker) -------- * libart has been replaced by cairo/pango * pango markup is supported @@ -32,7 +39,7 @@ Graphing (Tobi Oetiker) * new interface graphv which returns inforamation useing the rrd_info interface (Tobi Oetiker and Mark Plaksin) -Forecasting (Evan Miller) +NEW Forecasting (Evan Miller) ----------- * the new MHWPREDICT consolidation function uses a variation of the Holt-Winters method. It is a drop-in replacement for HWPREDICT, and is better suited for @@ -42,7 +49,8 @@ Rewrites -------- * rrd_restore now uses libxml for parsing which makes things much more tolerant towards xml variations. The old code could mostly just parse the - xml as it was output by rrd_dump (by Florian octo Forster) + xml as it was output by rrdtool dump. See also: 'incompatibilities' at the + top of this document. (by Florian octo Forster) * rrd_update rewritten to make it more modular. Fixed two longstanding HW bugs in the process (Evan Miller) diff --git a/src/rrd_dump.c b/src/rrd_dump.c index 7ad85b2..707789c 100644 --- a/src/rrd_dump.c +++ b/src/rrd_dump.c @@ -53,24 +53,59 @@ int rrd_dump( char **argv) { int rc; + int opt_noheader = 0; + /* init rrd clean */ - if (argc < 2) { - rrd_set_error("Not enough arguments"); - return -1; + optind = 0; + opterr = 0; /* initialize getopt */ + + while (42) { + int opt; + int option_index = 0; + static struct option long_options[] = { + {"no-header", no_argument, 0, 'n'}, + {0, 0, 0, 0} + }; + + opt = getopt_long(argc, argv, "n", long_options, &option_index); + + if (opt == EOF) + break; + + switch (opt) { + case 'n': + opt_range_check = 1; + break; + + default: + rrd_set_error("usage rrdtool %s [--no-header|-n] " + "file.rrd [file.xml]", argv[0]); + return (-1); + break; + } + } /* while (42) */ + + if ((argc - optind) < 2) { + rrd_set_error("usage rrdtool %s [--no-header|-n] " + "file.rrd [file.xml]", argv[0]); + return (-1); } if (argc == 3) { - rc = rrd_dump_r(argv[1], argv[2]); + rc = rrd_dump_opt_r(argv[1], argv[2],opt_noheader); } else { - rc = rrd_dump_r(argv[1], NULL); + rc = rrd_dump_opt_r(argv[1], NULL,opt_noheader); } return rc; } -int rrd_dump_r( + +int rrd_dump_opt_r( const char *filename, - char *outname) + char *outname, + int opt_noheader +) { unsigned int i, ii, ix, iii = 0; time_t now; @@ -98,10 +133,12 @@ int rrd_dump_r( out_file = stdout; } - fputs("", out_file); - fputs - ("", + if (opt_noheader){ + fputs("\n", out_file); + fputs + ("\n", out_file); + } fputs("", out_file); fputs("", out_file); if (atoi(rrd.stat_head->version) <= 3) { @@ -442,3 +479,11 @@ int rrd_dump_r( } return rrd_close(rrd_file); } + +/* backward compatibility with 1.2.x */ +int rrd_dump_r( + const char *filename, + char *outname) +{ + rrd_dump_opt_r(filename,outname,0); +}