]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/butil.c
Use the command line utility dropdb instead of the psql command
[bacula/bacula] / bacula / src / stored / butil.c
index a0892aa84530273953aa94ab6ff80e1f6e41b2dd..249a503c5c5a82da9da8324c221222466aef1594 100644 (file)
@@ -75,27 +75,34 @@ DEVICE *setup_to_access_device(JCR *jcr, int read_access)
    char *p;
    DEVRES *device;
 
-   jcr->VolumeName[0] = 0;
-   if (strncmp(jcr->dev_name, "/dev/", 5) != 0) {
-      /* Try stripping file part */
-      p = jcr->dev_name + strlen(jcr->dev_name);
-      while (p >= jcr->dev_name && *p != '/')
-        p--;
-      if (*p == '/') {
-        strcpy(jcr->VolumeName, p+1);
-        *p = 0;
+   /*
+    * If no volume name already given and no bsr, and it is a file,
+    * try getting name from Filename  
+    */
+   if (!jcr->bsr && jcr->VolumeName[0] == 0) {
+      if (strncmp(jcr->dev_name, "/dev/", 5) != 0) {
+        /* Try stripping file part */
+        p = jcr->dev_name + strlen(jcr->dev_name);
+         while (p >= jcr->dev_name && *p != '/')
+           p--;
+         if (*p == '/') {
+           pm_strcpy(&jcr->VolumeName, p+1);
+           *p = 0;
+        }
       }
    }
 
    if ((device=find_device_res(jcr->dev_name, read_access)) == NULL) {
-      Emsg2(M_FATAL, 0, _("Cannot find device %s in config file %s.\n"), 
+      Jmsg2(jcr, M_FATAL, 0, _("Cannot find device %s in config file %s.\n"), 
           jcr->dev_name, configfile);
       return NULL;
    }
+   jcr->device = device;
    
    dev = init_dev(NULL, device);
+   jcr->device->dev = dev;
    if (!dev || !open_device(dev)) {
-      Emsg1(M_FATAL, 0, _("Cannot open %s\n"), jcr->dev_name);
+      Jmsg1(jcr, M_FATAL, 0, _("Cannot open %s\n"), jcr->dev_name);
       return NULL;
    }
    Dmsg0(90, "Device opened for read.\n");
@@ -106,7 +113,6 @@ DEVICE *setup_to_access_device(JCR *jcr, int read_access)
 
    if (read_access) {
       if (!acquire_device_for_read(jcr, dev, block)) {
-        Emsg0(M_ERROR, 0, dev->errmsg);
         free_block(block);
         return NULL;
       }
@@ -174,6 +180,10 @@ static void my_free_jcr(JCR *jcr)
       free_pool_memory(jcr->fileset_name);
       jcr->fileset_name = NULL;
    }
+   if (jcr->fileset_md5) {
+      free_pool_memory(jcr->fileset_md5);
+      jcr->fileset_md5 = NULL;
+   }
    if (jcr->dev_name) {
       free_pool_memory(jcr->dev_name);
       jcr->dev_name = NULL;
@@ -189,32 +199,36 @@ static void my_free_jcr(JCR *jcr)
  * Setup a "daemon" JCR for the various standalone
  *  tools (e.g. bls, bextract, bscan, ...)
  */
-JCR *setup_jcr(char *name, char *device, BSR *bsr
+JCR *setup_jcr(char *name, char *device, BSR *bsr, char *VolumeName)
 {
    JCR *jcr = new_jcr(sizeof(JCR), my_free_jcr);
    jcr->VolSessionId = 1;
    jcr->VolSessionTime = (uint32_t)time(NULL);
    jcr->bsr = bsr;
-   jcr->NumVolumes = 1;
+   jcr->NumVolumes = 0;
    jcr->pool_name = get_pool_memory(PM_FNAME);
    strcpy(jcr->pool_name, "Default");
    jcr->pool_type = get_pool_memory(PM_FNAME);
    strcpy(jcr->pool_type, "Backup");
    jcr->job_name = get_pool_memory(PM_FNAME);
-   strcpy(jcr->job_name, "Dummy.Job.Name");
+   pm_strcpy(&jcr->job_name, "Dummy.Job.Name");
    jcr->client_name = get_pool_memory(PM_FNAME);
-   strcpy(jcr->client_name, "Dummy.Client.Name");
-   strcpy(jcr->Job, name);
+   pm_strcpy(&jcr->client_name, "Dummy.Client.Name");
+   bstrncpy(jcr->Job, name, sizeof(jcr->Job));
    jcr->fileset_name = get_pool_memory(PM_FNAME);
-   strcpy(jcr->fileset_name, "Dummy.fileset.name");
+   pm_strcpy(&jcr->fileset_name, "Dummy.fileset.name");
    jcr->fileset_md5 = get_pool_memory(PM_FNAME);
-   strcpy(jcr->fileset_md5, "Dummy.fileset.md5");
-   jcr->JobId = 1;
-   jcr->JobType = JT_BACKUP;
+   pm_strcpy(&jcr->fileset_md5, "Dummy.fileset.md5");
+   jcr->JobId = 0;
+   jcr->JobType = JT_CONSOLE;
    jcr->JobLevel = L_FULL;
    jcr->JobStatus = JS_Terminated;
    jcr->dev_name = get_pool_memory(PM_FNAME);
    pm_strcpy(&jcr->dev_name, device);
+   if (!bsr && VolumeName) {
+      pm_strcpy(&jcr->VolumeName, VolumeName);
+   }
+   jcr->where = bstrdup("");
    return jcr;
 }
 
@@ -222,61 +236,23 @@ JCR *setup_jcr(char *name, char *device, BSR *bsr)
 /*
  * Device got an error, attempt to analyse it
  */
-void display_error_status(DEVICE *dev)
+void display_tape_error_status(JCR *jcr, DEVICE *dev)
 {
    uint32_t status;
 
-   Emsg0(M_ERROR, 0, dev->errmsg);
+   Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
    status_dev(dev, &status);
    Dmsg1(20, "Device status: %x\n", status);
-   if (status & MT_EOD)
-      Emsg0(M_ERROR_TERM, 0, _("Unexpected End of Data\n"));
-   else if (status & MT_EOT)
-      Emsg0(M_ERROR_TERM, 0, _("Unexpected End of Tape\n"));
-   else if (status & MT_EOF)
-      Emsg0(M_ERROR_TERM, 0, _("Unexpected End of File\n"));
-   else if (status & MT_DR_OPEN)
-      Emsg0(M_ERROR_TERM, 0, _("Tape Door is Open\n"));
-   else if (!(status & MT_ONLINE))
-      Emsg0(M_ERROR_TERM, 0, _("Unexpected Tape is Off-line\n"));
+   if (status & BMT_EOD)
+      Jmsg(jcr, M_ERROR, 0, _("Unexpected End of Data\n"));
+   else if (status & BMT_EOT)
+      Jmsg(jcr, M_ERROR, 0, _("Unexpected End of Tape\n"));
+   else if (status & BMT_EOF)
+      Jmsg(jcr, M_ERROR, 0, _("Unexpected End of File\n"));
+   else if (status & BMT_DR_OPEN)
+      Jmsg(jcr, M_ERROR, 0, _("Tape Door is Open\n"));
+   else if (!(status & BMT_ONLINE))
+      Jmsg(jcr, M_ERROR, 0, _("Unexpected Tape is Off-line\n"));
    else
-      Emsg2(M_ERROR_TERM, 0, _("Read error on Record Header %s: %s\n"), dev_name(dev), strerror(errno));
-}
-
-
-extern char *getuser(uid_t uid);
-extern char *getgroup(gid_t gid);
-
-void print_ls_output(char *fname, char *link, int type, struct stat *statp)
-{
-   char buf[1000]; 
-   char ec1[30];
-   char *p, *f;
-   int n;
-
-   p = encode_mode(statp->st_mode, buf);
-   n = sprintf(p, "  %2d ", (uint32_t)statp->st_nlink);
-   p += n;
-   n = sprintf(p, "%-8.8s %-8.8s", getuser(statp->st_uid), getgroup(statp->st_gid));
-   p += n;
-   n = sprintf(p, "%8.8s ", edit_uint64(statp->st_size, ec1));
-   p += n;
-   p = encode_time(statp->st_ctime, p);
-   *p++ = ' ';
-   *p++ = ' ';
-   /* Copy file name */
-   for (f=fname; *f && (p-buf) < (int)sizeof(buf); )
-      *p++ = *f++;
-   if (type == FT_LNK) {
-      *p++ = ' ';
-      *p++ = '-';
-      *p++ = '>';
-      *p++ = ' ';
-      /* Copy link name */
-      for (f=link; *f && (p-buf) < (int)sizeof(buf); )
-        *p++ = *f++;
-   }
-   *p++ = '\n';
-   *p = 0;
-   fputs(buf, stdout);
+      Jmsg(jcr, M_ERROR, 0, _("Read error on Record Header %s: %s\n"), dev_name(dev), strerror(errno));
 }