]> git.sur5r.net Git - bacula/bacula/commitdiff
Fix LabelDate and tweaks
authorKern Sibbald <kern@sibbald.com>
Sun, 12 Jan 2003 21:12:59 +0000 (21:12 +0000)
committerKern Sibbald <kern@sibbald.com>
Sun, 12 Jan 2003 21:12:59 +0000 (21:12 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@282 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/cats/sql_create.c
bacula/src/dird/catreq.c
bacula/src/dird/ua_cmds.c
bacula/src/lib/btime.c

index b2a334b8629f83eaa19350f4f0b4e7bda4199c8c..739a3764511277de3d43410b64fd75eff2680bfa 100644 (file)
@@ -225,6 +225,8 @@ db_create_media_record(B_DB *mdb, MEDIA_DBR *mr)
 {
    int stat;
    char ed1[30], ed2[30], ed3[30], ed4[30];
+   char dt[MAX_TIME_LENGTH];
+   struct tm tm;
 
    db_lock(mdb);
    Mmsg(&mdb->cmd, "SELECT MediaId FROM Media WHERE VolumeName='%s'", 
@@ -243,10 +245,16 @@ db_create_media_record(B_DB *mdb, MEDIA_DBR *mr)
    }
 
    /* Must create it */
+   if (mr->LabelDate) {
+      localtime_r(&mr->LabelDate, &tm); 
+      strftime(dt, sizeof(dt), "%Y-%m-%d %T", &tm);
+   } else {
+      strcpy(dt, "0000-00-00 00:00:00");
+   }
    Mmsg(&mdb->cmd, 
 "INSERT INTO Media (VolumeName,MediaType,PoolId,MaxVolBytes,VolCapacityBytes," 
-"Recycle,VolRetention,VolUseDuration,VolStatus,Slot) "
-"VALUES ('%s','%s',%u,%s,%s,%d,%s,%s,'%s',%d)", 
+"Recycle,VolRetention,VolUseDuration,VolStatus,LabelDate,Slot) "
+"VALUES ('%s','%s',%u,%s,%s,%d,%s,%s,'%s','%s',%d)", 
                  mr->VolumeName,
                  mr->MediaType, mr->PoolId, 
                  edit_uint64(mr->MaxVolBytes,ed1),
@@ -254,7 +262,7 @@ db_create_media_record(B_DB *mdb, MEDIA_DBR *mr)
                  mr->Recycle,
                  edit_uint64(mr->VolRetention, ed3),
                  edit_uint64(mr->VolUseDuration, ed4),
-                 mr->VolStatus,
+                 mr->VolStatus, dt,
                  mr->Slot);
 
    Dmsg1(500, "Create Volume: %s\n", mdb->cmd);
index e68ef0a2590d528484edae7556559fdb1626fe4f..1c0d6799ea2c692ecc7e162146f28e129401ada2 100644 (file)
@@ -103,6 +103,7 @@ next_volume:
             Dmsg1(100, "find_recycled_volume2 %d\n", ok);
            if (!ok) {
               /* See if we can create a new Volume */
+              mr.LabelDate = 0;
               ok = newVolume(jcr, &mr);
            }
         }
@@ -222,7 +223,7 @@ next_volume:
         return;
       }
       /* Set first written time if this is first job */
-      if (mr.VolJobs == 0) {
+      if (mr.VolJobs == 0 || sdmr.VolJobs == 1) {
         mr.FirstWritten = jcr->start_time;   /* use Job start time as first write */
       }
       Dmsg2(200, "Update media: BefVolJobs=%u After=%u\n", mr.VolJobs, sdmr.VolJobs);
index f19e21ff062c9c88bf2dedd77e7557a2f2dfa806..af742f86ea3faf08533ebf3cf8df5b65511fc19c 100644 (file)
@@ -1305,6 +1305,7 @@ gotVol:
    unbash_spaces(mr.VolumeName);
    unbash_spaces(mr.MediaType);
    unbash_spaces(pr.Name);
+   mr.LabelDate = time(NULL);
    if (ok) {
       set_pool_dbr_defaults_in_media_dbr(&mr, &pr);
       if (db_create_media_record(ua->db, &mr)) {
index 77df8f01c48d18b0ccd649b67a4c514bcc8f2b38..efdfecc2d7cc5b9d6a631af37c06923fbcdd4785 100644 (file)
@@ -60,11 +60,12 @@ utime_t str_to_utime(char *str)
    }
    if (tm.tm_mon > 0) {
       tm.tm_mon--;
+   } else { 
+      return 0;
    }
    if (tm.tm_year >= 1900) {
-      tm.tm_year -= 1900;
    } else {
-      tm.tm_year = 0;
+      return 0;
    }
    return (utime_t)mktime(&tm);
 }