From 20979f1830333991afa582df39219df5cd898148 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Sat, 20 Nov 2010 23:30:02 +0100 Subject: [PATCH] Add db_get_file_list_with_delta() for restore This function returns the list of all files with Delta --- bacula/src/cats/protos.h | 3 +++ bacula/src/cats/sql_cmds.h | 1 + bacula/src/cats/sql_get.c | 43 +++++++++++++++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/bacula/src/cats/protos.h b/bacula/src/cats/protos.h index 0a384bfc05..2a0f3376dd 100644 --- a/bacula/src/cats/protos.h +++ b/bacula/src/cats/protos.h @@ -124,6 +124,9 @@ int db_get_client_record(JCR *jcr, B_DB *mdb, CLIENT_DBR *cdbr); int db_get_counter_record(JCR *jcr, B_DB *mdb, COUNTER_DBR *cr); bool db_get_query_dbids(JCR *jcr, B_DB *mdb, POOL_MEM &query, dbid_list &ids); bool db_get_file_list(JCR *jcr, B_DB *mdb, char *jobids, bool use_md5, DB_RESULT_HANDLER *result_handler, void *ctx); +bool db_get_file_list_with_delta(JCR *jcr, B_DB *mdb, + char *jobids, bool use_md5, + DB_RESULT_HANDLER *result_handler, void *ctx); bool db_get_base_jobid(JCR *jcr, B_DB *mdb, JOB_DBR *jr, JobId_t *jobid); bool db_accurate_get_jobids(JCR *jcr, B_DB *mdb, JOB_DBR *jr, db_list_ctx *jobids); bool db_get_used_base_jobids(JCR *jcr, B_DB *mdb, POOLMEM *jobids, db_list_ctx *result); diff --git a/bacula/src/cats/sql_cmds.h b/bacula/src/cats/sql_cmds.h index 51d7b4c594..8ac2301745 100644 --- a/bacula/src/cats/sql_cmds.h +++ b/bacula/src/cats/sql_cmds.h @@ -69,6 +69,7 @@ extern const char CATS_IMP_EXP *uar_sel_jobid_temp; extern const char CATS_IMP_EXP *select_recent_version[5]; extern const char CATS_IMP_EXP *select_recent_version_with_basejob[5]; +extern const char CATS_IMP_EXP *select_recent_version_with_basejob_and_delta[]; extern const char CATS_IMP_EXP *create_temp_accurate_jobids[5]; extern const char CATS_IMP_EXP *create_temp_basefile[5]; extern const char CATS_IMP_EXP *create_temp_new_basefile[5]; diff --git a/bacula/src/cats/sql_get.c b/bacula/src/cats/sql_get.c index 755c765401..e38e5dde04 100644 --- a/bacula/src/cats/sql_get.c +++ b/bacula/src/cats/sql_get.c @@ -1119,13 +1119,18 @@ bool db_get_file_list(JCR *jcr, B_DB *mdb, char *jobids, bool use_md5, POOL_MEM buf2(PM_MESSAGE); Mmsg(buf2, select_recent_version_with_basejob[db_type], jobids, jobids, jobids, jobids); + + /* bsr code is optimized for JobId sorted, with Delta, we need to get + * them ordered by date. JobTDate and JobId can be mixed if using Copy + * or Migration + */ Mmsg(buf, "SELECT Path.Path, Filename.Name, T1.FileIndex, T1.JobId, LStat, MarkId, MD5 " "FROM ( %s ) AS T1 " "JOIN Filename ON (Filename.FilenameId = T1.FilenameId) " "JOIN Path ON (Path.PathId = T1.PathId) " "WHERE FileIndex > 0 " -"ORDER BY T1.JobTDate, FileIndex ASC",/* Return sorted by JobId, */ +"ORDER BY T1.JobTDate, FileIndex ASC",/* Return sorted by JobTDate */ /* FileIndex for restore code */ buf2.c_str()); if (!use_md5) { @@ -1143,6 +1148,42 @@ bool db_get_file_list(JCR *jcr, B_DB *mdb, char *jobids, bool use_md5, return db_sql_query(mdb, buf.c_str(), result_handler, ctx); } +bool db_get_file_list_with_delta(JCR *jcr, B_DB *mdb, + char *jobids, bool use_md5, + DB_RESULT_HANDLER *result_handler, void *ctx) +{ + if (!*jobids) { + db_lock(mdb); + Mmsg(mdb->errmsg, _("ERR=JobIds are empty\n")); + db_unlock(mdb); + return false; + } + POOL_MEM buf(PM_MESSAGE); + POOL_MEM buf2(PM_MESSAGE); + Mmsg(buf2, select_recent_version_with_basejob_and_delta[db_type], + jobids, jobids, jobids, jobids); + + /* bsr code is optimized for JobId sorted, with Delta, we need to get + * them ordered by date. JobTDate and JobId can be mixed if using Copy + * or Migration + */ + Mmsg(buf, +"SELECT Path.Path, Filename.Name, T1.FileIndex, T1.JobId, LStat, MarkId, MD5 " + "FROM ( %s ) AS T1 " + "JOIN Filename ON (Filename.FilenameId = T1.FilenameId) " + "JOIN Path ON (Path.PathId = T1.PathId) " +"WHERE FileIndex > 0 " +"ORDER BY T1.JobTDate, FileIndex ASC",/* Return sorted by JobTDate */ + /* FileIndex for restore code */ + buf2.c_str()); + if (!use_md5) { + replace_md5(buf.c_str()); + } + Dmsg1(100, "q=%s\n", buf.c_str()); + + return db_sql_query(mdb, buf.c_str(), result_handler, ctx); +} + /** * This procedure gets the base jobid list used by jobids, */ -- 2.39.5