int do_restore_server(const char *basedir, const char *backup, const char *restoreregex, enum action act, const char *client, struct cntr *p1cntr, struct cntr *cntr, struct config *cconf) { int a=0; int i=0; int ret=0; int found=0; struct bu *arr=NULL; unsigned long index=0; char *tmppath1=NULL; char *tmppath2=NULL; regex_t *regex=NULL; bool all=FALSE; logp("in do_restore\n"); if(compile_regex(®ex, restoreregex)) return -1; if(!(tmppath1=prepend_s(basedir, "tmp1", strlen("tmp1"))) || !(tmppath2=prepend_s(basedir, "tmp2", strlen("tmp2")))) { if(tmppath1) free(tmppath1); if(regex) { regfree(regex); free(regex); } return -1; } if(get_current_backups(basedir, &arr, &a, 1)) { if(tmppath1) free(tmppath1); if(tmppath2) free(tmppath2); if(regex) { regfree(regex); free(regex); } return -1; } if(backup && *backup=='a') { all=TRUE; } else if(!(index=strtoul(backup, NULL, 10)) && a>0) { // No backup specified, do the most recent. ret=restore_manifest(arr, a, a-1, tmppath1, tmppath2, regex, act, client, p1cntr, cntr, cconf, all); found=TRUE; } if(!found) for(i=0; i<a; i++) { if(all || !strcmp(arr[i].timestamp, backup) || arr[i].index==index) { found=TRUE; //logp("got: %s\n", arr[i].path); ret|=restore_manifest(arr, a, i, tmppath1, tmppath2, regex, act, client, p1cntr, cntr, cconf, all); if(!all) break; } } // If doing all backups, send restore end. if(!ret && all && found) ret=do_restore_end(act, cntr); free_current_backups(&arr, a); if(!found) { logp("backup not found\n"); async_write_str(CMD_ERROR, "backup not found"); ret=-1; } if(tmppath1) { unlink(tmppath1); free(tmppath1); } if(tmppath2) { unlink(tmppath2); free(tmppath2); } if(regex) { regfree(regex); free(regex); } return ret; }
int do_restore_server(const char *basedir, enum action act, const char *client, int srestore, char **dir_for_notify, struct cntr *p1cntr, struct cntr *cntr, struct config *cconf) { int a=0; int i=0; int ret=0; int found=0; struct bu *arr=NULL; unsigned long index=0; char *tmppath1=NULL; char *tmppath2=NULL; regex_t *regex=NULL; logp("in do_restore\n"); if(compile_regex(®ex, cconf->regex)) return -1; if(!(tmppath1=prepend_s(basedir, "tmp1", strlen("tmp1"))) || !(tmppath2=prepend_s(basedir, "tmp2", strlen("tmp2")))) { if(tmppath1) free(tmppath1); if(regex) { regfree(regex); free(regex); } return -1; } if(get_current_backups(basedir, &arr, &a, 1)) { if(tmppath1) free(tmppath1); if(tmppath2) free(tmppath2); if(regex) { regfree(regex); free(regex); } return -1; } if(!(index=strtoul(cconf->backup, NULL, 10)) && a>0) { // No backup specified, do the most recent. ret=restore_manifest(arr, a, a-1, tmppath1, tmppath2, regex, srestore, act, client, dir_for_notify, p1cntr, cntr, cconf); found=TRUE; } if(!found) for(i=0; i<a; i++) { if(!strcmp(arr[i].timestamp, cconf->backup) || arr[i].index==index) { found=TRUE; //logp("got: %s\n", arr[i].path); ret|=restore_manifest(arr, a, i, tmppath1, tmppath2, regex, srestore, act, client, dir_for_notify, p1cntr, cntr, cconf); break; } } free_current_backups(&arr, a); if(!found) { logp("backup not found\n"); async_write_str(CMD_ERROR, "backup not found"); ret=-1; } if(tmppath1) { unlink(tmppath1); free(tmppath1); } if(tmppath2) { unlink(tmppath2); free(tmppath2); } if(regex) { regfree(regex); free(regex); } return ret; }
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(®ex, 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; }