From: Eric Bollengier Date: Mon, 3 Aug 2009 08:34:01 +0000 (+0200) Subject: add list basefiles command X-Git-Tag: Release-5.0.0~342 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=15430480f9c0ac23a58ae77353a9cb700c0442db;p=bacula%2Fbacula add list basefiles command make list files compatible with basefiles --- diff --git a/bacula/src/cats/protos.h b/bacula/src/cats/protos.h index 4af787d8b0..1349aa4e56 100644 --- a/bacula/src/cats/protos.h +++ b/bacula/src/cats/protos.h @@ -126,6 +126,9 @@ void db_list_joblog_records(JCR *jcr, B_DB *mdb, JobId_t JobId, DB_LIST_HANDLER int db_list_sql_query(JCR *jcr, B_DB *mdb, const char *query, DB_LIST_HANDLER *sendit, void *ctx, int verbose, e_list_type type); void db_list_client_records(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type); void db_list_copies_records(JCR *jcr, B_DB *mdb, uint32_t limit, char *jobids, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type); +void +db_list_base_files_for_job(JCR *jcr, B_DB *mdb, JobId_t jobid, DB_LIST_HANDLER *sendit, void *ctx); + /* sql_update.c */ bool db_update_job_start_record(JCR *jcr, B_DB *db, JOB_DBR *jr); diff --git a/bacula/src/cats/sql_get.c b/bacula/src/cats/sql_get.c index d216d5dd33..3dc65d2838 100644 --- a/bacula/src/cats/sql_get.c +++ b/bacula/src/cats/sql_get.c @@ -1066,13 +1066,12 @@ bool db_get_file_list(JCR *jcr, B_DB *mdb, char *jobids, #define new_db_get_file_list #ifdef new_db_get_file_list - /* This is broken, at least if called from ua_restore.c */ Mmsg(buf, "SELECT Path.Path, Filename.Name, File.FileIndex, File.JobId, File.LStat " "FROM ( " "SELECT max(FileId) as FileId, PathId, FilenameId " "FROM (SELECT FileId, PathId, FilenameId FROM File WHERE JobId IN (%s) " - "UNION " + "UNION ALL " /* we already sort after */ "SELECT File.FileId, PathId, FilenameId " "FROM BaseFiles JOIN File USING (FileId) " "WHERE BaseFiles.JobId IN (%s) " diff --git a/bacula/src/cats/sql_list.c b/bacula/src/cats/sql_list.c index fb228ccdd1..c2b22b82f0 100644 --- a/bacula/src/cats/sql_list.c +++ b/bacula/src/cats/sql_list.c @@ -434,15 +434,67 @@ db_list_files_for_job(JCR *jcr, B_DB *mdb, JobId_t jobid, DB_LIST_HANDLER *sendi * Stupid MySQL is NON-STANDARD ! */ if (db_type == SQL_TYPE_MYSQL) { - Mmsg(mdb->cmd, "SELECT CONCAT(Path.Path,Filename.Name) AS Filename FROM File," - "Filename,Path WHERE File.JobId=%s AND Filename.FilenameId=File.FilenameId " - "AND Path.PathId=File.PathId", - edit_int64(jobid, ed1)); + Mmsg(mdb->cmd, "SELECT CONCAT(Path.Path,Filename.Name) AS Filename " + "FROM (SELECT PathId, FilenameId FROM File WHERE JobId=%s " + "UNION ALL " + "SELECT PathId, FilenameId " + "FROM BaseFiles JOIN File " + "ON (BaseFiles.FileId = File.FileId) " + "WHERE BaseFiles.JobId = %s" + ") AS F, Filename,Path " + "WHERE Filename.FilenameId=F.FilenameId " + "AND Path.PathId=F.PathId", + edit_int64(jobid, ed1), ed1); } else { - Mmsg(mdb->cmd, "SELECT Path.Path||Filename.Name AS Filename FROM File," - "Filename,Path WHERE File.JobId=%s AND Filename.FilenameId=File.FilenameId " - "AND Path.PathId=File.PathId", + Mmsg(mdb->cmd, "SELECT Path.Path||Filename.Name AS Filename " + "FROM (SELECT PathId, FilenameId FROM File WHERE JobId=%s " + "UNION ALL " + "SELECT PathId, FilenameId " + "FROM BaseFiles JOIN File " + "ON (BaseFiles.FileId = File.FileId) " + "WHERE BaseFiles.JobId = %s" + ") AS F, Filename,Path " + "WHERE Filename.FilenameId=F.FilenameId " + "AND Path.PathId=F.PathId", + edit_int64(jobid, ed1), ed1); + } + + if (!QUERY_DB(jcr, mdb, mdb->cmd)) { + db_unlock(mdb); + return; + } + + list_result(jcr, mdb, sendit, ctx, HORZ_LIST); + + sql_free_result(mdb); + db_unlock(mdb); +} + +void +db_list_base_files_for_job(JCR *jcr, B_DB *mdb, JobId_t jobid, DB_LIST_HANDLER *sendit, void *ctx) +{ + char ed1[50]; + db_lock(mdb); + + /* + * Stupid MySQL is NON-STANDARD ! + */ + if (db_type == SQL_TYPE_MYSQL) { + Mmsg(mdb->cmd, "SELECT CONCAT(Path.Path,Filename.Name) AS Filename " + "FROM BaseFiles, File, Filename, Path " + "WHERE BaseFiles.JobId=%s AND BaseFiles.BaseJobId = File.JobId " + "AND BaseFiles.FileId = File.FileId " + "AND Filename.FilenameId=File.FilenameId " + "AND Path.PathId=File.PathId", edit_int64(jobid, ed1)); + } else { + Mmsg(mdb->cmd, "SELECT Path.Path||Filename.Name AS Filename " + "FROM BaseFiles, File, Filename, Path " + "WHERE BaseFiles.JobId=%s AND BaseFiles.BaseJobId = File.JobId " + "AND BaseFiles.FileId = File.FileId " + "AND Filename.FilenameId=File.FilenameId " + "AND Path.PathId=File.PathId", + edit_int64(jobid, ed1)); } if (!QUERY_DB(jcr, mdb, mdb->cmd)) { diff --git a/bacula/src/dird/dird.c b/bacula/src/dird/dird.c index 441a0eb298..8dc5ee951c 100644 --- a/bacula/src/dird/dird.c +++ b/bacula/src/dird/dird.c @@ -1081,6 +1081,7 @@ static bool check_catalog(cat_op mode) if (mode == UPDATE_AND_FIX) { db_sql_query(db, cleanup_created_job, NULL, NULL); db_sql_query(db, cleanup_running_job, NULL, NULL); + db_sql_query(db, "CREATE INDEX basefiles_jobid_idx ON BaseFiles ( JobId )" , NULL, NULL); } db_close_database(NULL, db); diff --git a/bacula/src/dird/ua_output.c b/bacula/src/dird/ua_output.c index c93ad9d2d4..7bd629a7af 100644 --- a/bacula/src/dird/ua_output.c +++ b/bacula/src/dird/ua_output.c @@ -326,6 +326,25 @@ static int do_list_cmd(UAContext *ua, const char *cmd, e_list_type llist) jr.JobId = 0; db_list_job_records(ua->jcr, ua->db, &jr, prtit, ua, llist); + /* List Base files */ + } else if (strcasecmp(ua->argk[i], NT_("basefiles")) == 0) { + /* TODO: cleanup this block */ + 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; + db_get_job_record(ua->jcr, ua->db, &jr); + jobid = jr.JobId; + } else if (strcasecmp(ua->argk[j], NT_("jobid")) == 0 && ua->argv[j]) { + jobid = str_to_int64(ua->argv[j]); + } else { + continue; + } + if (jobid > 0) { + db_list_base_files_for_job(ua->jcr, ua->db, jobid, prtit, ua); + } + } + /* List FILES */ } else if (strcasecmp(ua->argk[i], NT_("files")) == 0) {