From: Eric Bollengier Date: Mon, 21 Nov 2022 15:24:20 +0000 (+0100) Subject: Add list restoreobject client= option X-Git-Tag: Beta-15.0.0~265 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9d33ab0c6cc80b2da426461e2ce8c3cc928a2e22;p=thirdparty%2Fbacula.git Add list restoreobject client= option --- diff --git a/bacula/src/cats/cats.h b/bacula/src/cats/cats.h index 98431d8a8..6cbdaeeff 100644 --- a/bacula/src/cats/cats.h +++ b/bacula/src/cats/cats.h @@ -338,6 +338,7 @@ struct ROBJECT_DBR { DBId_t RestoreObjectId; int limit; /* Needed to restrict a search */ + DBId_t clientid; }; diff --git a/bacula/src/cats/sql_list.c b/bacula/src/cats/sql_list.c index 02ffd927a..248fd3345 100644 --- a/bacula/src/cats/sql_list.c +++ b/bacula/src/cats/sql_list.c @@ -378,22 +378,23 @@ void BDB::bdb_list_plugin_objects_ids(JCR *jcr, char* id_list, DB_LIST_HANDLER * */ void BDB::bdb_list_restore_objects(JCR *jcr, ROBJECT_DBR *rr, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type) { - POOL_MEM filter; - char ed1[50]; - char *jobid; + POOL_MEM filter, jfilter; /* The ACL checking is done on the bconsole command */ if (rr->JobIds && is_a_number_list(rr->JobIds)) { - jobid = rr->JobIds; + Mmsg(jfilter, " %s ", rr->JobIds); } else if (rr->JobId) { - jobid = edit_int64(rr->JobId, ed1); + Mmsg(jfilter, " %ld ", rr->JobId); + + } else if (rr->clientid > 0) { + Mmsg(jfilter, "SELECT A.JobId FROM Job AS A JOIN RestoreObject AS B USING (JobId) WHERE A.ClientId = %ld ORDER By A.JobTDate DESC LIMIT 1", rr->clientid); } else { return; } - - if (rr->FileType > 0) { + + if (rr->clientid == 0 && rr->FileType > 0) { Mmsg(filter, "AND ObjectType = %d ", rr->FileType); } @@ -402,14 +403,14 @@ void BDB::bdb_list_restore_objects(JCR *jcr, ROBJECT_DBR *rr, DB_LIST_HANDLER *s Mmsg(cmd, "SELECT JobId, RestoreObjectId, ObjectName, " "PluginName, ObjectType " "FROM RestoreObject JOIN Job USING (JobId) WHERE JobId IN (%s) %s " - "ORDER BY JobTDate ASC, RestoreObjectId", - jobid, filter.c_str()); + "ORDER BY JobTDate ASC, RestoreObjectId ASC", + jfilter.c_str(), filter.c_str()); } else { Mmsg(cmd, "SELECT JobId, RestoreObjectId, ObjectName, " "PluginName, ObjectType, ObjectLength " "FROM RestoreObject JOIN Job USING (JobId) WHERE JobId IN (%s) %s " - "ORDER BY JobTDate ASC, RestoreObjectId", - jobid, filter.c_str()); + "ORDER BY JobTDate ASC, RestoreObjectId ASC", + jfilter.c_str(), filter.c_str()); } if (!QueryDB(jcr, cmd)) { diff --git a/bacula/src/dird/ua_output.c b/bacula/src/dird/ua_output.c index 80b4d960e..867dae058 100644 --- a/bacula/src/dird/ua_output.c +++ b/bacula/src/dird/ua_output.c @@ -701,7 +701,17 @@ static int do_list_cmd(UAContext *ua, const char *cmd, e_list_type llist) for (j=i+1; jargc; j++) { if (strcasecmp(ua->argk[j], NT_("ujobid")) == 0 && ua->argv[j]) { bstrncpy(jr.Job, ua->argv[j], MAX_NAME_LENGTH); - jr.JobId = 0; + jr.JobId = 0; // TODO: jr is not used + + } else if (strcasecmp(ua->argk[j], NT_("client")) == 0) { + if (is_name_valid(ua->argv[j], NULL)) { + CLIENT_DBR cr; + bmemset(&cr, 0, sizeof(cr)); + /* Both Backup & Restore wants to list jobs for this client */ + if(get_client_dbr(ua, &cr, JT_BACKUP_RESTORE)) { + rr.clientid = cr.ClientId; + } + } } else if (strcasecmp(ua->argk[j], NT_("jobid")) == 0 && ua->argv[j]) { @@ -756,8 +766,8 @@ static int do_list_cmd(UAContext *ua, const char *cmd, e_list_type llist) } } - if (!rr.JobId && !rr.JobIds) { - ua->error_msg(_("list pluginrestoreconf requires jobid argument\n")); + if (!rr.JobId && !rr.JobIds && !rr.clientid) { + ua->error_msg(_("list pluginrestoreconf requires jobid argument or Client\n")); return 1; }