]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_restore.c
Fix bug #1307 AllowHigherDuplicates=no prevents automatic job escalation
[bacula/bacula] / bacula / src / dird / ua_restore.c
index 2e55a404051f0119f6a3fc1732ded71fe3d22065..90a475c6b299f2e8d67796d756c4821705288075 100644 (file)
@@ -990,8 +990,12 @@ static void split_path_and_filename(UAContext *ua, RESTORE_CTX *rx, char *name)
 
 static bool ask_for_fileregex(UAContext *ua, RESTORE_CTX *rx)
 {
-   ua->send_msg(_("\nThere were no files inserted into the tree, so file selection\n"
-                  "is not possible.Most likely your retention policy pruned the files\n"));
+   if (find_arg(ua, NT_("all")) >= 0) {  /* if user enters all on command line */
+      return true;                       /* select everything */
+   }
+   ua->send_msg(_("\n\nFor one or more of the JobIds selected, no files were found,\n"
+                 "so file selection is not possible.\n"
+                 "Most likely your retention policy pruned the files.\n"));
    if (get_yesno(ua, _("\nDo you want to restore all the files? (yes|no): "))) {
       if (ua->pint32_val == 1)
          return true;
@@ -1005,8 +1009,9 @@ static bool ask_for_fileregex(UAContext *ua, RESTORE_CTX *rx)
 
             fileregex_re = (regex_t *)bmalloc(sizeof(regex_t));
             rc = regcomp(fileregex_re, ua->cmd, REG_EXTENDED|REG_NOSUB);
-            if (rc != 0)
+            if (rc != 0) {
                regerror(rc, fileregex_re, errmsg, sizeof(errmsg));
+            }
             regfree(fileregex_re);
             free(fileregex_re);
             if (*errmsg) {
@@ -1081,6 +1086,22 @@ static bool build_directory_tree(UAContext *ua, RESTORE_CTX *rx)
       }
    }
 #endif
+   /*
+    * Look at the first JobId on the list (presumably the oldest) and
+    *  if it is marked purged, don't do the manual selection because
+    *  the Job was pruned, so the tree is incomplete.
+    */
+   if (tree.FileCount != 0) {
+      /* Find out if any Job is purged */
+      Mmsg(rx->query, "SELECT SUM(PurgedFiles) FROM Job WHERE JobId IN (%s)", rx->JobIds);
+      if (!db_sql_query(ua->db, rx->query, restore_count_handler, (void *)rx)) {
+         ua->error_msg("%s\n", db_strerror(ua->db));
+      }
+      /* rx->JobId is the PurgedFiles flag */
+      if (rx->found && rx->JobId > 0) {
+         tree.FileCount = 0;           /* set count to zero, no tree selection */
+      }
+   }
    if (tree.FileCount == 0) {
       OK = ask_for_fileregex(ua, rx);
       if (OK) {