From 91a8df10ca7e7ae394682af8d132f597f2dcfbcc Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Fri, 1 Oct 2010 17:59:22 +0200 Subject: [PATCH] Add "all" option to .bvfs_get_jobids dot command. This option allows to know which jobs should be included to build a virtual backup view that merges all FileSet together with BVFS. --- bacula/src/cats/sql_cmds.c | 11 +++++++++++ bacula/src/cats/sql_cmds.h | 1 + bacula/src/dird/ua_dotcmds.c | 34 +++++++++++++++++++++++++++++++--- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/bacula/src/cats/sql_cmds.c b/bacula/src/cats/sql_cmds.c index 5340b2dfc4..eca649a19b 100644 --- a/bacula/src/cats/sql_cmds.c +++ b/bacula/src/cats/sql_cmds.c @@ -230,6 +230,17 @@ const char *uar_sel_fileset = "AND Job.ClientId=%s AND Client.ClientId=%s " "ORDER BY FileSet.FileSet"; +/* Select all different FileSet for this client + * This query doesn't guarantee that the Id is the latest + * version of the FileSet. Can be used with other queries that + * use Ids to select the FileSet name. (like in accurate) + */ +const char *uar_sel_filesetid = + "SELECT MAX(FileSetId) " + "FROM FileSet JOIN Job USING (FileSetId) " + "WHERE Job.ClientId=%s " + "GROUP BY FileSet"; + /* Find MediaType used by this Job */ const char *uar_mediatype = "SELECT MediaType FROM JobMedia,Media WHERE JobMedia.JobId=%s " diff --git a/bacula/src/cats/sql_cmds.h b/bacula/src/cats/sql_cmds.h index 6d771b3bd6..148dd0aff0 100644 --- a/bacula/src/cats/sql_cmds.h +++ b/bacula/src/cats/sql_cmds.h @@ -57,6 +57,7 @@ extern const char CATS_IMP_EXP *uar_inc; extern const char CATS_IMP_EXP *uar_list_temp; extern const char CATS_IMP_EXP *uar_sel_all_temp1; extern const char CATS_IMP_EXP *uar_sel_fileset; +extern const char CATS_IMP_EXP *uar_sel_filesetid; extern const char CATS_IMP_EXP *uar_mediatype; extern const char CATS_IMP_EXP *uar_jobid_fileindex; extern const char CATS_IMP_EXP *uar_dif; diff --git a/bacula/src/dird/ua_dotcmds.c b/bacula/src/dird/ua_dotcmds.c index f1724c8d9e..6c7965453e 100644 --- a/bacula/src/dird/ua_dotcmds.c +++ b/bacula/src/dird/ua_dotcmds.c @@ -421,11 +421,19 @@ static bool dot_bvfs_versions(UAContext *ua, const char *cmd) return true; } +/* .bvfs_get_jobids jobid=1 + * -> returns needed jobids to restore + * .bvfs_get_jobids jobid=1 all + * -> returns needed jobids to restore with all filesets a JobId=1 time + */ static bool dot_bvfs_get_jobids(UAContext *ua, const char *cmd) { JOB_DBR jr; - db_list_ctx jobids; + db_list_ctx jobids, tempids; int pos; + char ed1[50]; + POOL_MEM query; + dbid_list ids; /* Store all FileSetIds for this client */ if (!open_client_db(ua)) { return true; @@ -441,10 +449,30 @@ static bool dot_bvfs_get_jobids(UAContext *ua, const char *cmd) ua->cmd, db_strerror(ua->db)); return true; } + + /* If we have the "all" option, we do a search on all defined fileset + * for this client + */ + if (find_arg(ua, "all") > 0) { + edit_int64(jr.ClientId, ed1); + Mmsg(query, uar_sel_filesetid, ed1); + db_get_query_dbids(ua->jcr, ua->db, query, ids); + } else { + ids.num_ids = 1; + ids.DBId[0] = jr.FileSetId; + } + jr.JobLevel = L_INCREMENTAL; /* Take Full+Diff+Incr */ - if (!db_accurate_get_jobids(ua->jcr, ua->db, &jr, &jobids)) { - return true; + + /* Foreach different FileSet, we build a restore jobid list */ + for (int i=0; i < ids.num_ids; i++) { + jr.FileSetId = ids.DBId[i]; + if (!db_accurate_get_jobids(ua->jcr, ua->db, &jr, &tempids)) { + return true; + } + jobids.cat(tempids); } + ua->send_msg("%s\n", jobids.list); return true; } -- 2.39.5