예제 #1
0
void load_config(struct config *config) {
	char *data = read_full_file(config->config_path);
	if(NULL == data) {
		fatal("Can't read config file \"%s\".", config->config_path);
	}
	
	char *err = load_config_from_string(config, data, 0);
	if(err) {
		log_error("%s", err);
		fatal("Broken config file \"%s\".", config->config_path);
	}
	
	free(data);
}
예제 #2
0
파일: config.c 프로젝트: zhouyuan/destor
void load_config() {
	sds config = sdsempty();
	char buf[DESTOR_CONFIGLINE_MAX + 1];

	FILE *fp;
	if ((fp = fopen("destor.config", "r")) == 0) {
		destor_log(DESTOR_WARNING, "No destor.config file!");
		return;
	}

	while (fgets(buf, DESTOR_CONFIGLINE_MAX + 1, fp) != NULL)
		config = sdscat(config, buf);

	fclose(fp);
	load_config_from_string(config);
	sdsfree(config);
}
예제 #3
0
파일: destor.c 프로젝트: fdl66/chongshan
int main(int argc, char **argv) {

	destor_start();
	int job = DESTOR_BACKUP;
	int revision = -1;

	int opt = 0;
	while ((opt = getopt_long(argc, argv, short_options, long_options, NULL))
			!= -1) {
		switch (opt) {
		case 'r':
			job = DESTOR_RESTORE;
			revision = atoi(optarg);
			break;
		case 's':
			destor_stat();
			break;
		case 't':
			job = DESTOR_MAKE_TRACE;
			break;
		case 'h':
			usage();
			break;
		case 'p': {
			sds param = sdsnew(optarg);
			load_config_from_string(param);
			break;
		}
		default:
			return 0;
		}
	}
	sds path = NULL;
    

	switch (job) {
	case DESTOR_BACKUP:

		if (argc > optind) {
			path = sdsnew(argv[optind]);
		} else {
			fprintf(stderr, "backup job needs a protected path!\n");
			usage();
		}

		do_backup(path);


		/*
		 * The backup concludes.
		 * GC starts
		 * */
		if(destor.backup_retention_time >= 0
				&& jcr.id >= destor.backup_retention_time){
			NOTICE("GC is running!");
			do_delete(jcr.id - destor.backup_retention_time);
		}

		sdsfree(path);

		break;
	case DESTOR_RESTORE:
		if (revision < 0) {
			fprintf(stderr, "A job id is required!\n");
			usage();
		}
		if (argc > optind) {
			path = sdsnew(argv[optind]);
		} else {
			fprintf(stderr, "A target directory is required!\n");
			usage();
		}

		do_restore(revision, path[0] == 0 ? 0 : path);

		sdsfree(path);
		break;
	case DESTOR_MAKE_TRACE: {
		if (argc > optind) {
			path = sdsnew(argv[optind]);
		} else {
			fprintf(stderr, "A target directory is required!\n");
			usage();
		}

		make_trace(path);
		sdsfree(path);
		break;
	}
	default:
		fprintf(stderr, "Invalid job type!\n");
		usage();
	}
	destor_shutdown();

	return 0;
}