]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Add cats functions to deal with new Job table fields
authorEric Bollengier <eric@baculasystems.com>
Fri, 12 Aug 2022 08:43:44 +0000 (10:43 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:56:59 +0000 (13:56 +0200)
bacula/src/cats/cats.h
bacula/src/cats/sql_cmds.c
bacula/src/cats/sql_create.c
bacula/src/cats/sql_get.c
bacula/src/cats/sql_list.c
bacula/src/cats/sql_update.c

index 8ad4453b450a90847cb82e03d421d8182436a1af..4204c72dde21b45152b7f2b0d517c28e5ec75f9b 100644 (file)
@@ -140,6 +140,7 @@ struct JOB_DBR {
    time_t StartTime;                  /* Job start time */
    time_t EndTime;                    /* Job termination time of orig job */
    time_t RealEndTime;                /* Job termination time of this job */
+   time_t RealStartTime;              /* Job start time of this job (even VirtualFull) */
    utime_t JobTDate;                  /* Backup time/date in seconds */
    uint32_t VolSessionId;
    uint32_t VolSessionTime;
@@ -172,6 +173,7 @@ struct JOB_DBR {
    char cStartTime[MAX_TIME_LENGTH];
    char cEndTime[MAX_TIME_LENGTH];
    char cRealEndTime[MAX_TIME_LENGTH];
+   char cRealStartTime[MAX_TIME_LENGTH];
    /* Extra stuff not in DB */
    int     order;                     /* 0 ASC, 1 DESC */
    int     limit;                     /* limit records to display */
index 9fd9d99663cbcbd723b612e51863381fad29c7c9..9614e9da56a72ca48eb7afab7c2c32372d039cb7 100644 (file)
@@ -73,15 +73,17 @@ const char *sync_jobhisto[] =
 const char *fill_jobhisto =
         "INSERT INTO JobHisto (JobId, Job, Name, Type, Level,"
            "ClientId, JobStatus,"
-           "SchedTime, StartTime, EndTime, RealEndTime, JobTDate,"
+           "SchedTime, StartTime, EndTime, RealEndTime, RealStartTime, JobTDate,"
            "VolSessionId, VolSessionTime, JobFiles, JobBytes, ReadBytes,"
            "JobErrors, JobMissingFiles, PoolId, FileSetId, PriorJobId, PriorJob, "
-           "PurgedFiles, HasBase, HasCache, Reviewed, Comment, FileTable)"
+           "PurgedFiles, HasBase, HasCache, Reviewed, Comment, FileTable, "
+           "isVirtualFull,CompressRatio,Rate,LastReadStorageId,WriteStorageId,ReadDevice,WriteDevice,StatusInfo)"
         "SELECT JobId, Job, Name, Type, Level, ClientId, JobStatus,"
-           "SchedTime, StartTime, EndTime, RealEndTime, JobTDate,"
+           "SchedTime, StartTime, EndTime, RealEndTime, RealStartTime, JobTDate,"
            "VolSessionId, VolSessionTime, JobFiles, JobBytes, ReadBytes,"
            "JobErrors, JobMissingFiles, PoolId, FileSetId, PriorJobId, PriorJob, "
-           "PurgedFiles, HasBase, HasCache, Reviewed, Comment, FileTable "
+           "PurgedFiles, HasBase, HasCache, Reviewed, Comment, FileTable, "
+           "isVirtualFull,CompressRatio,Rate,LastReadStorageId,WriteStorageId,ReadDevice,WriteDevice,StatusInfo"
           "FROM Job "
          "WHERE JobStatus IN ('T','W','f','A','E')"
            "AND NOT EXISTS "
index 17fd4a8715ca153c85141d212c22977cc74f4ddb..3a4caaa87f896e101c040551869f4f40b2f59eb3 100644 (file)
@@ -78,11 +78,11 @@ bool BDB::bdb_create_job_record(JCR *jcr, JOB_DBR *jr)
    /* Must create it */
    Mmsg(cmd,
 "INSERT INTO Job (Job,Name,Type,Level,JobStatus,StartTime,SchedTime,JobTDate,"
-                 "ClientId,Comment) "
-"VALUES ('%s','%s','%c','%c','%c','%s','%s',%s,%s,'%s')",
+                 "ClientId,Comment,isVirtualFull) "
+"VALUES ('%s','%s','%c','%c','%c','%s','%s',%s,%s,'%s',%d)",
            esc_job, esc_name, (char)(jr->JobType), (char)(jr->JobLevel),
           (char)(jr->JobStatus), dt2, dt, edit_uint64(JobTDate, ed1),
-           edit_int64(jr->ClientId, ed2), buf.c_str());
+          edit_int64(jr->ClientId, ed2), buf.c_str(), jr->isVirtualFull);
 
    if ((jr->JobId = sql_insert_autokey_record(cmd, NT_("Job"))) == 0) {
       Mmsg2(&errmsg, _("Create DB Job record %s failed. ERR=%s\n"),
index fe4109c490127f6cb87bca4f0a9cd8a51d0fd318..a6d9b1bf24440907b14b219ec65c0c44697186c8 100644 (file)
@@ -256,18 +256,16 @@ bool BDB::bdb_get_job_record(JCR *jcr, JOB_DBR *jr)
          Mmsg(cmd, "SELECT VolSessionId,VolSessionTime,"
 "PoolId,StartTime,EndTime,JobFiles,JobBytes,JobTDate,Job,JobStatus,"
 "Type,Level,ClientId,Job.Name,PriorJobId,RealEndTime,JobId,FileSetId,"
-"SchedTime,ReadBytes,HasBase,PurgedFiles,PriorJob,Comment,"
-"Reviewed, Client.Name AS Client "
-"FROM Job JOIN Client USING (ClientId) WHERE Job='%s'", esc);
+"SchedTime,RealStartTime,ReadBytes,HasBase,PurgedFiles,PriorJob,Comment,Reviewed,Client.Name AS Client,isVirtualFull,WriteStorageId,LastReadstorageId "
+"FROM Job WHERE Job='%s'", esc);
 
       } else if (jr->PriorJob[0]) {
          bdb_escape_string(jcr, esc, jr->PriorJob, strlen(jr->PriorJob));
          Mmsg(cmd, "SELECT VolSessionId,VolSessionTime,"
 "PoolId,StartTime,EndTime,JobFiles,JobBytes,JobTDate,Job,JobStatus,"
-"Type,Level,ClientId,Job.Name AS Name,PriorJobId,RealEndTime,JobId,FileSetId,"
-"SchedTime,ReadBytes,HasBase,PurgedFiles,PriorJob,Comment,"
-"Reviewed, Client.Name AS Client "
-"FROM Job JOIN CLient USING (ClientId) WHERE PriorJob='%s' ORDER BY Type ASC LIMIT 1", esc);
+"Type,Level,ClientId,Name,PriorJobId,RealEndTime,JobId,FileSetId,"
+"SchedTime,RealStartTime,ReadBytes,HasBase,PurgedFiles,PriorJob,Comment,Reviewed,Client.Name AS Client,isVirtualFull,WriteStorageId,LastReadstorageId "
+"FROM Job WHERE PriorJob='%s' ORDER BY Type ASC LIMIT 1", esc);
       } else {
          Mmsg0(errmsg, _("No Job found\n"));
          bdb_unlock();
@@ -278,13 +276,13 @@ bool BDB::bdb_get_job_record(JCR *jcr, JOB_DBR *jr)
       Mmsg(cmd, "SELECT VolSessionId,VolSessionTime,"
 // 2      3         4        5       6       7        8    9           
 "PoolId,StartTime,EndTime,JobFiles,JobBytes,JobTDate,Job,JobStatus,"
-// 10  11    12       13                 14          15       16      17
-"Type,Level,ClientId,Job.Name AS Name,PriorJobId,RealEndTime,JobId,FileSetId,"
-// 18       19         20       21          22      23           
-"SchedTime,ReadBytes,HasBase,PurgedFiles,PriorJob,Comment,"
-// 24          25
-"Reviewed, Client.Name AS Client "
-"FROM Job JOIN Client USING (ClientId) WHERE JobId=%s",
+// 10 11     12      13    14           15        16     17
+"Type,Level,ClientId,Name,PriorJobId,RealEndTime,JobId,FileSetId,"
+// 18        19            20        21       22            23   24       25       26
+"SchedTime,RealStartTime,ReadBytes,HasBase,PurgedFiles,PriorJob,Comment,Reviewed,Client.Name AS Client,"
+//        27          28           29              30        31              32     
+"isVirtualFull,WriteStorageId,LastReadStorageId,StatusInfo,LastReadDevice,WriteDevice "
+"FROM Job WHERE JobId=%s",
           edit_int64(jr->JobId, ed1));
    }
 
@@ -327,17 +325,25 @@ bool BDB::bdb_get_job_record(JCR *jcr, JOB_DBR *jr)
    }
    jr->FileSetId = str_to_int64(row[17]);
    bstrncpy(jr->cSchedTime, row[18]!=NULL?row[18]:"", sizeof(jr->cSchedTime));
-   jr->ReadBytes = str_to_int64(row[19]);
+   bstrncpy(jr->cRealStartTime, row[19]!=NULL?row[19]:"", sizeof(jr->cRealStartTime));
+   jr->ReadBytes = str_to_int64(row[20]);
    jr->StartTime = str_to_utime(jr->cStartTime);
    jr->SchedTime = str_to_utime(jr->cSchedTime);
    jr->EndTime = str_to_utime(jr->cEndTime);
    jr->RealEndTime = str_to_utime(jr->cRealEndTime);
-   jr->HasBase = str_to_int64(row[20]);
-   jr->PurgedFiles = str_to_int64(row[21]);
-   bstrncpy(jr->PriorJob, NPRTB(row[22]), sizeof(jr->PriorJob));
-   bstrncpy(jr->Comment, NPRTB(row[23]), sizeof(jr->Comment));
-   jr->Reviewed = str_to_int64(row[24]);
-   bstrncpy(jr->Client, NPRTB(row[25]), sizeof(jr->Client));
+   jr->RealStartTime = str_to_utime(jr->cRealStartTime);
+   jr->HasBase = str_to_int64(row[21]);
+   jr->PurgedFiles = str_to_int64(row[22]);
+   bstrncpy(jr->PriorJob, NPRTB(row[23]), sizeof(jr->PriorJob));
+   bstrncpy(jr->Comment, NPRTB(row[24]), sizeof(jr->Comment));
+   jr->Reviewed = str_to_int64(row[25]);
+   bstrncpy(jr->Client, NPRTB(row[26]), sizeof(jr->Client));
+   jr->isVirtualFull = str_to_int64(row[27]);
+   jr->WriteStorageId = str_to_int64(row[28]);
+   jr->LastReadStorageId = str_to_int64(row[29]);
+   bstrncpy(jr->StatusInfo, NPRTB(row[30]), sizeof(jr->StatusInfo));
+   bstrncpy(jr->LastReadDevice, NPRTB(row[31]), sizeof(jr->LastReadDevice));
+   bstrncpy(jr->WriteDevice, NPRTB(row[32]), sizeof(jr->WriteDevice));
    sql_free_result();
 
    bdb_unlock();
index e457c6431cfe6d00d1d7354ad0043fd1d3e3821b..d0ac2cf77e382fc0074dcd8f5cd0cb8a2b6ebda7 100644 (file)
@@ -905,6 +905,10 @@ alist *BDB::bdb_list_job_records(JCR *jcr, JOB_DBR *jr, DB_LIST_HANDLER *sendit,
    } else if (jr->Reviewed > 0) {
       Mmsg(tmp, " Job.Reviewed = %d ", jr->Reviewed);
       append_filter(&where, tmp);
+
+   } else if (jr->isVirtualFull > 0) {
+      Mmsg(tmp, " Job.isVirtualFull = %d ", jr->isVirtualFull);
+      append_filter(&where, tmp);
    }
 
    if (type == INCOMPLETE_JOBS && jr->JobStatus == JS_FatalError) {
@@ -942,6 +946,11 @@ alist *BDB::bdb_list_job_records(JCR *jcr, JOB_DBR *jr, DB_LIST_HANDLER *sendit,
       append_filter(&where, tmp);
    }
 
+   if (jr->isVirtualFull > 0) {
+      Mmsg(tmp, " Job.isVirtualFull=%s ", edit_int64(jr->isVirtualFull, ed1));
+      append_filter(&where, tmp);
+   }
+
    where_tmp = get_acls(DB_ACL_BIT(DB_ACL_CLIENT)  |
                         DB_ACL_BIT(DB_ACL_JOB)     |
                         DB_ACL_BIT(DB_ACL_FILESET),
@@ -959,12 +968,14 @@ alist *BDB::bdb_list_job_records(JCR *jcr, JOB_DBR *jr, DB_LIST_HANDLER *sendit,
       Mmsg(cmd,
            "SELECT JobId,Job,Job.Name,PurgedFiles,Type,Level,"
            "Job.ClientId,Client.Name as ClientName,JobStatus,Status.JobStatusLong,SchedTime,"
-           "StartTime,EndTime,RealEndTime,JobTDate,"
+           "StartTime,EndTime,RealEndTime,RealStartTime,JobTDate,"
            "VolSessionId,VolSessionTime,JobFiles,JobBytes,ReadBytes,JobErrors,"
-           "JobMissingFiles,Job.PoolId,Pool.Name as PoolName,PriorJobId,"
-           "Job.FileSetId,FileSet.FileSet,Job.HasCache,Comment,Reviewed "
+           "JobMissingFiles,Job.PoolId,Pool.Name as PoolName,PriorJobId,PriorJob,"
+           "Job.FileSetId,FileSet.FileSet,Job.HasCache,Comment,Reviewed,isVirtualFull,Rate,CompressRatio,StatusInfo, "
+           "SW.Name AS WriteStorage, WriteDevice, SR.Name AS LastReadStorage, LastReadDevice "
            "FROM Job JOIN Client USING (ClientId) LEFT JOIN Pool USING (PoolId) "
-           "LEFT JOIN FileSet USING (FileSetId) LEFT JOIN Status USING (JobStatus) %s "
+           "LEFT JOIN FileSet USING (FileSetId) LEFT JOIN Status USING (JobStatus) "
+           "LEFT JOIN Storage AS SW ON (SW.StorageId = Job.WriteStorageId) LEFT JOIN Storage AS SR ON (SR.StorageId = Job.LastReadStorageId) %s "
            "ORDER BY StartTime %s %s", where, order, limit);
       break;
    case HORZ_LIST:
index d29bf50d0d67c84ca700cf5183ab73c4648c2fab..8c5dcc44d402cb04485595e661da9a17ec78ffb8 100644 (file)
@@ -149,10 +149,13 @@ int BDB::bdb_update_job_end_record(JCR *jcr, JOB_DBR *jr)
 {
    char dt[MAX_TIME_LENGTH];
    char rdt[MAX_TIME_LENGTH];
+   char esc1[MAX_ESCAPE_NAME_LENGTH];
+   char esc2[MAX_ESCAPE_UNAME_LENGTH];
+   char esc3[MAX_ESCAPE_UNAME_LENGTH];
    time_t ttime;
    struct tm tm;
    int stat;
-   char ed1[30], ed2[30], ed3[50], ed4[50];
+   char ed1[30], ed2[30], ed3[50], ed4[50], ed5[50], ed6[50];
    btime_t JobTDate;
    char PriorJobId[50];
 
@@ -176,16 +179,22 @@ int BDB::bdb_update_job_end_record(JCR *jcr, JOB_DBR *jr)
    JobTDate = ttime;
 
    bdb_lock();
+   bdb_escape_string(jcr, esc1, jr->StatusInfo, strlen(jr->StatusInfo));
+   bdb_escape_string(jcr, esc2, jr->LastReadDevice, strlen(jr->LastReadDevice));
+   bdb_escape_string(jcr, esc3, jr->WriteDevice, strlen(jr->WriteDevice));
    Mmsg(cmd,
       "UPDATE Job SET JobStatus='%c',EndTime='%s',"
 "ClientId=%u,JobBytes=%s,ReadBytes=%s,JobFiles=%u,JobErrors=%u,VolSessionId=%u,"
 "VolSessionTime=%u,PoolId=%u,FileSetId=%u,JobTDate=%s,"
-"RealEndTime='%s',PriorJobId=%s,HasBase=%u,PurgedFiles=%u,PriorJob='%s' WHERE JobId=%s",
+"RealEndTime='%s',PriorJobId=%s,HasBase=%u,PurgedFiles=%u,PriorJob='%s',"
+"Rate=%.1f,CompressRatio=%.1f,WriteStorageId=%s,LastReadStorageId=%s,StatusInfo='%s',LastReadDevice='%s',WriteDevice='%s' WHERE JobId=%s",
       (char)(jr->JobStatus), dt, jr->ClientId, edit_uint64(jr->JobBytes, ed1),
       edit_uint64(jr->ReadBytes, ed4),
       jr->JobFiles, jr->JobErrors, jr->VolSessionId, jr->VolSessionTime,
       jr->PoolId, jr->FileSetId, edit_uint64(JobTDate, ed2),
       rdt, PriorJobId, jr->HasBase, jr->PurgedFiles, jr->PriorJob,
+      jr->Rate, jr->CompressRatio, edit_uint64(jr->WriteStorageId, ed5),
+      edit_uint64(jr->LastReadStorageId, ed6), esc1, esc2, esc3,
       edit_int64(jr->JobId, ed3));
 
    stat = UpdateDB(jcr, cmd, false);