X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Fdird%2Fua_restore.c;h=b3ec5f420668fbfc6952c708f14b7aab94407911;hb=b8224aab234012c2d127b84eceb160e99dd4a14d;hp=f5c4595adf83f6742e5198ce0ec3cfcce2ecf340;hpb=8f8d5c6a0536d27d4dc5ccadca2dcec3c309248e;p=bacula%2Fbacula diff --git a/bacula/src/dird/ua_restore.c b/bacula/src/dird/ua_restore.c index f5c4595adf..b3ec5f4206 100644 --- a/bacula/src/dird/ua_restore.c +++ b/bacula/src/dird/ua_restore.c @@ -68,7 +68,7 @@ static bool insert_dir_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *di static void insert_one_file_or_dir(UAContext *ua, RESTORE_CTX *rx, char *date, bool dir); static int get_client_name(UAContext *ua, RESTORE_CTX *rx); static int get_date(UAContext *ua, char *date, int date_len); -static int count_handler(void *ctx, int num_fields, char **row); +static int restore_count_handler(void *ctx, int num_fields, char **row); static bool insert_table_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *table); /* @@ -310,6 +310,8 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) char *p; char date[MAX_TIME_LENGTH]; bool have_date = false; + /* Include current second if using current time */ + utime_t now = time(NULL) + 1; JobId_t JobId; JOB_DBR jr = { (JobId_t)-1 }; bool done = false; @@ -378,7 +380,12 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) done = true; break; case 1: /* current */ - bstrutime(date, sizeof(date), time(NULL)); + /* + * Note, we add one second here just to include any job + * that may have finished within the current second, + * which happens a lot in scripting small jobs. + */ + bstrutime(date, sizeof(date), now); have_date = true; break; case 2: /* before */ @@ -398,7 +405,7 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) return 0; } if (!have_date) { - bstrutime(date, sizeof(date), time(NULL)); + bstrutime(date, sizeof(date), now); } if (!get_client_name(ua, rx)) { return 0; @@ -408,7 +415,7 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) return 2; case 5: /* select */ if (!have_date) { - bstrutime(date, sizeof(date), time(NULL)); + bstrutime(date, sizeof(date), now); } if (!select_backups_before_date(ua, rx, date)) { return 0; @@ -512,7 +519,7 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) done = false; break; case 4: /* Select the most recent backups */ - bstrutime(date, sizeof(date), time(NULL)); + bstrutime(date, sizeof(date), now); if (!select_backups_before_date(ua, rx, date)) { return 0; } @@ -526,7 +533,7 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) } break; case 6: /* Enter files */ - bstrutime(date, sizeof(date), time(NULL)); + bstrutime(date, sizeof(date), now); if (!get_client_name(ua, rx)) { return 0; } @@ -567,7 +574,7 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) return 2; case 8: /* Find JobIds for current backup */ - bstrutime(date, sizeof(date), time(NULL)); + bstrutime(date, sizeof(date), now); if (!select_backups_before_date(ua, rx, date)) { return 0; } @@ -597,7 +604,7 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) if (*rx->JobIds == 0 || *rx->JobIds == '.') { return 0; /* nothing entered, return */ } - bstrutime(date, sizeof(date), time(NULL)); + bstrutime(date, sizeof(date), now); if (!get_client_name(ua, rx)) { return 0; } @@ -771,6 +778,7 @@ static bool insert_file_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *f } if (!rx->found) { ua->error_msg(_("No database record found for: %s\n"), file); +// ua->error_msg("Query=%s\n", rx->query); return true; } return true; @@ -900,7 +908,7 @@ static bool build_directory_tree(UAContext *ua, RESTORE_CTX *rx) if (get_next_jobid_from_list(&p, &JobId) > 0) { /* Use first JobId as estimate of the number of files to restore */ Mmsg(rx->query, uar_count_files, edit_int64(JobId, ed1)); - if (!db_sql_query(ua->db, rx->query, count_handler, (void *)rx)) { + if (!db_sql_query(ua->db, rx->query, restore_count_handler, (void *)rx)) { ua->error_msg("%s\n", db_strerror(ua->db)); } if (rx->found) { @@ -1179,7 +1187,7 @@ int get_next_jobid_from_list(char **p, JobId_t *JobId) return 1; } -static int count_handler(void *ctx, int num_fields, char **row) +static int restore_count_handler(void *ctx, int num_fields, char **row) { RESTORE_CTX *rx = (RESTORE_CTX *)ctx; rx->JobId = str_to_int64(row[0]);