Exemplo n.º 1
0
Arquivo: quota.c Projeto: Lacoste/burp
static void quota_log_bytes(struct async *as,
	const char *msg, uint64_t byte, uint64_t quota)
{
	as->asfd->write_str(as->asfd, CMD_WARNING, msg);
	logp("Bytes estimated: %"PRIu64"%s\n", byte, bytes_to_human(byte));
	logp("%s: %"PRIu64"%s\n", msg, quota, bytes_to_human(quota));
}
Exemplo n.º 2
0
static void update_screen_live_counter_single(struct cntr_ent *e,
	int *x, int col)
{
	char msg[128]="";
	const char *bytes_human="";
	if(!(e->flags & CNTR_SINGLE_FIELD)) return;
	if(!e->count) return;
	switch(e->cmd)
	{
		case CMD_TIMESTAMP:
		case CMD_TIMESTAMP_END:
			return;
		case CMD_BYTES_ESTIMATED:
		case CMD_BYTES:
		case CMD_BYTES_RECV:
		case CMD_BYTES_SENT:
			bytes_human=bytes_to_human(e->count);
			break;
		default:
			break;
	}
	snprintf(msg, sizeof(msg), "%19s: %12"PRIu64" %s",
		e->label, e->count, bytes_human);
	print_line(msg, (*x)++, col);
}
Exemplo n.º 3
0
static void client_summary(struct cstat *cstat,
	int row, int col, int clientwidth)
{
	char msg[1024]="";
	char fmt[64]="";
	struct bu *cbu=NULL;
	snprintf(fmt, sizeof(fmt), "%%-%d.%ds %%9s %%s%%s",
		clientwidth, clientwidth);

	// Find the current backup.
	cbu=bu_find_current(cstat->bu);

	switch(cstat->run_status)
	{
		case RUN_STATUS_RUNNING:
			if(toggle)
			{
				char f[64]="";
				char b[64]="";
				uint64_t p=0;
				uint64_t t=0;
				struct cntr *cntr=cstat->cntr;
				struct cntr_ent *ent_gtotal=
					cntr->ent[(uint8_t)CMD_GRAND_TOTAL];

				t=ent_gtotal->count
					+ent_gtotal->same
					+ent_gtotal->changed;
				if(ent_gtotal->phase1)
					p=(t*100)/ent_gtotal->phase1;
				snprintf(f, sizeof(f),
					" %"PRIu64"/%"PRIu64" %"PRIu64"%%",
					t, ent_gtotal->phase1, p);
				if(cntr->byte)
					snprintf(b, sizeof(b), "%s",
						bytes_to_human(cntr->byte));
				snprintf(msg, sizeof(msg), fmt,
					cstat->name,
					run_status_to_str(cstat),
					f, b);
				break;
			}
			// Else fall through.
		case RUN_STATUS_IDLE:
		case RUN_STATUS_SERVER_CRASHED:
		case RUN_STATUS_CLIENT_CRASHED:
		default:
			snprintf(msg, sizeof(msg), fmt,
				cstat->name,
				run_status_to_str(cstat),
				" last backup: ",
				get_bu_str(cbu));
			break;
	}

	if(*msg) print_line(msg, row, col);
}
Exemplo n.º 4
0
static void bottom_part(struct cntr *a, struct cntr *b, enum action act)
{
	logc("\n");
	logc("             Warnings:   % 11llu\n",
		b->warning + a->warning);
	logc("\n");
	logc("      Bytes estimated:   % 11llu", a->byte);
	logc("%s\n", bytes_to_human(a->byte));

	if(act==ACTION_ESTIMATE) return;

	logc("      Bytes in backup:   % 11llu", b->byte);
	logc("%s\n", bytes_to_human(b->byte));
	logc("       Bytes received:   % 11llu", b->recvbyte);
	logc("%s\n", bytes_to_human(b->recvbyte));
	logc("           Bytes sent:   % 11llu", b->sentbyte);
	logc("%s\n", bytes_to_human(b->sentbyte));
}
Exemplo n.º 5
0
void show_stat_info(char *fname, struct stat *buf) {
    static char mode[255];
    mode_to_letters(buf->st_mode, mode);
    printf("    mode: %s\n", mode); /* type + mode */
    printf("   links: %d\n", buf->st_nlink); /* # links */
    printf("    user: %s\n", uid_to_name(buf->st_uid)); /* user name */
    printf("   group: %s\n", gid_to_name(buf->st_gid)); /* group name */
    printf("    size: %s\n", bytes_to_human(buf->st_size)); /* file size */
    printf("accessed: %s\n", show_time((int) buf->st_atime)); /* accessed */
    printf("modified: %s\n", show_time((int) buf->st_mtime)); /* modified */
    printf(" changed: %s\n", show_time((int) buf->st_ctime)); /* changed */
}
Exemplo n.º 6
0
Arquivo: cntr.c Projeto: jkniiv/burp
static void bottom_part(struct cntr *c, enum action act)
{
	unsigned long long l;
	struct cntr_ent **e=c->ent;
	logc("\n");
	logc("             Warnings:   % 11llu\n", get_count(e, CMD_WARNING));
	logc("\n");
	logc("      Bytes estimated:   % 11llu", get_count(e, CMD_BYTES_ESTIMATED));
	logc("%s\n", bytes_to_human(get_count(e, CMD_BYTES_ESTIMATED)));

	if(act==ACTION_ESTIMATE) return;

	if(act==ACTION_BACKUP
	  || act==ACTION_BACKUP_TIMED)
	{
		l=get_count(e, CMD_BYTES);
		logc("      Bytes in backup:   % 11llu", l);
		logc("%s\n", bytes_to_human(l));
	}
	if(act==ACTION_RESTORE)
	{
		l=get_count(e, CMD_BYTES);
		logc("      Bytes attempted:   % 11llu", l);
		logc("%s\n", bytes_to_human(l));
	}
	if(act==ACTION_VERIFY)
	{
		l=get_count(e, CMD_BYTES);
		logc("        Bytes checked:   % 11llu", l);
		logc("%s\n", bytes_to_human(l));
	}

	if(act==ACTION_BACKUP
	  || act==ACTION_BACKUP_TIMED)
	{
		l=get_count(e, CMD_BYTES_RECV);
		logc("       Bytes received:   % 11llu", l);
		logc("%s\n", bytes_to_human(l));
	}
	if(act==ACTION_BACKUP 
	  || act==ACTION_BACKUP_TIMED
	  || act==ACTION_RESTORE)
	{
		l=get_count(e, CMD_BYTES_SENT);
		logc("           Bytes sent:   % 11llu", l);
		logc("%s\n", bytes_to_human(l));
	}
}
Exemplo n.º 7
0
static void bottom_part(struct cntr *a, struct cntr *b, enum action act)
{
	logc("\n");
	logc("             Warnings:   % 11llu\n",
		b->warning + a->warning);
	logc("\n");
	logc("      Bytes estimated:   % 11llu", a->byte);
	logc("%s\n", bytes_to_human(a->byte));

	if(act==ACTION_ESTIMATE) return;

	if(act==ACTION_BACKUP
	  || act==ACTION_BACKUP_TIMED)
	{
		logc("      Bytes in backup:   % 11llu", b->byte);
		logc("%s\n", bytes_to_human(b->byte));
	}
	if(act==ACTION_RESTORE)
	{
		logc("      Bytes attempted:   % 11llu", b->byte);
		logc("%s\n", bytes_to_human(b->byte));
	}
	if(act==ACTION_VERIFY)
	{
		logc("        Bytes checked:   % 11llu", b->byte);
		logc("%s\n", bytes_to_human(b->byte));
	}

	if(act==ACTION_BACKUP
	  || act==ACTION_BACKUP_TIMED)
	{
		logc("       Bytes received:   % 11llu", b->recvbyte);
		logc("%s\n", bytes_to_human(b->recvbyte));
	}
	if(act==ACTION_BACKUP 
	  || act==ACTION_BACKUP_TIMED
	  || act==ACTION_RESTORE)
	{
		logc("           Bytes sent:   % 11llu", b->sentbyte);
		logc("%s\n", bytes_to_human(b->sentbyte));
	}
}
Exemplo n.º 8
0
void show_stat_info_oneline(char *fname, struct stat *buf) {
    static char mode[255];
    mode_to_letters(buf->st_mode, mode);
    printf("%s %d %s %s %s\t%s %s\n", mode, buf->st_nlink, uid_to_name(buf->st_uid), gid_to_name(buf->st_gid), bytes_to_human(buf->st_size), show_time((int) buf->st_mtime), fname);
}
Exemplo n.º 9
0
Arquivo: bedup.c Projeto: kaptk2/burp
int run_bedup(int argc, char *argv[])
{
	int i=1;
	int ret=0;
	int option=0;
	int nonburp=0;
	unsigned int maxlinks=DEF_MAX_LINKS;
	char *groups=NULL;
	char ext[16]="";
	int givenconfigfile=0;
	const char *configfile=NULL;

	configfile=get_config_path();
	snprintf(ext, sizeof(ext), ".bedup.%d", getpid());

	while((option=getopt(argc, argv, "c:dg:hlm:nvV?"))!=-1)
	{
		switch(option)
		{
			case 'c':
				configfile=optarg;
				givenconfigfile=1;
				break;
			case 'd':
				deletedups=1;
				break;
			case 'g':
				groups=optarg;
				break;
			case 'l':
				makelinks=1;
				break;
			case 'm':
				maxlinks=atoi(optarg);
				break;
			case 'n':
				nonburp=1;
				break;
			case 'V':
				printf("%s-%s\n", prog, VERSION);
				return 0;
			case 'v':
				verbose=1;
				break;
			case 'h':
			case '?':
				return usage();
		}
	}

	if(nonburp && givenconfigfile)
	{
		logp("-n and -c options are mutually exclusive\n");
		return 1;
	}
	if(nonburp && groups)
	{
		logp("-n and -g options are mutually exclusive\n");
		return 1;
	}
	if(!nonburp && maxlinks!=DEF_MAX_LINKS)
	{
		logp("-m option is specified via the configuration file in burp mode (max_hardlinks=)\n");
		return 1;
	}
	if(deletedups && makelinks)
	{
		logp("-d and -l options are mutually exclusive\n");
		return 1;
	}
	if(deletedups && !nonburp)
	{
		logp("-d option requires -n option\n");
		return 1;
	}

	if(optind>=argc)
	{
		if(nonburp)
		{
			logp("No directories found after options\n");
			return 1;
		}
	}
	else
	{
		if(!nonburp)
		{
			logp("Do not specify extra arguments.\n");
			return 1;
		}
	}

	if(maxlinks<2)
	{
		logp("The argument to -m needs to be greater than 1.\n");
		return 1;
	}

	if(nonburp)
	{
		// Read directories from command line.
		for(i=optind; i<argc; i++)
		{
			// Strip trailing slashes, for tidiness.
			if(argv[i][strlen(argv[i])-1]=='/')
				argv[i][strlen(argv[i])-1]='\0';
			if(process_dir("", argv[i], ext, maxlinks,
				0 /* not burp mode */, 0 /* level */))
			{
				ret=1;
				break;
			}
		}
	}
	else
	{
		struct conf **globalcs=NULL;
		struct strlist *grouplist=NULL;
		struct lock *globallock=NULL;

		if(groups)
		{
			char *tok=NULL;
			if((tok=strtok(groups, ",\n")))
			{
				do
				{
					if(strlist_add(&grouplist, tok, 1))
					{
						log_out_of_memory(__func__);
						return -1;
					}
				} while((tok=strtok(NULL, ",\n")));
			}
			if(!grouplist)
			{
				logp("unable to read list of groups\n");
				return -1;
			}
		}

		// Read directories from config files, and get locks.
		if(!(globalcs=confs_alloc())) return -1;
		if(confs_init(globalcs)) return -1;
		if(conf_load_global_only(configfile, globalcs)) return 1;
		if(get_e_burp_mode(globalcs[OPT_BURP_MODE])!=BURP_MODE_SERVER)
		{
			logp("%s is not a server config file\n", configfile);
			confs_free(&globalcs);
			return 1;
		}
		logp("Dedup clients from %s\n",
			get_string(globalcs[OPT_CLIENTCONFDIR]));
		maxlinks=get_int(globalcs[OPT_MAX_HARDLINKS]);
		if(grouplist)
		{
			struct strlist *g=NULL;
			logp("in dedup groups:\n");
			for(g=grouplist; g; g=g->next)
				logp("%s\n", g->path);
		}
		else
		{
			char *lockpath=NULL;
			// Only get the global lock when doing a global run.
			// If you are doing individual groups, you are likely
			// to want to do many different dedup jobs and a
			// global lock would get in the way.
			if(!(lockpath=prepend(
				get_string(globalcs[OPT_LOCKFILE]),
				".bedup", ""))
			  || !(globallock=lock_alloc_and_init(lockpath)))
				return 1;
			lock_get(globallock);
			if(globallock->status!=GET_LOCK_GOT)
			{
				logp("Could not get lock %s (%d)\n", lockpath,
					globallock->status);
				free_w(&lockpath);
				return 1;
			}
			logp("Got %s\n", lockpath);
		}
		ret=iterate_over_clients(globalcs, grouplist, ext, maxlinks);
		confs_free(&globalcs);

		lock_release(globallock);
		lock_free(&globallock);
		strlists_free(&grouplist);
	}

	if(!nonburp)
	{
		logp("%d client storages scanned\n", ccount);
	}
	logp("%llu duplicate %s found\n",
		count, count==1?"file":"files");
	logp("%llu bytes %s%s\n",
		savedbytes, (makelinks || deletedups)?"saved":"saveable",
			bytes_to_human(savedbytes));
	return ret;
}
Exemplo n.º 10
0
int main(int argc, char *argv[])
{
	int i=1;
	int ret=0;
	int option=0;
	int nonburp=0;
	unsigned int maxlinks=DEF_MAX_LINKS;
	char *groups=NULL;
	char ext[16]="";
	int givenconfigfile=0;
	prog=basename(argv[0]);
	init_log(prog);
	const char *configfile=NULL;

	configfile=get_config_path();
	snprintf(ext, sizeof(ext), ".bedup.%d", getpid());

	while((option=getopt(argc, argv, "c:g:hlmnv?"))!=-1)
	{
		switch(option)
		{
			case 'c':
				configfile=optarg;
				givenconfigfile=1;
				break;
			case 'g':
				groups=optarg;
				break;
			case 'l':
				makelinks=1;
				break;
			case 'm':
				maxlinks=atoi(optarg);
				break;
			case 'n':
				nonburp=1;
				break;
			case 'v':
				printf("%s-%s\n", prog, VERSION);
				return 0;
			case 'h':
			case '?':
				return usage();
		}
	}

	if(nonburp && givenconfigfile)
	{
		logp("-n and -c options are mutually exclusive\n");
		return 1;
	}
	if(nonburp && groups)
	{
		logp("-n and -g options are mutually exclusive\n");
		return 1;
	}
	if(!nonburp && maxlinks!=DEF_MAX_LINKS)
	{
		logp("-m option is specified via the configuration file in burp mode (max_hardlinks=)\n");
		return 1;
	}

	if(optind>=argc)
	{
		if(nonburp)
		{
			logp("No directories found after options\n");
			return 1;
		}
	}
	else
	{
		if(!nonburp)
		{
			logp("Do not specify extra arguments.\n");
			return 1;
		}
	}

	if(maxlinks<2)
	{
		logp("The argument to -m needs to be greater than 1.\n");
		return 1;
	}

	if(nonburp)
	{
		// Read directories from command line.
		for(i=optind; i<argc; i++)
		{
			// Strip trailing slashes, for tidiness.
			if(argv[i][strlen(argv[i])-1]=='/')
				argv[i][strlen(argv[i])-1]='\0';
			if(process_dir("", argv[i], ext, maxlinks,
				0 /* not burp mode */, 0 /* level */))
			{
				ret=1;
				break;
			}
		}
	}
	else
	{
		int gcount=0;
		struct config conf;
		char *globallock=NULL;
		struct strlist **grouplist=NULL;

		if(groups)
		{
			char *tok=NULL;
			if((tok=strtok(groups, ",\n")))
			{
				do
				{
					if(strlist_add(&grouplist, &gcount,
						tok, 1))
					{
						logp("out of memory\n");
						return -1;
					}
				} while((tok=strtok(NULL, ",\n")));
			}
			if(!gcount)
			{
				logp("unable to read list of groups\n");
				return -1;
			}
		}

		// Read directories from config files, and get locks.
		init_config(&conf);
		if(load_config(configfile, &conf, 1)) return 1;
		if(conf.mode!=MODE_SERVER)
		{
			logp("%s is not a server config file\n", configfile);
			free_config(&conf);
			return 1;
		}
		logp("Dedup clients from %s\n", conf.clientconfdir);
		maxlinks=conf.max_hardlinks;
		if(gcount)
		{
			logp("in dedup groups:\n");
			for(i=0; i<gcount; i++)
				logp("%s\n", grouplist[i]->path);
		}
		else
		{
			// Only get the global lock when doing a global run.
			// If you are doing individual groups, you are likely
			// to want to do many different dedup jobs and a
			// global lock would get in the way.
			if(!(globallock=prepend(conf.lockfile, ".bedup", "")))
				return 1;
			if(get_lock(globallock))
			{
				logp("Could not get %s\n", globallock);
				return 1;
			}
			logp("Got %s\n", globallock);
		}
		ret=iterate_over_clients(&conf, grouplist, gcount,
			ext, maxlinks);
		free_config(&conf);

		if(globallock)
		{
			unlink(globallock);
			free(globallock);
		}
	}

	if(!nonburp)
	{
		logp("%d client storages scanned\n", ccount);
	}
	logp("%llu duplicate %s found\n",
		count, count==1?"file":"files");
	logp("%llu bytes %s%s\n",
		savedbytes, makelinks?"saved":"saveable",
			bytes_to_human(savedbytes));
	return ret;
}
Exemplo n.º 11
0
const char *bytes_to_human_str(const char *str)
{
	return bytes_to_human(strtoull(str, NULL, 10));
}