]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/bscan.c
This commit was manufactured by cvs2svn to create tag
[bacula/bacula] / bacula / src / stored / bscan.c
index d367b99a3efa41fe4c68484615121f82b7ed501d..ff212e24dc62451bc785a188331cf2c0b73958df 100644 (file)
    Copyright (C) 2001-2005 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
+   modify it under the terms of the GNU General Public License
+   version 2 as amended with additional clauses defined in the
+   file LICENSE in the main source directory.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-   MA 02111-1307, USA.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+   the file LICENSE for additional details.
 
  */
 
@@ -112,7 +107,7 @@ static void usage()
 {
    fprintf(stderr, _(
 "Copyright (C) 2001-2005 Kern Sibbald.\n"
-"\nVersion: " VERSION " (" BDATE ")\n\n"
+"\nVersion: %s (%s)\n\n"
 "Usage: bscan [ options ] <bacula-archive>\n"
 "       -b bootstrap      specify a bootstrap file\n"
 "       -c <file>         specify configuration file\n"
@@ -129,7 +124,7 @@ static void usage()
 "       -v                verbose\n"
 "       -V <Volumes>      specify Volume names (separated by |)\n"
 "       -w <dir>          specify working directory (default from conf file)\n"
-"       -?                print this message\n\n"));
+"       -?                print this message\n\n"), VERSION, BDATE);
    exit(1);
 }
 
@@ -139,6 +134,10 @@ int main (int argc, char *argv[])
    struct stat stat_buf;
    char *VolumeName = NULL;
 
+   setlocale(LC_ALL, "");
+   bindtextdomain("bacula", LOCALEDIR);
+   textdomain("bacula");
+
    my_name_is(argc, argv, "bscan");
    init_msg(NULL, NULL);
 
@@ -260,7 +259,7 @@ int main (int argc, char *argv[])
    if (!bjcr) {
       exit(1);
    }
-   dev = bjcr->dcr->dev;
+   dev = bjcr->read_dcr->dev;
    if (showProgress) {
       char ed1[50];
       struct stat sb;
@@ -283,9 +282,14 @@ int main (int argc, char *argv[])
    }
 
    do_scan();
-   printf("Records %sadded or updated in the catalog:\n%7d Media\n%7d Pool\n%7d Job\n%7d File\n",
-      update_db?"":"would have been ",
-      num_media, num_pools, num_jobs, num_files);
+   if (update_db) {
+      printf("Records added or updated in the catalog:\n%7d Media\n%7d Pool\n%7d Job\n%7d File\n",
+         num_media, num_pools, num_jobs, num_files);
+   }
+   else {
+      printf("Records would have been added or updated in the catalog:\n%7d Media\n%7d Pool\n%7d Job\n%7d File\n",
+         num_media, num_pools, num_jobs, num_files);
+   }
 
    free_jcr(bjcr);
    term_dev(dev);
@@ -317,6 +321,7 @@ static bool bscan_mount_next_read_volume(DCR *dcr)
 //       mdcr->EndBlock = (uint32_t)dcr->file_addr;
 //       mdcr->EndFile = (uint32_t)(dcr->file_addr >> 32);
       }
+      mjcr->read_dcr->VolLastIndex = dcr->VolLastIndex;
       if (!create_jobmedia_record(db, mjcr)) {
          Pmsg2(000, _("Could not create JobMedia record for Volume=%s Job=%s\n"),
             dev->VolCatInfo.VolCatName, mjcr->Job);
@@ -352,7 +357,7 @@ static void do_scan()
 
    /* Detach bscan's jcr as we are not a real Job on the tape */
 
-   read_records(bjcr->dcr, record_cb, bscan_mount_next_read_volume);
+   read_records(bjcr->read_dcr, record_cb, bscan_mount_next_read_volume);
 
    free_attr(attr);
 }
@@ -371,10 +376,10 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec)
 
    if (rec->data_len > 0) {
       mr.VolBytes += rec->data_len + WRITE_RECHDR_LENGTH; /* Accumulate Volume bytes */
-      if (showProgress) {
+      if (showProgress && currentVolumeSize > 0) {
          int pct = (mr.VolBytes * 100) / currentVolumeSize;
          if (pct != last_pct) {
-            fprintf(stdout, "done: %d%%\n", pct);
+            fprintf(stdout, _("done: %d%%\n"), pct);
             fflush(stdout);
             last_pct = pct;
          }
@@ -429,7 +434,7 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec)
 
          /* Check Media Info */
          memset(&mr, 0, sizeof(mr));
-         bstrncpy(mr.VolumeName, dev->VolHdr.VolName, sizeof(mr.VolumeName));
+         bstrncpy(mr.VolumeName, dev->VolHdr.VolumeName, sizeof(mr.VolumeName));
          mr.PoolId = pr.PoolId;
          num_media++;
          if (db_get_media_record(bjcr, db, &mr)) {
@@ -495,10 +500,11 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec)
 
          /* process label, if Job record exists don't update db */
          mjcr = create_job_record(db, &jr, &label, rec);
-         dcr = mjcr->dcr;
+         dcr = mjcr->read_dcr;
          update_db = save_update_db;
 
          jr.PoolId = pr.PoolId;
+#ifdef xxx
          /* Set start positions into JCR */
          if (dev->is_tape()) {
             /*
@@ -511,6 +517,7 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec)
             dcr->StartBlock = (uint32_t)dev->file_addr;
             dcr->StartFile = (uint32_t)(dev->file_addr >> 32);
          }
+#endif
          mjcr->start_time = jr.StartTime;
          mjcr->JobLevel = jr.JobLevel;
 
@@ -564,8 +571,9 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec)
          mjcr->JobStatus = JS_Terminated;
 
          /* Create JobMedia record */
+         mjcr->read_dcr->VolLastIndex = dcr->VolLastIndex;
          create_jobmedia_record(db, mjcr);
-         dev->attached_dcrs->remove(mjcr->dcr);
+         dev->attached_dcrs->remove(mjcr->read_dcr);
          free_jcr(mjcr);
 
          break;
@@ -597,7 +605,7 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec)
                if (!db_update_job_end_record(bjcr, db, &jr)) {
                   Pmsg1(0, _("Could not update job record. ERR=%s\n"), db_strerror(db));
                }
-               mjcr->dcr = NULL;
+               mjcr->read_dcr = NULL;
                free_jcr(mjcr);
             }
          }
@@ -625,7 +633,7 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec)
       }
       return true;
    }
-   dcr = mjcr->dcr;
+   dcr = mjcr->read_dcr;
    if (dcr->VolFirstIndex == 0) {
       dcr->VolFirstIndex = block->FirstIndex;
    }
@@ -737,7 +745,7 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec)
  */
 static void bscan_free_jcr(JCR *jcr)
 {
-   Dmsg0(200, "Start dird free_jcr\n");
+   Dmsg0(200, "Start bscan free_jcr\n");
 
    if (jcr->file_bsock) {
       Dmsg0(200, "Close File bsock\n");
@@ -754,7 +762,11 @@ static void bscan_free_jcr(JCR *jcr)
       free_dcr(jcr->dcr);
       jcr->dcr = NULL;
    }
-   Dmsg0(200, "End dird free_jcr\n");
+   if (jcr->read_dcr) {
+      free_dcr(jcr->read_dcr);
+      jcr->read_dcr = NULL;
+   }
+   Dmsg0(200, "End bscan free_jcr\n");
 }
 
 /*
@@ -765,7 +777,7 @@ static int create_file_attributes_record(B_DB *db, JCR *mjcr,
                                char *fname, char *lname, int type,
                                char *ap, DEV_RECORD *rec)
 {
-   DCR *dcr = mjcr->dcr;
+   DCR *dcr = mjcr->read_dcr;
    ar.fname = fname;
    ar.link = lname;
    ar.ClientId = mjcr->ClientId;
@@ -1097,7 +1109,7 @@ static int update_job_record(B_DB *db, JOB_DBR *jr, SESSION_LABEL *elabel,
 static int create_jobmedia_record(B_DB *db, JCR *mjcr)
 {
    JOBMEDIA_DBR jmr;
-   DCR *dcr = mjcr->dcr;
+   DCR *dcr = mjcr->read_dcr;
 
    if (dev->is_tape()) {
       dcr->EndBlock = dev->EndBlock;
@@ -1113,7 +1125,7 @@ static int create_jobmedia_record(B_DB *db, JCR *mjcr)
    jmr.JobId = mjcr->JobId;
    jmr.MediaId = mr.MediaId;
    jmr.FirstIndex = dcr->VolFirstIndex;
-   jmr.LastIndex = dcr->FileIndex;
+   jmr.LastIndex = dcr->VolLastIndex;
    jmr.StartFile = dcr->StartFile;
    jmr.EndFile = dcr->EndFile;
    jmr.StartBlock = dcr->StartBlock;
@@ -1192,7 +1204,8 @@ static JCR *create_jcr(JOB_DBR *jr, DEV_RECORD *rec, uint32_t JobId)
    jobjcr->VolSessionId = rec->VolSessionId;
    jobjcr->VolSessionTime = rec->VolSessionTime;
    jobjcr->ClientId = jr->ClientId;
-   new_dcr(jobjcr, dev);
+   jobjcr->read_dcr = new_dcr(jobjcr, dev);
+
    return jobjcr;
 }
 
@@ -1205,6 +1218,9 @@ bool    dir_ask_sysop_to_create_appendable_volume(DCR *dcr) { return 1; }
 bool    dir_update_file_attributes(DCR *dcr, DEV_RECORD *rec) { return 1;}
 bool    dir_send_job_status(JCR *jcr) {return 1;}
 int     generate_job_event(JCR *jcr, const char *event) { return 1; }
+VOLRES *new_volume(DCR *dcr, const char *VolumeName) { return NULL; }
+bool    free_volume(DEVICE *dev) { return true; }
+void    free_unused_volume(DCR *dcr) { }
 
 bool dir_ask_sysop_to_mount_volume(DCR *dcr)
 {
@@ -1214,8 +1230,8 @@ bool dir_ask_sysop_to_mount_volume(DCR *dcr)
    if (dev_cap(dev, CAP_OFFLINEUNMOUNT)) {
       offline_dev(dev);
    }
-   force_close_dev(dev);
-   fprintf(stderr, "Mount Volume \"%s\" on device %s and press return when ready: ",
+   force_close_device(dev);
+   fprintf(stderr, _("Mount Volume \"%s\" on device %s and press return when ready: "),
          dcr->VolumeName, dev->print_name());
    getchar();
    return true;