Beispiel #1
0
int timestamp_get_new(struct sdirs *sdirs,
	char *buf, size_t s, char *bufforfile, size_t bs, struct conf **cconfs)
{
	time_t t=0;
	unsigned long index=0;
	struct bu *bu=NULL;
	struct bu *bu_list=NULL;
	const struct tm *ctm=NULL;

	// Want to prefix the timestamp with an index that increases by
	// one each time. This makes it far more obvious which backup depends
	// on which - even if the system clock moved around. Take that,
	// bacula!

	// This function orders the array with the highest index number last.
	if(bu_get_list(sdirs, &bu_list)) return -1;
	for(bu=bu_list; bu; bu=bu->next) if(!bu->next) index=bu->bno;

	bu_list_free(&bu_list);

	time(&t);
	ctm=localtime(&t);
        // Windows does not like the %T strftime format option - you get
        // complaints under gdb.
	index++;

	write_to_buf(buf, s, index, NULL, ctm);
	write_to_buf(bufforfile, bs, index,
		get_string(cconfs[OPT_TIMESTAMP_FORMAT]), ctm);

	return 0;
}
Beispiel #2
0
int do_delete_server(struct asfd *asfd,
	struct sdirs *sdirs, struct cntr *cntr,
	const char *cname, const char *backup, const char *manual_delete)
{
	int ret=-1;
	int found=0;
	unsigned long bno=0;
	struct bu *bu=NULL;
	struct bu *bu_list=NULL;

	logp("in do_delete\n");

	if(bu_get_list(sdirs, &bu_list)
	  || write_status(CNTR_STATUS_DELETING, NULL, cntr))
		goto end;

	if(backup && *backup) bno=strtoul(backup, NULL, 10);

	for(bu=bu_list; bu; bu=bu->next)
	{
		if(!backup || !*backup) continue;
		if(!found
		  && (!strcmp(bu->timestamp, backup)
			|| bu->bno==bno))
		{
			if(bu->flags & BU_DELETABLE)
			{
				found=1;
				if(asfd->write_str(asfd, CMD_GEN, "ok")
				  || delete_backup(sdirs, cname, bu,
					manual_delete))
						goto end;
			}
			else
			{
				asfd->write_str(asfd, CMD_ERROR,
					"backup not deletable");
				goto end;
			}
			break;
		}
	}

	if(backup && *backup && !found)
	{
		asfd->write_str(asfd, CMD_ERROR, "backup not found");
		goto end;
	}

	ret=0;
end:
	bu_list_free(&bu_list);
	return ret;
}
Beispiel #3
0
int list_server_init(
    struct asfd *a,
    struct sdirs *s,
    struct cntr *c,
    enum protocol p,
    const char *backup_str,
    const char *regex_str,
    const char *browsedir_str)
{
    asfd=a;
    cntr=c;
    protocol=p;
    backup=backup_str;
    browsedir=browsedir_str;
    if(bu_get_list(s, &bu_list))
        goto error;
    if(regex_str
            && *regex_str
            && !(regex=regex_compile(regex_str)))
    {
        char msg[256]="";
        snprintf(msg, sizeof(msg), "unable to compile regex: %s\n",
                 regex_str);
        log_and_send(asfd, msg);
        goto error;
    }
    list_mode=LIST_MODE_BACKUPS;
    if(regex || browsedir)
        list_mode=LIST_MODE_CONTENTS_MANY;
    if(backup && *backup)
    {
        if((bno=strtoul(backup, NULL, 10))>0)
            list_mode=LIST_MODE_CONTENTS_ONE;
        else if(*backup=='c')
            list_mode=LIST_MODE_CONTENTS_ONE;
        else if(*backup=='a')
            list_mode=LIST_MODE_CONTENTS_MANY;
        else
            list_mode=LIST_MODE_CONTENTS_ONE;
    }
    return 0;
error:
    list_server_free();
    return -1;
}
Beispiel #4
0
int delete_backups(struct sdirs *sdirs,
	const char *cname, struct strlist *keep, const char *manual_delete)
{
	int ret=-1;
	struct bu *bu_list=NULL;
	// Deleting a backup might mean that more become available to delete.
	// Keep trying to delete until we cannot delete any more.
	while(1)
	{
		if(bu_get_list(sdirs, &bu_list)) goto end;
		switch(do_delete_backups(sdirs, cname, keep, bu_list,
			manual_delete))
		{
			case 0: ret=0; goto end;
			case -1: ret=-1; goto end;
			default: break;
		}
		bu_list_free(&bu_list);
	}
end:
	bu_list_free(&bu_list);
	return ret;
}
Beispiel #5
0
int do_restore_server(struct asfd *asfd, struct sdirs *sdirs,
	enum action act, int srestore,
	char **dir_for_notify, struct conf **confs)
{
	int ret=0;
	uint8_t found=0;
	struct bu *bu=NULL;
	struct bu *bu_list=NULL;
	unsigned long bno=0;
	regex_t *regex=NULL;
	const char *backup=get_string(confs[OPT_BACKUP]);

	logp("in do_restore\n");

	if(compile_regex(&regex, get_string(confs[OPT_REGEX]))) return -1;

	if(bu_get_list(sdirs, &bu_list))
	{
		if(regex) { regfree(regex); free(regex); }
		return -1;
	}

	if((!backup
	 || !*backup
	 || !(bno=strtoul(backup, NULL, 10)))
		&& bu_list)
	{
		found=1;
		// No backup specified, do the most recent.
		for(bu=bu_list; bu && bu->next; bu=bu->next) { }
		ret=restore_manifest(asfd, bu, regex, srestore,
				act, sdirs, dir_for_notify, confs);
	}

	if(!found) for(bu=bu_list; bu; bu=bu->next)
	{
		if(!strcmp(bu->timestamp, backup)
		  || bu->bno==bno)
		{
			found=1;
			//logp("got: %s\n", bu->path);
			ret|=restore_manifest(asfd, bu, regex, srestore,
				act, sdirs, dir_for_notify, confs);
			break;
		}
	}

	bu_list_free(&bu_list);

	if(!found)
	{
		logp("backup not found\n");
		asfd->write_str(asfd, CMD_ERROR, "backup not found");
		ret=-1;
	}
	if(regex)
	{
		regfree(regex);
		free(regex);
	}
	return ret;
}