From: Eric Bollengier Date: Thu, 30 Jul 2009 19:56:50 +0000 (+0200) Subject: display base jobs during restore X-Git-Tag: Release-5.0.0~356 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=91c3255df32c716947d3db2a7cefe902c6b85ec9;p=bacula%2Fbacula display base jobs during restore --- diff --git a/bacula/src/cats/sql_cmds.c b/bacula/src/cats/sql_cmds.c index 476ba63d75..4ff0c6e9e4 100644 --- a/bacula/src/cats/sql_cmds.c +++ b/bacula/src/cats/sql_cmds.c @@ -293,6 +293,12 @@ const char *uar_list_jobs = "FROM Client,Job WHERE Client.ClientId=Job.ClientId AND JobStatus IN ('T','W') " "AND Type='B' ORDER BY StartTime DESC LIMIT 20"; +const char *uar_print_jobs = + "SELECT DISTINCT JobId,Level,JobFiles,JobBytes,StartTime,VolumeName" + " FROM Job JOIN JobMedia USING (JobId) JOIN Media USING (MediaId) " + " WHERE JobId IN (%s) " + " ORDER BY StartTime ASC"; + /* * Find all files for a particular JobId and insert them into * the tree during a restore. diff --git a/bacula/src/cats/sql_cmds.h b/bacula/src/cats/sql_cmds.h index 7b967572e8..a5d8054e48 100644 --- a/bacula/src/cats/sql_cmds.h +++ b/bacula/src/cats/sql_cmds.h @@ -53,6 +53,7 @@ extern const char CATS_IMP_EXP *upd_Purged; extern const char CATS_IMP_EXP *cleanup_created_job; extern const char CATS_IMP_EXP *cleanup_running_job; extern const char CATS_IMP_EXP *uar_list_jobs; +extern const char CATS_IMP_EXP *uar_print_jobs; extern const char CATS_IMP_EXP *uar_count_files; extern const char CATS_IMP_EXP *uar_sel_files; extern const char CATS_IMP_EXP *uar_del_temp; diff --git a/bacula/src/cats/sql_get.c b/bacula/src/cats/sql_get.c index 78a6862038..d216d5dd33 100644 --- a/bacula/src/cats/sql_get.c +++ b/bacula/src/cats/sql_get.c @@ -1108,7 +1108,7 @@ bool db_get_used_base_jobids(JCR *jcr, B_DB *mdb, POOLMEM *jobids, POOLMEM *resu " FROM Job JOIN BaseFiles USING (JobId) " " WHERE Job.HasBase = 1 " " AND JobId IN (%s) ", jobids); - return db_sql_query(mdb, buf.c_str(), db_get_int_handler, jobids); + return db_sql_query(mdb, buf.c_str(), db_get_int_handler, result); } /* The decision do change an incr/diff was done before diff --git a/bacula/src/dird/ua.h b/bacula/src/dird/ua.h index 4af9c01d5a..31ca5b49e4 100644 --- a/bacula/src/dird/ua.h +++ b/bacula/src/dird/ua.h @@ -106,6 +106,7 @@ struct RESTORE_CTX { char RestoreClientName[MAX_NAME_LENGTH]; /* restore client */ char last_jobid[20]; POOLMEM *JobIds; /* User entered string of JobIds */ + POOLMEM *BaseJobIds; /* Base jobids */ STORE *store; JOB *restore_job; POOL *pool; diff --git a/bacula/src/dird/ua_restore.c b/bacula/src/dird/ua_restore.c index 19415f2622..f6eb76c99d 100644 --- a/bacula/src/dird/ua_restore.c +++ b/bacula/src/dird/ua_restore.c @@ -90,6 +90,7 @@ int restore_cmd(UAContext *ua, const char *cmd) rx.path = get_pool_memory(PM_FNAME); rx.fname = get_pool_memory(PM_FNAME); rx.JobIds = get_pool_memory(PM_FNAME); + rx.BaseJobIds = get_pool_memory(PM_FNAME); rx.query = get_pool_memory(PM_FNAME); rx.bsr = new_bsr(); @@ -310,6 +311,10 @@ static void free_rx(RESTORE_CTX *rx) free_pool_memory(rx->JobIds); rx->JobIds = NULL; } + if (rx->BaseJobIds) { + free_pool_memory(rx->BaseJobIds); + rx->BaseJobIds = NULL; + } if (rx->fname) { free_pool_memory(rx->fname); rx->fname = NULL; @@ -449,7 +454,7 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) NULL }; - *rx->JobIds = 0; + rx->BaseJobIds[0] = rx->JobIds[0] = 0; for (i=1; iargc; i++) { /* loop through arguments */ bool found_kw = false; @@ -809,6 +814,7 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) ua->warning_msg(_("No Jobs selected.\n")); return 0; } + if (strchr(rx->JobIds,',')) { ua->info_msg(_("You have selected the following JobIds: %s\n"), rx->JobIds); } else { @@ -1091,9 +1097,9 @@ static bool build_directory_tree(UAContext *ua, RESTORE_CTX *rx) if (!db_get_file_list(ua->jcr, ua->db, rx->JobIds, insert_tree_handler, (void *)&tree)) { ua->error_msg("%s", db_strerror(ua->db)); } - /* we concat the base job list to the current jobids list */ - if (!db_get_used_base_jobids(ua->jcr, ua->db, rx->JobIds, rx->JobIds)) { - ua->error_msg("%s", db_strerror(ua->db)); + if (*rx->BaseJobIds) { + pm_strcat(rx->JobIds, ","); + pm_strcat(rx->JobIds, rx->BaseJobIds); } #else for (p=rx->JobIds; get_next_jobid_from_list(&p, &JobId) > 0; ) { @@ -1308,8 +1314,8 @@ static bool select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *dat } /* Get the JobIds from that list */ - rx->JobIds[0] = 0; - rx->last_jobid[0] = 0; + rx->last_jobid[0] = rx->BaseJobIds[0] = rx->JobIds[0] = 0; + if (!db_sql_query(ua->db, uar_sel_jobid_temp, jobid_handler, (void *)rx)) { ua->warning_msg("%s\n", db_strerror(ua->db)); } @@ -1323,6 +1329,18 @@ static bool select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *dat /* Display a list of Jobs selected for this restore */ db_list_sql_query(ua->jcr, ua->db, uar_list_temp, prtit, ua, 1, HORZ_LIST); ok = true; + + if (!db_get_used_base_jobids(ua->jcr, ua->db, rx->JobIds, rx->BaseJobIds)) { + ua->warning_msg("%s", db_strerror(ua->db)); + } + + if (*rx->BaseJobIds) { + POOL_MEM buf; + Mmsg(buf, uar_print_jobs, rx->BaseJobIds); + ua->send_msg(_("The restore will use the following jobs as Base\n")); + db_list_sql_query(ua->jcr, ua->db, buf.c_str(), prtit, ua, 1, HORZ_LIST); + } + } else { ua->warning_msg(_("No jobs found.\n")); }