Пример #1
0
static int json_send_backup(struct asfd *asfd, struct bu *bu)
{
	static char wbuf[B_TEMPLATE_MAX];
	snprintf(wbuf, B_TEMPLATE_MAX, backup_template,
		bu->next?",\n":"",
		bu->bno, bu->deletable,
		(long)timestamp_to_long(bu->timestamp));
	return json_str_to_client(asfd, wbuf);
}
Пример #2
0
static int json_send_client_start(struct asfd *asfd,
	struct cstat *clist, struct cstat *cstat)
{
	struct bu *bu_current=cstat->bu_current;
	static char wbuf[CLI_TEMPLATE_MAX];
	snprintf(wbuf, CLI_TEMPLATE_MAX, client_start,
		clist==cstat?"":",\n",
		cstat->name,
		cstat_status_to_str(cstat),
		bu_current?bu_current->bno:0,
		bu_current?(long)timestamp_to_long(bu_current->timestamp):0);
	return json_str_to_client(asfd, wbuf);
}
Пример #3
0
static int check_interval(
	struct strlist *interval,
	const char *cname,
	const char *ctimestamp,
	time_t time_now)
{
	char *cp;
	long min_time;
	long seconds=0;
	char tstmp[64]="";
	char min_time_buf[64]="";

	if((seconds=get_interval_in_seconds(interval->path, cname))<0)
		return -1;
	if(timestamp_read(ctimestamp, tstmp, sizeof(tstmp)))
	{
		logp("Could not read timestamp %s\n", ctimestamp);
		return 0; // Backup now.
	}

	min_time=timestamp_to_long(tstmp)+seconds;
	strftime(min_time_buf, sizeof(min_time_buf),
		DEFAULT_TIMESTAMP_FORMAT, localtime(&min_time));
	cp=strchr(tstmp, ' ');
	if(cp)
		cp++;
	else
		cp=tstmp;

	logp("Last backup: %s\n", cp);
	logp("Next after : %s (interval %s)\n", min_time_buf, interval->path);

	if(min_time < time_now)
		return 0;
	return 1;
}
Пример #4
0
static int json_send_backup(struct asfd *asfd, struct cstat *cstat,
	struct bu *bu, int print_flags,
	const char *logfile, const char *browse,
	int use_cache)
{
	long long bno=0;
	long long timestamp=0;
	if(!bu) return 0;
	bno=(long long)bu->bno;
	timestamp=(long long)timestamp_to_long(bu->timestamp);

	if(yajl_map_open_w()
	  || yajl_gen_int_pair_w("number", bno)
	  || yajl_gen_int_pair_w("timestamp", timestamp)
	  || yajl_gen_str_w("flags")
	  || yajl_array_open_w()
	  || flag_wrap_str(bu, BU_HARDLINKED, "hardlinked")
	  || flag_wrap_str(bu, BU_DELETABLE, "deletable")
	  || flag_wrap_str(bu, BU_WORKING, "working")
	  || flag_wrap_str(bu, BU_FINISHING, "finishing")
	  || flag_wrap_str(bu, BU_CURRENT, "current")
	  || flag_wrap_str(bu, BU_MANIFEST, "manifest")
	  || yajl_array_close_w())
		return -1;
	if(bu->flags & (BU_WORKING|BU_FINISHING))
	{
		if(do_counters(cstat->cntr)) return -1;
	}
	if(print_flags
	  && (bu->flags & (BU_LOG_BACKUP|BU_LOG_RESTORE|BU_LOG_VERIFY
		|BU_STATS_BACKUP|BU_STATS_RESTORE|BU_STATS_VERIFY)))
	{
		if(yajl_gen_str_w("logs")
		  || yajl_map_open_w()
		  || yajl_gen_str_w("list")
	  	  || yajl_array_open_w()
		  || flag_wrap_str(bu, BU_LOG_BACKUP, "backup")
		  || flag_wrap_str(bu, BU_LOG_RESTORE, "restore")
		  || flag_wrap_str(bu, BU_LOG_VERIFY, "verify")
		  || flag_wrap_str(bu, BU_STATS_BACKUP, "backup_stats")
		  || flag_wrap_str(bu, BU_STATS_RESTORE, "restore_stats")
		  || flag_wrap_str(bu, BU_STATS_VERIFY, "verify_stats")
	  	  || yajl_array_close_w())
			return -1;
		if(logfile)
		{
			if(flag_wrap_str_zp(bu,
				BU_LOG_BACKUP, "backup", logfile)
			  || flag_wrap_str_zp(bu,
				BU_LOG_RESTORE, "restore", logfile)
			  || flag_wrap_str_zp(bu,
				BU_LOG_VERIFY, "verify", logfile)
			  || flag_wrap_str_zp(bu,
				BU_STATS_BACKUP, "backup_stats", logfile)
			  || flag_wrap_str_zp(bu,
				BU_STATS_RESTORE, "restore_stats", logfile)
			  || flag_wrap_str_zp(bu,
				BU_STATS_VERIFY, "verify_stats", logfile))
					return -1;
		}
		if(yajl_map_close_w())
			return -1;
		if(browse)
		{
			if(yajl_gen_str_w("browse")) return -1;
			if(yajl_map_open_w()) return -1;
			if(yajl_gen_str_pair_w("directory", browse)) return -1;
			if(yajl_gen_str_w("entries")) return -1;
			if(yajl_array_open_w()) return -1;
			if(browse_manifest(asfd, cstat, bu, browse, use_cache))
				return -1;
			if(yajl_array_close_w()) return -1;
			if(yajl_map_close_w()) return -1;

		}
	}
	if(yajl_gen_map_close(yajl)!=yajl_gen_status_ok)
		return -1;

	return 0;
}