From: Eric Bollengier Date: Thu, 3 Mar 2022 10:31:03 +0000 (+0100) Subject: Add new fileindex option to the .bvfs_restore command X-Git-Tag: Beta-15.0.0~634 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=33bec23e60c55bfa1f9c3171782e957f97e0c373;p=thirdparty%2Fbacula.git Add new fileindex option to the .bvfs_restore command --- diff --git a/bacula/src/cats/bvfs.c b/bacula/src/cats/bvfs.c index af1101d5c..d451d613e 100644 --- a/bacula/src/cats/bvfs.c +++ b/bacula/src/cats/bvfs.c @@ -1525,7 +1525,7 @@ bail_out: return ret; } -bool Bvfs::compute_restore_list(char *fileid, char *dirid, char *output_table) +bool Bvfs::compute_restore_list(char *fileid, char *dirid, char *fileindex, char *output_table) { POOL_MEM query; POOL_MEM tmp, tmp2; @@ -1537,11 +1537,13 @@ bool Bvfs::compute_restore_list(char *fileid, char *dirid, char *output_table) bool use_insert_hardlinks_fast = false; /* check args */ - if ((*fileid && !is_a_number_list(fileid)) || - (*dirid && !is_a_number_list(dirid)) || - (!*fileid && !*dirid)|| (!output_table) + if ((fileid && *fileid && !is_a_number_list(fileid)) || + (dirid && *dirid && !is_a_number_list(dirid)) || + (fileindex && *fileindex && !is_a_number_list(fileindex)) || + (!*fileid && !*dirid && (!fileindex || !*fileindex)) || (!output_table) ) { + Dmsg0(dbglevel, "Invalid parameters\n"); return false; } if (!check_temp(output_table)) { @@ -1575,6 +1577,31 @@ bool Bvfs::compute_restore_list(char *fileid, char *dirid, char *output_table) pm_strcat(query, tmp.c_str()); } + if (fileindex && *fileindex) { /* Select files with their fileindex */ + int64_t jobid, fidx; + sellist sel; + sel.set_string(fileindex, true); + + /* check the format */ + foreach_sellist(jobid, &sel) { + fidx = sel.next(); + if (fidx <= 0) { + goto bail_out; + } + if (init) { + query.strcat(" UNION "); + } + Mmsg(tmp,"SELECT Job.JobId, JobTDate, FileIndex, Filename, " + "PathId, FileId " + "FROM File JOIN Job USING (JobId) " + "WHERE JobId = %lld AND FileIndex = %lld AND JobId IN (%s) ", + jobid, fidx, jobids); + + pm_strcat(query, tmp.c_str()); + init=true; + } + } + /* Add a directory content */ while (get_next_id_from_list(&dirid, &id) == 1) { Mmsg(tmp, "SELECT Path FROM Path WHERE PathId=%lld", id); diff --git a/bacula/src/cats/bvfs.h b/bacula/src/cats/bvfs.h index 68c3309e0..35454df8b 100644 --- a/bacula/src/cats/bvfs.h +++ b/bacula/src/cats/bvfs.h @@ -241,7 +241,7 @@ public: void clear_cache(); /* Compute restore list */ - bool compute_restore_list(char *fileid, char *dirid, char *output_table); + bool compute_restore_list(char *fileid, char *dirid, char *fileindex, char *output_table); /* Drop previous restore list */ bool drop_restore_list(char *output_table); diff --git a/bacula/src/dird/ua_dotcmds.c b/bacula/src/dird/ua_dotcmds.c index ccd001a47..e957db462 100644 --- a/bacula/src/dird/ua_dotcmds.c +++ b/bacula/src/dird/ua_dotcmds.c @@ -823,13 +823,13 @@ bail_out: return ret; } -/* .bvfs_restore path=b2XXXXX jobid=1,2 fileid=1,2 dirid=1,2 objectid=1,2 +/* .bvfs_restore path=b2XXXXX jobid=1,2 fileid=1,2 dirid=1,2 fileindex=fidx,jobid,fidx,jobid objectid=1,2 */ static bool dot_bvfs_restore(UAContext *ua, const char *cmd) { DBId_t pathid=0; int limit=2000, offset=0, i; - char *path=NULL, *jobid = NULL, *username=NULL; + char *path=NULL, *jobid = NULL, *username=NULL, *fileindex=NULL; db_list_ctx jobids, fileid, dirid; bool object = false, ret = false; @@ -864,6 +864,7 @@ static bool dot_bvfs_restore(UAContext *ua, const char *cmd) } fileid.add(ua->argv[i]); } + if ((i = find_arg_with_value(ua, "dirid")) >= 0) { if (ua->argv[i][0] != '\0' && !is_a_number_list(ua->argv[i])) { ua->error_msg("Please provide dirid as a list of integers!\n"); @@ -872,6 +873,27 @@ static bool dot_bvfs_restore(UAContext *ua, const char *cmd) dirid.add(ua->argv[i]); } + if ((i = find_arg_with_value(ua, "fileindex")) >= 0) { + if (ua->argv[i][0] != '\0' && !is_a_number_list(ua->argv[i])) { + ua->error_msg("Please provide fileid as a list of integers!\n"); + return true; + } + + int64_t jobid, fidx; + sellist sel; + sel.set_string(ua->argv[i], true); + + /* check the format */ + foreach_sellist(jobid, &sel) { + fidx = sel.next(); + if (fidx <= 0) { + ua->error_msg("Please provide jobid,fileindex as a list of integers!\n"); + return true; + } + } + fileindex = ua->argv[i]; + } + if (object) { i = find_arg_with_value(ua, "objectid"); if (ua->argv[i][0] != '\0' && !is_a_number_list(ua->argv[i])) { @@ -896,7 +918,7 @@ static bool dot_bvfs_restore(UAContext *ua, const char *cmd) if ((i = find_arg(ua, "nodelta")) >= 0) { fs.set_compute_delta(false); } - if (fs.compute_restore_list(fileid.list, dirid.list, path)) { + if (fs.compute_restore_list(fileid.list, dirid.list, fileindex, path)) { ua->send_msg("OK\n"); } else { ua->error_msg("Can't create restore list\n");