]> git.sur5r.net Git - bacula/bacula/commitdiff
Fix since truncation bug; lock db during recycling; new update command line args...
authorKern Sibbald <kern@sibbald.com>
Sun, 6 Jul 2003 21:25:57 +0000 (21:25 +0000)
committerKern Sibbald <kern@sibbald.com>
Sun, 6 Jul 2003 21:25:57 +0000 (21:25 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@624 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/ChangeLog
bacula/kernstodo
bacula/src/dird/catreq.c
bacula/src/dird/fd_cmds.c
bacula/src/dird/ua_cmds.c
bacula/src/dird/ua_label.c
bacula/src/dird/ua_run.c
bacula/src/lib/edit.c

index ea78e15b6b2a901cde2c2985de03dec7810dc156..c690e0e4d3c3add066b18cb8fd21e0da0b472fd1 100644 (file)
@@ -1,5 +1,12 @@
 
 2003-07-xx Version 1.31 Beta xxJul03
+- Lock database while recycling.
+- Fix a bug in editing since where I forgot to update to the new size.  
+- Implement all the command line update arguments.
+- Modify label to use volume=xxx for the new volume and oldvolume=yyy
+  if doing a relable.
+- Added yes to run command line arguments.
+- Clear errno in editing a string to utime.
 - In restore print only volumes that will actually be used.
 - Fix bextract -- add appropriate breaks in new case code.
 - Add a new test -- bsr-opt-test for testing bsr optimization. As usual,
index f6756b0334d8af4731674f3e3931ecebb0fb3beb..d9acc5f39274a4c7c3f255bb85eae8e902e49d44 100644 (file)
@@ -37,6 +37,7 @@ Testing to do: (painful)
 - Figure out how to use ssh or stunnel to protect Bacula communications.
 
 For 1.31 release:
+- Complete (or turn off) the command line code in update.
 - In Win portable restore the directory is not create    
    27-Jun-2003 16:52 tibs-fd: kernsrestore.2003-06-27_16.52.20 Error:
    create_file.c:175 Could not create
@@ -1017,4 +1018,3 @@ Done: (see kernsdone for more)
   Constrain FileIndex to be within range for Volume.
 - Pass prefix_links to FD.
 - Fix restore list of volumes if Volume not selected.
-
index b2453e5cc40e589c3e4821f03465b8c608017df4..5d3c306fd35ff26468d1fed69454ce4a4378796d 100644 (file)
@@ -89,6 +89,7 @@ void catalog_request(JCR *jcr, BSOCK *bs, char *msg)
       /*
        * Find the Next Volume for Append
        */
+      db_lock(jcr->db);
       for ( ;; ) {
          strcpy(mr.VolStatus, "Append");  /* want only appendable volumes */
         ok = db_find_next_volume(jcr, jcr->db, index, &mr);  
@@ -155,6 +156,7 @@ void catalog_request(JCR *jcr, BSOCK *bs, char *msg)
         }
         break;
       } /* end for loop */
+      db_unlock(jcr->db);
 
       /*
        * Send Find Media response to Storage daemon 
@@ -245,6 +247,7 @@ void catalog_request(JCR *jcr, BSOCK *bs, char *msg)
       &sdmr.VolWrites, &sdmr.MaxVolBytes, &sdmr.LastWritten, &sdmr.VolStatus, 
       &sdmr.Slot, &relabel) == 14) {
 
+      db_lock(jcr->db);
       Dmsg3(400, "Update media %s oldStat=%s newStat=%s\n", sdmr.VolumeName,
         mr.VolStatus, sdmr.VolStatus);
       bstrncpy(mr.VolumeName, sdmr.VolumeName, sizeof(mr.VolumeName)); /* copy Volume name */
@@ -253,6 +256,7 @@ void catalog_request(JCR *jcr, BSOCK *bs, char *msg)
          Jmsg(jcr, M_ERROR, 0, _("Unable to get Media record for Volume %s: ERR=%s\n"),
              mr.VolumeName, db_strerror(jcr->db));
          bnet_fsend(bs, "1991 Catalog Request failed: %s", db_strerror(jcr->db));
+        db_unlock(jcr->db);
         return;
       }
       /* Set first written time if this is first job */
@@ -323,6 +327,7 @@ void catalog_request(JCR *jcr, BSOCK *bs, char *msg)
          bnet_fsend(bs, "1992 Update Media error\n");
          Dmsg0(190, "send error\n");
       }
+      db_unlock(jcr->db);
 
    /*
     * Request to create a JobMedia record
index 450e005d807cfad4a9cb87e44afbdf738eaa193e..e2a549fbb9ac33738410c2d1ce4482dccee2b82e 100644 (file)
@@ -137,22 +137,22 @@ void get_level_since_time(JCR *jcr, char *since, int since_len)
    jcr->stime[0] = 0;
    since[0] = 0;
    switch (jcr->JobLevel) {
-      case L_DIFFERENTIAL:
-      case L_INCREMENTAL:
-        /* Look up start time of last job */
-        jcr->jr.JobId = 0;
-        if (!db_find_job_start_time(jcr, jcr->db, &jcr->jr, &jcr->stime)) {
-            Jmsg(jcr, M_INFO, 0, "%s", db_strerror(jcr->db));
-            Jmsg(jcr, M_INFO, 0, _("No prior or suitable Full backup found. Doing FULL backup.\n"));
-            bsnprintf(since, since_len, " (upgraded from %s)", 
-              level_to_str(jcr->JobLevel));
-           jcr->JobLevel = jcr->jr.Level = L_FULL;
-        } else {
-            bstrncpy(since, ", since=", sizeof(since));
-           bstrncat(since, jcr->stime, sizeof(since));
-        }
-         Dmsg1(115, "Last start time = %s\n", jcr->stime);
-        break;
+   case L_DIFFERENTIAL:
+   case L_INCREMENTAL:
+      /* Look up start time of last job */
+      jcr->jr.JobId = 0;
+      if (!db_find_job_start_time(jcr, jcr->db, &jcr->jr, &jcr->stime)) {
+         Jmsg(jcr, M_INFO, 0, "%s", db_strerror(jcr->db));
+         Jmsg(jcr, M_INFO, 0, _("No prior or suitable Full backup found. Doing FULL backup.\n"));
+         bsnprintf(since, since_len, " (upgraded from %s)", 
+           level_to_str(jcr->JobLevel));
+        jcr->JobLevel = jcr->jr.Level = L_FULL;
+      } else {
+         bstrncpy(since, ", since=", since_len);
+        bstrncat(since, jcr->stime, since_len);
+      }
+      Dmsg1(115, "Last start time = %s\n", jcr->stime);
+      break;
    }
 }
 
@@ -226,7 +226,7 @@ static int send_list(JCR *jcr, int list)
       }
       fo = ie->opts_list[0];
       for (int j=0; j<fo->match.size(); j++) {
-         Dmsg1(000, "Match=%s\n", fo->match.get(j));
+         Dmsg1(100, "Match=%s\n", fo->match.get(j));
       }
       for (int j=0; j<ie->num_names; j++) {
         p = ie->name_list[j];
index ec2cfc13ed2e5c639c697c6a4caca833590f9d58..51a853570691d66e9f40f7a9466adf07748188e4 100644 (file)
@@ -57,8 +57,8 @@ extern int retentioncmd(UAContext *ua, char *cmd);
 extern int prunecmd(UAContext *ua, char *cmd);
 extern int purgecmd(UAContext *ua, char *cmd);
 extern int restorecmd(UAContext *ua, char *cmd);
-extern int labelcmd(UAContext *ua, char *cmd);
-extern int relabelcmd(UAContext *ua, char *cmd);
+extern int label_cmd(UAContext *ua, char *cmd);
+extern int relabel_cmd(UAContext *ua, char *cmd);
 extern int update_slots(UAContext *ua);  /* ua_label.c */
 
 /* Forward referenced functions */
@@ -94,7 +94,7 @@ static struct cmdstruct commands[] = {
  { N_("estimate"),   estimate_cmd,  _("performs FileSet estimate debug=1 give full listing")},
  { N_("exit"),       quit_cmd,      _("exit = quit")},
  { N_("help"),       help_cmd,      _("print this command")},
- { N_("label"),      labelcmd,      _("label a tape")},
+ { N_("label"),      label_cmd,     _("label a tape")},
  { N_("list"),       listcmd,       _("list [pools | jobs | jobtotals | media <pool> | files job=<nn>]; from catalog")},
  { N_("llist"),      llistcmd,      _("full or long list like list command")},
  { N_("messages"),   messagescmd,   _("messages")},
@@ -103,7 +103,7 @@ static struct cmdstruct commands[] = {
  { N_("purge"),      purgecmd,      _("purge records from catalog")},
  { N_("query"),      querycmd,      _("query catalog")},
  { N_("quit"),       quit_cmd,      _("quit")},
- { N_("relabel"),    relabelcmd,    _("relabel a tape")},
+ { N_("relabel"),    relabel_cmd,   _("relabel a tape")},
  { N_("release"),    release_cmd,   _("release <storage-name>")},
  { N_("restore"),    restorecmd,    _("restore files")},
  { N_("run"),        runcmd,        _("run <job-name>")},
@@ -668,11 +668,12 @@ static void update_volstatus(UAContext *ua, char *val, MEDIA_DBR *mr)
 static void update_volretention(UAContext *ua, char *val, MEDIA_DBR *mr)
 {
    char ed1[50];
-   POOLMEM *query = get_pool_memory(PM_MESSAGE);
+   POOLMEM *query;
    if (!duration_to_utime(val, &mr->VolRetention)) {
-      bsendmsg(ua, _("Invalid retention period specified.\n"));
+      bsendmsg(ua, _("Invalid retention period specified: %s\n"), val);
       return;
    }
+   query = get_pool_memory(PM_MESSAGE);
    Mmsg(&query, "UPDATE Media SET VolRetention=%s WHERE MediaId=%u",
       edit_uint64(mr->VolRetention, ed1), mr->MediaId);
    if (!db_sql_query(ua->db, query, NULL, NULL)) {  
@@ -687,12 +688,12 @@ static void update_volretention(UAContext *ua, char *val, MEDIA_DBR *mr)
 static void update_voluseduration(UAContext *ua, char *val, MEDIA_DBR *mr)
 {
    char ed1[50];
-   POOLMEM *query = get_pool_memory(PM_MESSAGE);
+   POOLMEM *query;
+
    if (!duration_to_utime(val, &mr->VolUseDuration)) {
-      bsendmsg(ua, _("Invalid use duration specified.\n"));
+      bsendmsg(ua, _("Invalid use duration specified: %s\n"), val);
       return;
    }
-   query = get_pool_memory(PM_MESSAGE);
    Mmsg(&query, "UPDATE Media SET VolUseDuration=%s WHERE MediaId=%u",
       edit_uint64(mr->VolUseDuration, ed1), mr->MediaId);
    if (!db_sql_query(ua->db, query, NULL, NULL)) {  
@@ -734,11 +735,13 @@ static void update_volmaxbytes(UAContext *ua, char *val, MEDIA_DBR *mr)
 {
    uint64_t maxbytes;
    char ed1[50];
-   POOLMEM *query = get_pool_memory(PM_MESSAGE);
+   POOLMEM *query;
+
    if (!size_to_uint64(val, strlen(val), &maxbytes)) {
-      bsendmsg(ua, _("Invalid byte size specification.\n"));
+      bsendmsg(ua, _("Invalid max. bytes specification: %s\n"), val);
       return;
    } 
+   query = get_pool_memory(PM_MESSAGE);
    Mmsg(&query, "UPDATE Media SET MaxVolBytes=%s WHERE MediaId=%u",
       edit_uint64(maxbytes, ed1), mr->MediaId);
    if (!db_sql_query(ua->db, query, NULL, NULL)) {  
@@ -752,7 +755,7 @@ static void update_volmaxbytes(UAContext *ua, char *val, MEDIA_DBR *mr)
 static void update_volrecycle(UAContext *ua, char *val, MEDIA_DBR *mr)
 {
    int recycle;
-   POOLMEM *query = get_pool_memory(PM_MESSAGE);
+   POOLMEM *query;
    if (strcasecmp(val, _("yes")) == 0) {
       recycle = 1;
    } else if (strcasecmp(val, _("no")) == 0) {
@@ -761,6 +764,7 @@ static void update_volrecycle(UAContext *ua, char *val, MEDIA_DBR *mr)
       bsendmsg(ua, _("Invalid value. It must by yes or no.\n"));
       return;
    }
+   query = get_pool_memory(PM_MESSAGE);
    Mmsg(&query, "UPDATE Media SET Recycle=%d WHERE MediaId=%u",
       recycle, mr->MediaId);
    if (!db_sql_query(ua->db, query, NULL, NULL)) {  
@@ -790,6 +794,7 @@ static int update_volume(UAContext *ua)
       N_("VolUse"),
       N_("MaxVolJobs"),
       N_("MaxVolFiles"),
+      N_("MaxVolBytes"),
       N_("Recycle"),
       NULL };
 
@@ -797,10 +802,29 @@ static int update_volume(UAContext *ua)
       return 0;
    }
    for (int i=0; kw[i]; i++) {
-      if (find_arg_with_value(ua, kw[i]) > 0) {
+      int j;
+      if ((j=find_arg_with_value(ua, kw[i])) > 0) {
         switch (i) {
         case 0:
-           update_volstatus(ua, ua->argv[i], &mr);
+           update_volstatus(ua, ua->argv[j], &mr);
+           break;
+        case 1:
+           update_volretention(ua, ua->argv[j], &mr);
+           break;
+        case 2:
+           update_voluseduration(ua, ua->argv[j], &mr);
+           break;
+        case 3:
+           update_volmaxjobs(ua, ua->argv[j], &mr);
+           break;
+        case 4:
+           update_volmaxfiles(ua, ua->argv[j], &mr);
+           break;
+        case 5:
+           update_volmaxbytes(ua, ua->argv[j], &mr);
+           break;
+        case 6:
+           update_volrecycle(ua, ua->argv[j], &mr);
            break;
         }
         done = true;
index be0746b3239ce59e3acc3980181855fe44e3fa10..1e1a5822beb91bb880f820d2988d4735316c3b7f 100644 (file)
@@ -52,12 +52,12 @@ static int is_cleaning_tape(UAContext *ua, MEDIA_DBR *mr, POOL_DBR *pr);
  *  
  *   label storage=xxx volume=vvv
  */
-int labelcmd(UAContext *ua, char *cmd)
+int label_cmd(UAContext *ua, char *cmd)
 {
    return do_label(ua, cmd, 0);       /* standard label */
 }
 
-int relabelcmd(UAContext *ua, char *cmd)
+int relabel_cmd(UAContext *ua, char *cmd)
 {
    return do_label(ua, cmd, 1);      /* relabel tape */
 }
@@ -94,6 +94,7 @@ int update_slots(UAContext *ua)
 
       memset(&mr, 0, sizeof(mr));
       bstrncpy(mr.VolumeName, vl->VolName, sizeof(mr.VolumeName));
+      db_lock(ua->db);
       if (db_get_media_record(ua->jcr, ua->db, &mr)) {
          if (mr.Slot != vl->Slot) {
             mr.Slot = vl->Slot;
@@ -108,11 +109,13 @@ int update_slots(UAContext *ua)
              bsendmsg(ua, _("Catalog record for Volume \"%s\" is up to date.\n"),
                mr.VolumeName);
          }   
+         db_unlock(ua->db);
          continue;
       } else {
           bsendmsg(ua, _("Record for Volume \"%s\" not found in catalog.\n"), 
             mr.VolumeName);
       }
+      db_unlock(ua->db);
    }
 
 
@@ -171,8 +174,8 @@ static int do_label(UAContext *ua, char *cmd, int relabel)
 
    /* If relabel get name of Volume to relabel */
    if (relabel) {
-      /* Check for volume=OldVolume */
-      i = find_arg_with_value(ua, "volume"); 
+      /* Check for oldvolume=name */
+      i = find_arg_with_value(ua, "oldvolume"); 
       if (i >= 0) {
         memset(&omr, 0, sizeof(omr));
         bstrncpy(omr.VolumeName, ua->argv[i], sizeof(omr.VolumeName));
@@ -195,8 +198,8 @@ checkVol:
       }
    }
 
-   /* Check for name=NewVolume */
-   i = find_arg_with_value(ua, "name");
+   /* Check for volume=NewVolume */
+   i = find_arg_with_value(ua, "volume");
    if (i >= 0) {
       pm_strcpy(&ua->cmd, ua->argv[i]);
       goto checkName;
index 6dadd3dfffe72aa4a3e7cbcbd74977f5db7bebec..7e1fe8e073a19ca206a8d20a4442d882e65c656c 100644 (file)
@@ -69,6 +69,7 @@ int runcmd(UAContext *ua, char *cmd)
       N_("bootstrap"),
       N_("replace"),
       N_("when"),
+      N_("yes"),          /* 11 -- see below */
       NULL};
 
    if (!open_db(ua)) {
@@ -92,7 +93,8 @@ int runcmd(UAContext *ua, char *cmd)
       Dmsg2(200, "Doing arg %d = %s\n", i, ua->argk[i]);
       for (j=0; !found && kw[j]; j++) {
         if (strcasecmp(ua->argk[i], _(kw[j])) == 0) {
-           if (!ua->argv[i]) {
+           /* Note, yes has no value, so do not err */
+           if (!ua->argv[i] && j != 11 /*yes*/) {
                bsendmsg(ua, _("Value missing for keyword %s\n"), ua->argk[i]);
               return 1;
            }
@@ -186,6 +188,9 @@ int runcmd(UAContext *ua, char *cmd)
                  when = ua->argv[i];
                  found = True;
                  break;
+              case 11: /* yes */
+                 found = True;
+                 break;
               default:
                  break;
            }
index 0e147bcf936b48f7cca10e086300064f6c845451..153e73c9b283aaa1af7f77549537cc81867ab1a6 100644 (file)
@@ -128,6 +128,7 @@ int duration_to_utime(char *str, utime_t *value)
    if (mod[i] == 0 || !is_a_number(str)) {
       return 0;
    }
+   errno = 0;
    val = strtod(str, NULL);
    if (errno != 0 || val < 0) {
       return 0;
@@ -212,6 +213,7 @@ int size_to_uint64(char *str, int str_len, uint64_t *rtn_value)
    }
    Dmsg3(400, "size str=:%s: %lf i=%d\n", str, strtod(str, NULL), i);
 
+   errno = 0;
    value = strtod(str, NULL);
    if (errno != 0 || value < 0) {
       return 0;