]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_restore.c
- Move test for MaxStartDelay as suggested by Peter.
[bacula/bacula] / bacula / src / dird / ua_restore.c
index 0c958af04dad3b45d69c4c9ba491a02059722cfb..25438c3e1a00db20ba3092512cd78e7a9199fde5 100644 (file)
@@ -66,7 +66,7 @@ struct RESTORE_CTX {
    uint32_t TotalFiles;
    uint32_t JobId;
    char ClientName[MAX_NAME_LENGTH];
-   char last_jobid[10];
+   char last_jobid[20];
    POOLMEM *JobIds;                   /* User entered string of JobIds */
    STORE  *store;
    JOB *restore_job;
@@ -306,7 +306,9 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx)
       "Select backup for a client before a specified time",
       "Enter a list of files to restore",
       "Enter a list of files to restore before a specified time",
-      "Enter a list of directories to restore for a given JobId",
+      "Find the JobIds of the most recent backup for a client",
+      "Find the JobIds for a backup for a client before a specified time",
+      "Enter a list of directories to restore for given JobIds",
       "Cancel",
       NULL };
 
@@ -446,13 +448,16 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx)
          done = false;
          break;
       case 1:                         /* list where a file is saved */
+         if (!get_client_name(ua, rx)) {
+            return 0;
+         }
          if (!get_cmd(ua, _("Enter Filename (no path):"))) {
             return 0;
          }
          len = strlen(ua->cmd);
          fname = (char *)malloc(len * 2 + 1);
          db_escape_string(fname, ua->cmd, len);
-         Mmsg(rx->query, uar_file, fname);
+         Mmsg(rx->query, uar_file, rx->ClientName, fname);
          free(fname);
          gui_save = ua->jcr->gui;
          ua->jcr->gui = true;
@@ -539,15 +544,36 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx)
          }
          return 2;
 
-      case 8:                         /* Enter directories */
-         if (get_cmd(ua, _("Enter JobId(s), comma separated, to restore: "))) {
-            if (*rx->JobIds != 0) {
+      case 8:                         /* Find JobIds for current backup */
+         bstrutime(date, sizeof(date), time(NULL));
+         if (!select_backups_before_date(ua, rx, date)) {
+            return 0;
+         }
+         done = false;
+         break;
+
+      case 9:                         /* Find JobIds for give date */
+         if (!get_date(ua, date, sizeof(date))) {
+            return 0;
+         }
+         if (!select_backups_before_date(ua, rx, date)) {
+            return 0;
+         }
+         done = false;
+         break;
+
+      case 10:                        /* Enter directories */
+         if (*rx->JobIds != 0) {
+            bsendmsg(ua, _("You have already seleted the following JobIds: %s\n"),
+               rx->JobIds);
+         } else if (get_cmd(ua, _("Enter JobId(s), comma separated, to restore: "))) {
+            if (*rx->JobIds != 0 && *ua->cmd) {
                pm_strcat(rx->JobIds, ",");
             }
-            pm_strcpy(rx->JobIds, ua->cmd);
+            pm_strcat(rx->JobIds, ua->cmd);
          }
-         if (*rx->JobIds != 0) {
-            return 0;
+         if (*rx->JobIds == 0 || *rx->JobIds == '.') {
+            return 0;                 /* nothing entered, return */
          }
          bstrutime(date, sizeof(date), time(NULL));
          if (!get_client_name(ua, rx)) {
@@ -557,13 +583,16 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx)
                         "containg a list of directories and terminate\n"
                         "them with a blank line.\n"));
          for ( ;; ) {
-            if (!get_cmd(ua, _("Enter full filename: "))) {
+            if (!get_cmd(ua, _("Enter directory name: "))) {
                return 0;
             }
             len = strlen(ua->cmd);
             if (len == 0) {
                break;
             }
+            if (ua->cmd[len-1] != '/') {
+               strcat(ua->cmd, "/");
+            }
             insert_one_file_or_dir(ua, rx, date, true);
          }
          /* Check MediaType and select storage that corresponds */
@@ -572,7 +601,7 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx)
          }
          return 2;
 
-      case 9:                         /* Cancel or quit */
+      case 11:                        /* Cancel or quit */
          return 0;
       }
    }
@@ -726,6 +755,8 @@ static bool insert_file_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *f
 static bool insert_dir_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *dir,
                                         char *date)
 {
+   char ed1[50];
+
    strip_trailing_junk(dir);
    if (*rx->JobIds == 0) {
       bsendmsg(ua, _("No JobId specified cannot continue.\n"));
@@ -747,7 +778,7 @@ static bool insert_dir_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *di
    /*
     * Find the MediaTypes for this JobId and add to the name_list
     */
-   Mmsg(rx->query, uar_mediatype, rx->JobId);
+   Mmsg(rx->query, uar_mediatype, edit_int64(rx->JobId, ed1));
    if (!db_sql_query(ua->db, rx->query, unique_name_list_handler, (void *)&rx->name_list)) {
       bsendmsg(ua, "%s", db_strerror(ua->db));
       return false;
@@ -867,8 +898,8 @@ static bool build_directory_tree(UAContext *ua, RESTORE_CTX *rx)
    }
    if (tree.FileCount == 0) {
       bsendmsg(ua, "\nThere were no files inserted into the tree, so file selection\n"
-         "is not possible.\n");
-      if (!get_yesno(ua, _("Do you want to restore all the files? (yes|no): "))) {
+         "is not possible.Most likely your retention policy pruned the files\n");
+      if (!get_yesno(ua, _("\nDo you want to restore all the files? (yes|no): "))) {
          OK = false;
       } else {
          last_JobId = 0;