From: Eric Bollengier Date: Mon, 4 Jan 2016 10:26:38 +0000 (+0100) Subject: Add ExpiresIn field in list and llist media output X-Git-Tag: Release-7.4.0~33 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=41f0422362cc505a76e1a545bc3b64fe77498b0a;p=bacula%2Fbacula Add ExpiresIn field in list and llist media output --- diff --git a/bacula/src/cats/sql_cmds.c b/bacula/src/cats/sql_cmds.c index d80003bf25..ebd439c571 100644 --- a/bacula/src/cats/sql_cmds.c +++ b/bacula/src/cats/sql_cmds.c @@ -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'))))" +}; diff --git a/bacula/src/cats/sql_cmds.h b/bacula/src/cats/sql_cmds.h index 2c91f6f9da..1d8602b0eb 100644 --- a/bacula/src/cats/sql_cmds.h +++ b/bacula/src/cats/sql_cmds.h @@ -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[]; diff --git a/bacula/src/cats/sql_list.c b/bacula/src/cats/sql_list.c index 0171eb8519..fbba97a1fb 100644 --- a/bacula/src/cats/sql_list.c +++ b/bacula/src/cats/sql_list.c @@ -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)); } }