]> git.sur5r.net Git - bacula/bacula/commitdiff
Add ExpiresIn field in list and llist media output
authorEric Bollengier <eric@baculasystems.com>
Mon, 4 Jan 2016 10:26:38 +0000 (11:26 +0100)
committerKern Sibbald <kern@sibbald.com>
Sat, 9 Jan 2016 16:42:23 +0000 (17:42 +0100)
bacula/src/cats/sql_cmds.c
bacula/src/cats/sql_cmds.h
bacula/src/cats/sql_list.c

index d80003bf25a14b617cf46288d3e591f16d04bb9c..ebd439c5719288da0276cd30efe59dce6f521656 100644 (file)
@@ -1013,3 +1013,12 @@ const char *expired_volumes[] = {
    /* SQLite */
    expired_volumes_defaults
 };
+
+const char *expires_in[] = {
+   /* MySQL */
+   "(GREATEST(0, CAST(UNIX_TIMESTAMP(LastWritten) + VolRetention AS SIGNED) - UNIX_TIMESTAMP(NOW())))",
+   /* PostgreSQL */
+   "GREATEST(0, (extract('epoch' from LastWritten + VolRetention * interval '1second' - NOW())::bigint))",
+   /* SQLite */
+   "MAX(0, (strftime('%s', LastWritten) + VolRetention - strftime('%s', datetime('now', 'localtime'))))"
+};
index 2c91f6f9dab7f4eb6841b04990533c1e2d7d2471..1d8602b0ebae264c46753c1a50acd999d052733a 100644 (file)
@@ -87,3 +87,4 @@ extern const char CATS_IMP_EXP *uar_sel_fileset;
 extern const char CATS_IMP_EXP *uar_sel_filesetid;
 extern const char CATS_IMP_EXP *uar_sel_jobid_temp;
 extern const char CATS_IMP_EXP *update_counter_values[]; 
+extern const char CATS_IMP_EXP *expires_in[];
index 0171eb8519eeeb9812a840bae1ff8933855ee23b..fbba97a1fb4d7abe88e0d83b9274c6d4588be383 100644 (file)
@@ -195,6 +195,7 @@ void BDB::bdb_list_media_records(JCR *jcr, MEDIA_DBR *mdbr,
 {
    char ed1[50];
    char esc[MAX_ESCAPE_NAME_LENGTH];
+   const char *expiresin = expires_in[bdb_get_type_index()];
 
    bdb_lock();
    bdb_escape_string(jcr, esc, mdbr->VolumeName, strlen(mdbr->VolumeName));
@@ -210,8 +211,8 @@ void BDB::bdb_list_media_records(JCR *jcr, MEDIA_DBR *mdbr,
             "EndFile,EndBlock,VolParts,LabelType,StorageId,DeviceId,"
             "MediaAddressing,VolReadTime,VolWriteTime,"
             "LocationId,RecycleCount,InitialWrite,ScratchPoolId,RecyclePoolId, "
-            "ActionOnPurge,Comment"
-            " FROM Media WHERE Media.VolumeName='%s'", esc);
+            "ActionOnPurge,%s AS ExpiresIn, Comment"
+            " FROM Media WHERE Media.VolumeName='%s'", expiresin, esc);
       } else {
          Mmsg(cmd, "SELECT MediaId,VolumeName,Slot,PoolId,"
             "MediaType,MediaTypeId,FirstWritten,LastWritten,LabelDate,VolJobs,"
@@ -222,20 +223,20 @@ void BDB::bdb_list_media_records(JCR *jcr, MEDIA_DBR *mdbr,
             "EndFile,EndBlock,VolParts,LabelType,StorageId,DeviceId,"
             "MediaAddressing,VolReadTime,VolWriteTime,"
             "LocationId,RecycleCount,InitialWrite,ScratchPoolId,RecyclePoolId, "
-            "ActionOnPurge,Comment"
+            "ActionOnPurge,%s AS ExpiresIn, Comment"
             " FROM Media WHERE Media.PoolId=%s ORDER BY MediaId",
-            edit_int64(mdbr->PoolId, ed1));
+              expiresin, edit_int64(mdbr->PoolId, ed1));
       }
    } else {
       if (mdbr->VolumeName[0] != 0) {
          Mmsg(cmd, "SELECT MediaId,VolumeName,VolStatus,Enabled,"
-            "VolBytes,VolFiles,VolRetention,Recycle,Slot,InChanger,MediaType,VolParts,LastWritten "
-            "FROM Media WHERE Media.VolumeName='%s'", esc);
+            "VolBytes,VolFiles,VolRetention,Recycle,Slot,InChanger,MediaType,LastWritten,%s AS ExpiresIn "
+              "FROM Media WHERE Media.VolumeName='%s'", expiresin, esc);
       } else {
          Mmsg(cmd, "SELECT MediaId,VolumeName,VolStatus,Enabled,"
-            "VolBytes,VolFiles,VolRetention,Recycle,Slot,InChanger,MediaType,VolParts,LastWritten "
+            "VolBytes,VolFiles,VolRetention,Recycle,Slot,InChanger,MediaType,LastWritten,%s AS ExpiresIn "
             "FROM Media WHERE Media.PoolId=%s ORDER BY MediaId",
-            edit_int64(mdbr->PoolId, ed1));
+              expiresin, edit_int64(mdbr->PoolId, ed1));
       }
    }