*****************************************************************************
* rrd_restore.c creates new rrd from data dumped by rrd_dump.c
*****************************************************************************/
*****************************************************************************
* rrd_restore.c creates new rrd from data dumped by rrd_dump.c
*****************************************************************************/
int eat_tag(char **, char *);
int read_tag(char **, char *, char *, void *);
int xml2rrd(char*, rrd_t*, char);
int eat_tag(char **, char *);
int read_tag(char **, char *, char *, void *);
int xml2rrd(char*, rrd_t*, char);
void parse_patch1028_RRA_params(char **buf, rrd_t *rrd, int rra_index);
void parse_patch1028_CDP_params(char **buf, rrd_t *rrd, int rra_index, int ds_index);
void parse_FAILURES_history(char **buf, rrd_t *rrd, int rra_index, int ds_index);
void parse_patch1028_RRA_params(char **buf, rrd_t *rrd, int rra_index);
void parse_patch1028_CDP_params(char **buf, rrd_t *rrd, int rra_index, int ds_index);
void parse_FAILURES_history(char **buf, rrd_t *rrd, int rra_index, int ds_index);
strcpy(rrd->stat_head->cookie,RRD_COOKIE);
read_tag(&ptr,"version","%4[0-9]",rrd->stat_head->version);
/* added primitive version checking */
strcpy(rrd->stat_head->cookie,RRD_COOKIE);
read_tag(&ptr,"version","%4[0-9]",rrd->stat_head->version);
/* added primitive version checking */
- if (atoi(rrd -> stat_head -> version) != 2)
+ if (atoi(rrd -> stat_head -> version) > atoi(RRD_VERSION) )
+ {
+ rrd_set_error("Incompatible file version, detected version %s is bigger than supported version %s\n",
+ rrd -> stat_head -> version, RRD_VERSION );
+ free(rrd -> stat_head);
+ return -1;
+ }
+ if (atoi(rrd -> stat_head -> version) < 2)
- rrd_set_error("Incompatible file version, detected version %s, required version %s\n",
- rrd -> stat_head -> version, RRD_VERSION);
+ rrd_set_error("Can only restore version >= 2 (Not %s). Dump your rrd using a current rrdtool dump.", rrd -> stat_head -> version );
read_tag(&ptr2,"type",DST_FMT,rrd->ds_def[rrd->stat_head->ds_cnt-1].dst);
/* test for valid type */
read_tag(&ptr2,"type",DST_FMT,rrd->ds_def[rrd->stat_head->ds_cnt-1].dst);
/* test for valid type */
while (eat_tag(&ptr2,"rra") == 1){
rrd->stat_head->rra_cnt++;
while (eat_tag(&ptr2,"rra") == 1){
rrd->stat_head->rra_cnt++;
if((rrd->rra_def = rrd_realloc(rrd->rra_def,rrd->stat_head->rra_cnt*sizeof(rra_def_t)))==NULL){
rrd_set_error("allocating rra_def"); return -1; }
memset(&(rrd->rra_def[rrd->stat_head->rra_cnt-1]), 0, sizeof(rra_def_t));
if((rrd->rra_def = rrd_realloc(rrd->rra_def,rrd->stat_head->rra_cnt*sizeof(rra_def_t)))==NULL){
rrd_set_error("allocating rra_def"); return -1; }
memset(&(rrd->rra_def[rrd->stat_head->rra_cnt-1]), 0, sizeof(rra_def_t));
if((rrd->cdp_prep = rrd_realloc(rrd->cdp_prep,
rrd->stat_head->rra_cnt
*rrd->stat_head->ds_cnt*sizeof(cdp_prep_t)))==NULL){
if((rrd->cdp_prep = rrd_realloc(rrd->cdp_prep,
rrd->stat_head->rra_cnt
*rrd->stat_head->ds_cnt*sizeof(cdp_prep_t)))==NULL){
read_tag(&ptr2,"cf",CF_NAM_FMT,rrd->rra_def[rrd->stat_head->rra_cnt-1].cf_nam);
/* test for valid type */
read_tag(&ptr2,"cf",CF_NAM_FMT,rrd->rra_def[rrd->stat_head->rra_cnt-1].cf_nam);
/* test for valid type */
read_tag(&ptr2,"pdp_per_row","%lu",&(rrd->rra_def[rrd->stat_head->rra_cnt-1].pdp_cnt));
/* support to read RRA parameters */
read_tag(&ptr2,"pdp_per_row","%lu",&(rrd->rra_def[rrd->stat_head->rra_cnt-1].pdp_cnt));
/* support to read RRA parameters */
}
eat_tag(&ptr2, "/params");
eat_tag(&ptr2,"cdp_prep");
}
eat_tag(&ptr2, "/params");
eat_tag(&ptr2,"cdp_prep");
/* last row in the xml file is the most recent; as
* rrd_update increments the current row pointer, set cur_row
* here to the last row. */
/* last row in the xml file is the most recent; as
* rrd_update increments the current row pointer, set cur_row
* here to the last row. */
- int fd = open(file_name,O_RDWR|O_CREAT|O_EXCL,0666);
+#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
+ fdflags = O_RDWR|O_BINARY|O_CREAT;
+#else
+ fdflags = O_WRONLY|O_CREAT;
+#endif
+ if (force_overwrite == 0) {
+ fdflags |= O_EXCL;
+ }
+ fd = open(file_name,fdflags,0666);
-
- fwrite(rrd->live_head, sizeof(live_head_t),1, rrd_file);
+
+ /* maybe the xml hold an old formatted rrd */
+ if (atoi(rrd->stat_head->version) < 3)
+ fwrite(&(rrd->live_head->last_up), sizeof(long),1, rrd_file);
+ else
+ fwrite(rrd->live_head, sizeof(live_head_t),1, rrd_file);
fwrite( rrd->pdp_prep, sizeof(pdp_prep_t),rrd->stat_head->ds_cnt,rrd_file);
fwrite( rrd->pdp_prep, sizeof(pdp_prep_t),rrd->stat_head->ds_cnt,rrd_file);
static struct option long_options[] =
{
{"range-check", required_argument, 0, 'r'},
static struct option long_options[] =
{
{"range-check", required_argument, 0, 'r'},
- opt = getopt_long(argc, argv, "r", long_options, &option_index);
+ opt = getopt_long(argc, argv, "r:f", long_options, &option_index);
/* a backwards compatibility routine that will parse the RRA params section
* generated by the aberrant patch to 1.0.28. */
/* a backwards compatibility routine that will parse the RRA params section
* generated by the aberrant patch to 1.0.28. */
/* 28 = MAX_FAILURES_WINDOW_LEN */
read_tag(buf, "history", "%28[0-1]", history);
/* 28 = MAX_FAILURES_WINDOW_LEN */
read_tag(buf, "history", "%28[0-1]", history);