From 17be7838a436c9c4f0e332f0cd77a0bec17d1e84 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Thu, 20 Mar 2008 10:29:57 +0000 Subject: [PATCH] ebl Apply jobstat patch to add longterm statistics in catalog. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6650 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/cats/make_mysql_tables.in | 2 ++ bacula/src/cats/make_postgresql_tables.in | 3 +++ bacula/src/cats/make_sqlite3_tables.in | 3 +++ bacula/src/cats/make_sqlite_tables.in | 3 +++ bacula/src/cats/protos.h | 2 +- bacula/src/cats/sql_create.c | 4 +--- bacula/src/cats/sql_update.c | 10 ++++++++-- bacula/src/dird/dird_conf.c | 5 +++++ bacula/src/dird/dird_conf.h | 2 ++ bacula/src/dird/job.c | 2 +- bacula/src/dird/ua_prune.c | 7 ++++++- bacula/src/jcr.h | 1 + bacula/src/stored/bscan.c | 4 ++-- bacula/technotes-2.3 | 3 +++ 14 files changed, 41 insertions(+), 10 deletions(-) diff --git a/bacula/src/cats/make_mysql_tables.in b/bacula/src/cats/make_mysql_tables.in index cbe9f61b54..32a5b4d984 100644 --- a/bacula/src/cats/make_mysql_tables.in +++ b/bacula/src/cats/make_mysql_tables.in @@ -115,6 +115,8 @@ CREATE TABLE Job ( INDEX (Name(128)) ); +-- Create a table like Job for long term statistics +CREATE TABLE JobStat (LIKE Job); CREATE TABLE Location ( LocationId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, diff --git a/bacula/src/cats/make_postgresql_tables.in b/bacula/src/cats/make_postgresql_tables.in index 599a4a3063..d63e2de699 100644 --- a/bacula/src/cats/make_postgresql_tables.in +++ b/bacula/src/cats/make_postgresql_tables.in @@ -81,6 +81,9 @@ CREATE TABLE job CREATE INDEX job_name_idx on job (name); +-- Create a table like Job for long term statistics +CREATE TABLE jobstat (LIKE job); + CREATE TABLE Location ( LocationId serial not null, Location text not null, diff --git a/bacula/src/cats/make_sqlite3_tables.in b/bacula/src/cats/make_sqlite3_tables.in index b284fcb2c3..aea3628f6e 100644 --- a/bacula/src/cats/make_sqlite3_tables.in +++ b/bacula/src/cats/make_sqlite3_tables.in @@ -75,6 +75,9 @@ CREATE TABLE Job ( ); CREATE INDEX inx6 ON Job (Name); +-- Create a table like Job for long term statistics +CREATE TABLE JobStat (LIKE Job); + CREATE TABLE Location ( LocationId INTEGER, Location TEXT NOT NULL, diff --git a/bacula/src/cats/make_sqlite_tables.in b/bacula/src/cats/make_sqlite_tables.in index 7fdcbada56..6173a56a59 100644 --- a/bacula/src/cats/make_sqlite_tables.in +++ b/bacula/src/cats/make_sqlite_tables.in @@ -75,6 +75,9 @@ CREATE TABLE Job ( ); CREATE INDEX inx6 ON Job (Name); +-- Create a table like Job for long term statistics +CREATE TABLE JobStat (LIKE Job); + CREATE TABLE Location ( LocationId INTEGER, Location TEXT NOT NULL, diff --git a/bacula/src/cats/protos.h b/bacula/src/cats/protos.h index 2d78a3169d..2b4ecc8ed0 100644 --- a/bacula/src/cats/protos.h +++ b/bacula/src/cats/protos.h @@ -124,7 +124,7 @@ void db_list_client_records(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *sendit, void * /* sql_update.c */ bool db_update_job_start_record(JCR *jcr, B_DB *db, JOB_DBR *jr); -int db_update_job_end_record(JCR *jcr, B_DB *db, JOB_DBR *jr); +int db_update_job_end_record(JCR *jcr, B_DB *db, JOB_DBR *jr, bool stats_enabled); int db_update_client_record(JCR *jcr, B_DB *mdb, CLIENT_DBR *cr); int db_update_pool_record(JCR *jcr, B_DB *db, POOL_DBR *pr); bool db_update_storage_record(JCR *jcr, B_DB *mdb, STORAGE_DBR *sr); diff --git a/bacula/src/cats/sql_create.c b/bacula/src/cats/sql_create.c index 38268bdc98..447974b969 100644 --- a/bacula/src/cats/sql_create.c +++ b/bacula/src/cats/sql_create.c @@ -112,7 +112,7 @@ db_create_job_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr) bool db_create_jobmedia_record(JCR *jcr, B_DB *mdb, JOBMEDIA_DBR *jm) { - bool ok = true;; + bool ok = true; int count; char ed1[50], ed2[50]; @@ -162,8 +162,6 @@ db_create_jobmedia_record(JCR *jcr, B_DB *mdb, JOBMEDIA_DBR *jm) return ok; } - - /* Create Unique Pool record * Returns: false on failure * true on success diff --git a/bacula/src/cats/sql_update.c b/bacula/src/cats/sql_update.c index 5f037fba3c..161effa98d 100644 --- a/bacula/src/cats/sql_update.c +++ b/bacula/src/cats/sql_update.c @@ -142,7 +142,7 @@ static void edit_num_or_null(char *s, size_t n, uint64_t id) { * 1 on success */ int -db_update_job_end_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr) +db_update_job_end_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr, bool stats_enabled) { char dt[MAX_TIME_LENGTH]; char rdt[MAX_TIME_LENGTH]; @@ -192,11 +192,17 @@ db_update_job_end_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr) edit_int64(jr->JobId, ed3)); stat = UPDATE_DB(jcr, mdb, mdb->cmd); + + if (stat && stats_enabled) { + Mmsg(mdb->cmd, + "INSERT INTO JobStat (SELECT * FROM Job WHERE JobId=%s)", + edit_int64(jr->JobId, ed3)); + INSERT_DB(jcr, mdb, mdb->cmd); /* TODO: get a message ? */ + } db_unlock(mdb); return stat; } - /* * Update Client record * Returns: 0 on failure diff --git a/bacula/src/dird/dird_conf.c b/bacula/src/dird/dird_conf.c index 86a2e5f4d2..8e4dbea1be 100644 --- a/bacula/src/dird/dird_conf.c +++ b/bacula/src/dird/dird_conf.c @@ -133,6 +133,7 @@ static RES_ITEM dir_items[] = { {"tlskey", store_dir, ITEM(res_dir.tls_keyfile), 0, 0, 0}, {"tlsdhfile", store_dir, ITEM(res_dir.tls_dhfile), 0, 0, 0}, {"tlsallowedcn", store_alist_str, ITEM(res_dir.tls_allowed_cns), 0, 0, 0}, + {"statisticsretention", store_time, ITEM(res_dir.stats_retention), 0, ITEM_DEFAULT, 60*60*24*31*12*5}, {NULL, NULL, {0}, 0, 0, 0} }; @@ -322,6 +323,7 @@ RES_ITEM job_items[] = { {"selectionpattern", store_str, ITEM(res_job.selection_pattern), 0, 0, 0}, {"runscript", store_runscript, ITEM(res_job.RunScripts), 0, ITEM_NO_EQUALS, 0}, {"selectiontype", store_migtype, ITEM(res_job.selection_type), 0, 0, 0}, + {"usestatistics", store_bool, ITEM(res_job.stats_enabled), 0, 0, 0}, {"accurate", store_bool, ITEM(res_job.accurate), 0,0,0}, {"allowduplicatejobs", store_bool, ITEM(res_job.AllowDuplicateJobs), 0, ITEM_DEFAULT, false}, {"allowhigherduplicates", store_bool, ITEM(res_job.AllowHigherDuplicates), 0, ITEM_DEFAULT, true}, @@ -652,6 +654,9 @@ void dump_resource(int type, RES *reshdr, void sendit(void *sock, const char *fm if (res->res_job.RegexWhere) { sendit(sock, _(" --> RegexWhere=%s\n"), NPRT(res->res_job.RegexWhere)); } + if (res->res_job.stats_enabled) { + sendit(sock, _(" --> StatsEnabled=%d\n"), res->res_job.stats_enabled); + } if (res->res_job.RestoreBootstrap) { sendit(sock, _(" --> Bootstrap=%s\n"), NPRT(res->res_job.RestoreBootstrap)); } diff --git a/bacula/src/dird/dird_conf.h b/bacula/src/dird/dird_conf.h index f525562e12..f13205096d 100644 --- a/bacula/src/dird/dird_conf.h +++ b/bacula/src/dird/dird_conf.h @@ -129,6 +129,7 @@ public: bool tls_enable; /* Enable TLS */ bool tls_require; /* Require TLS */ bool tls_verify_peer; /* TLS Verify Client Certificate */ + utime_t stats_retention; /* Stats retention period in seconds */ /* Methods */ char *name() const; @@ -426,6 +427,7 @@ public: bool write_part_after_job; /* Set to write part after job in SD */ bool enabled; /* Set if job enabled */ bool OptimizeJobScheduling; /* Set if we should optimize Job scheduling */ + bool stats_enabled; /* Keep job records in a table for long term statistics */ bool accurate; /* Set if it is an accurate backup job */ bool AllowDuplicateJobs; /* Allow duplicate jobs */ bool AllowHigherDuplicates; /* Permit Higher Level */ diff --git a/bacula/src/dird/job.c b/bacula/src/dird/job.c index 3a0bd8f7f2..e394699f63 100644 --- a/bacula/src/dird/job.c +++ b/bacula/src/dird/job.c @@ -806,7 +806,7 @@ void update_job_end_record(JCR *jcr) jcr->jr.VolSessionId = jcr->VolSessionId; jcr->jr.VolSessionTime = jcr->VolSessionTime; jcr->jr.JobErrors = jcr->Errors; - if (!db_update_job_end_record(jcr, jcr->db, &jcr->jr)) { + if (!db_update_job_end_record(jcr, jcr->db, &jcr->jr, jcr->job->stats_enabled)) { Jmsg(jcr, M_WARNING, 0, _("Error updating job record. %s"), db_strerror(jcr->db)); } diff --git a/bacula/src/dird/ua_prune.c b/bacula/src/dird/ua_prune.c index 764ae2af1a..641117f690 100644 --- a/bacula/src/dird/ua_prune.c +++ b/bacula/src/dird/ua_prune.c @@ -107,6 +107,7 @@ int file_delete_handler(void *ctx, int num_fields, char **row) * prune files (from) client=xxx * prune jobs (from) client=xxx * prune volume=xxx + * prune stats */ int prunecmd(UAContext *ua, const char *cmd) { @@ -119,6 +120,7 @@ int prunecmd(UAContext *ua, const char *cmd) NT_("Files"), NT_("Jobs"), NT_("Volume"), + NT_("Stats"), NULL}; if (!open_client_db(ua)) { @@ -127,7 +129,7 @@ int prunecmd(UAContext *ua, const char *cmd) /* First search args */ kw = find_arg_keyword(ua, keywords); - if (kw < 0 || kw > 2) { + if (kw < 0 || kw > 3) { /* no args, so ask user */ kw = do_keyword_prompt(ua, _("Choose item to prune"), keywords); } @@ -162,6 +164,9 @@ int prunecmd(UAContext *ua, const char *cmd) } prune_volume(ua, &mr); return true; + case 3: /* prune stats */ + /* TODO: prune JobStat table */ + return true; default: break; } diff --git a/bacula/src/jcr.h b/bacula/src/jcr.h index 36494a89f8..4d41daa64d 100644 --- a/bacula/src/jcr.h +++ b/bacula/src/jcr.h @@ -289,6 +289,7 @@ public: bool unlink_bsr; /* Unlink bsr file created */ bool VSS; /* VSS used by FD */ bool Encrypt; /* Encryption used by FD */ + bool stats_enabled; /* Keep all job records in a table for long term statistics */ #endif /* DIRECTOR_DAEMON */ diff --git a/bacula/src/stored/bscan.c b/bacula/src/stored/bscan.c index 25b7d702d2..64640e6bb7 100644 --- a/bacula/src/stored/bscan.c +++ b/bacula/src/stored/bscan.c @@ -619,7 +619,7 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec) jr.VolSessionTime = mjcr->VolSessionTime; jr.JobTDate = (utime_t)mjcr->start_time; jr.ClientId = mjcr->ClientId; - if (!db_update_job_end_record(bjcr, db, &jr)) { + if (!db_update_job_end_record(bjcr, db, &jr, false)) { Pmsg1(0, _("Could not update job record. ERR=%s\n"), db_strerror(db)); } mjcr->read_dcr = NULL; @@ -1122,7 +1122,7 @@ static int update_job_record(B_DB *db, JOB_DBR *jr, SESSION_LABEL *elabel, return 1; } - if (!db_update_job_end_record(bjcr, db, jr)) { + if (!db_update_job_end_record(bjcr, db, jr, false)) { Pmsg2(0, _("Could not update JobId=%u record. ERR=%s\n"), jr->JobId, db_strerror(db)); free_jcr(mjcr); return 0; diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index 2500be4d73..650869d35b 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -18,10 +18,13 @@ Honor nodump flag Improved status commands for Bat Spooling/despooling status Implement ftruncate for NFS devices +Add long term statistic job table General: 20Mar08 +ebl Apply jobstat patch for long term statistics. Have to implement + purge stats command and upgrade scripts. kes Fix mtx-changer.in for broken Debian mt program. 19Mar08 kes Fix large number of JobMedia records reported by Eric Bollengier. -- 2.39.5