]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Fix restore count issue with restore menu 11
authorEric Bollengier <eric@baculasystems.com>
Wed, 30 Sep 2020 13:17:18 +0000 (15:17 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:02:57 +0000 (09:02 +0100)
bacula/src/cats/sql_cmds.c
bacula/src/dird/ua_restore.c

index 2e50e2db16a76e85701f5ec71816061904d67e0a..c526cd1e58db9753feac42e660f24b2f5efd9980 100644 (file)
@@ -667,7 +667,7 @@ const char *uar_jobid_fileindex_from_dir[] =
    "AND Client.Name='%s' "
    "AND Job.ClientId=Client.ClientId "
    "AND Path.PathId=File.Pathid "
-   "GROUP BY File.FileIndex ",
+   "GROUP BY File.FileIndex ORDER BY Job.StartTime",
  
    /* PostgreSQL */
    "SELECT Job.JobId,File.FileIndex FROM Job,File,Path,Client "
@@ -676,7 +676,7 @@ const char *uar_jobid_fileindex_from_dir[] =
    "AND Path.Path='%s' "
    "AND Client.Name='%s' "
    "AND Job.ClientId=Client.ClientId "
-   "AND Path.PathId=File.Pathid ",
+   "AND Path.PathId=File.Pathid ORDER BY Job.StartTime ",
  
    /* SQLite */
    "SELECT Job.JobId,File.FileIndex FROM Job,File,Path,Client "
@@ -686,7 +686,7 @@ const char *uar_jobid_fileindex_from_dir[] =
    "AND Client.Name='%s' "
    "AND Job.ClientId=Client.ClientId "
    "AND Path.PathId=File.Pathid "
-   "GROUP BY File.FileIndex "
+   "GROUP BY File.FileIndex ORDER BY Job.StartTime "
 }; 
  
 const char *sql_media_order_most_recently_written[] =
index fda2cd714814791229562ad7b7b458a23fafb95d..8b38921bbf1d95e0168e19851eb99415cb533417 100644 (file)
@@ -1117,6 +1117,8 @@ static bool insert_dir_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *di
       Mmsg(rx->query, uar_jobid_fileindex_from_dir[db_get_type_index(ua->db)], rx->JobIds, dir, rx->ClientName);
    }
    rx->found = false;
+   rx->JobId = 0; /* The jobid_fileindex_handler uses JobId to fill JobIds if needed */
+
    /* Find and insert jobid and File Index */
    if (!db_sql_query(ua->db, rx->query, jobid_fileindex_handler, (void *)rx)) {
       ua->error_msg(_("Query failed: %s. ERR=%s\n"),
@@ -1703,6 +1705,9 @@ static int jobid_fileindex_handler(void *ctx, int num_fields, char **row)
     *
     * It will permit to find restore objects to send during the restore
     */
+   if (rx->JobId == 0) {        /* Avoid to duplicate the JobId inside JobIds */
+      rx->JobId = JobId;
+   }
    if (rx->JobId != JobId) {
       if (*rx->JobIds) {
          pm_strcat(rx->JobIds, ",");