2 ===================================================================
3 --- src/dird/job.c (revision 6595)
4 +++ src/dird/job.c (working copy)
6 jcr->jr.VolSessionId = jcr->VolSessionId;
7 jcr->jr.VolSessionTime = jcr->VolSessionTime;
8 jcr->jr.JobErrors = jcr->Errors;
9 - if (!db_update_job_end_record(jcr, jcr->db, &jcr->jr)) {
10 + if (!db_update_job_end_record(jcr, jcr->db, &jcr->jr, jcr->job->stats_enabled)) {
11 Jmsg(jcr, M_WARNING, 0, _("Error updating job record. %s"),
12 db_strerror(jcr->db));
14 Index: src/dird/ua_prune.c
15 ===================================================================
16 --- src/dird/ua_prune.c (revision 6595)
17 +++ src/dird/ua_prune.c (working copy)
19 * prune files (from) client=xxx
20 * prune jobs (from) client=xxx
24 int prunecmd(UAContext *ua, const char *cmd)
33 if (!open_client_db(ua)) {
36 /* First search args */
37 kw = find_arg_keyword(ua, keywords);
38 - if (kw < 0 || kw > 2) {
39 + if (kw < 0 || kw > 3) {
40 /* no args, so ask user */
41 kw = do_keyword_prompt(ua, _("Choose item to prune"), keywords);
45 prune_volume(ua, &mr);
47 + case 3: /* prune stats */
48 + /* TODO: prune JobStat table */
53 Index: src/dird/dird_conf.c
54 ===================================================================
55 --- src/dird/dird_conf.c (revision 6595)
56 +++ src/dird/dird_conf.c (working copy)
58 {"tlskey", store_dir, ITEM(res_dir.tls_keyfile), 0, 0, 0},
59 {"tlsdhfile", store_dir, ITEM(res_dir.tls_dhfile), 0, 0, 0},
60 {"tlsallowedcn", store_alist_str, ITEM(res_dir.tls_allowed_cns), 0, 0, 0},
61 + {"statisticsretention", store_time, ITEM(res_dir.stats_retention), 0, ITEM_DEFAULT, 60*60*24*31*12*5},
62 {NULL, NULL, {0}, 0, 0, 0}
66 {"selectionpattern", store_str, ITEM(res_job.selection_pattern), 0, 0, 0},
67 {"runscript", store_runscript, ITEM(res_job.RunScripts), 0, ITEM_NO_EQUALS, 0},
68 {"selectiontype", store_migtype, ITEM(res_job.selection_type), 0, 0, 0},
69 + {"usestatistics", store_bool, ITEM(res_job.stats_enabled), 0, 0, 0},
70 {"accurate", store_bool, ITEM(res_job.accurate), 0,0,0},
71 {"allowduplicatejobs", store_bool, ITEM(res_job.AllowDuplicateJobs), 0, ITEM_DEFAULT, false},
72 {"allowhigherduplicates", store_bool, ITEM(res_job.AllowHigherDuplicates), 0, ITEM_DEFAULT, true},
74 if (res->res_job.RegexWhere) {
75 sendit(sock, _(" --> RegexWhere=%s\n"), NPRT(res->res_job.RegexWhere));
77 + if (res->res_job.stats_enabled) {
78 + sendit(sock, _(" --> StatsEnabled=%d\n"), res->res_job.stats_enabled);
80 if (res->res_job.RestoreBootstrap) {
81 sendit(sock, _(" --> Bootstrap=%s\n"), NPRT(res->res_job.RestoreBootstrap));
83 Index: src/dird/dird_conf.h
84 ===================================================================
85 --- src/dird/dird_conf.h (revision 6595)
86 +++ src/dird/dird_conf.h (working copy)
88 bool tls_enable; /* Enable TLS */
89 bool tls_require; /* Require TLS */
90 bool tls_verify_peer; /* TLS Verify Client Certificate */
91 + utime_t stats_retention; /* Stats retention period in seconds */
96 bool write_part_after_job; /* Set to write part after job in SD */
97 bool enabled; /* Set if job enabled */
98 bool OptimizeJobScheduling; /* Set if we should optimize Job scheduling */
99 + bool stats_enabled; /* Keep job records in a table for long term statistics */
100 bool accurate; /* Set if it is an accurate backup job */
101 bool AllowDuplicateJobs; /* Allow duplicate jobs */
102 bool AllowHigherDuplicates; /* Permit Higher Level */
103 Index: src/cats/sql_update.c
104 ===================================================================
105 --- src/cats/sql_update.c (revision 6595)
106 +++ src/cats/sql_update.c (working copy)
111 -db_update_job_end_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr)
112 +db_update_job_end_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr, bool stats_enabled)
114 char dt[MAX_TIME_LENGTH];
115 char rdt[MAX_TIME_LENGTH];
116 @@ -192,11 +192,17 @@
117 edit_int64(jr->JobId, ed3));
119 stat = UPDATE_DB(jcr, mdb, mdb->cmd);
121 + if (stat && stats_enabled) {
123 + "INSERT INTO JobStat (SELECT * FROM Job WHERE JobId=%s)",
124 + edit_int64(jr->JobId, ed3));
125 + INSERT_DB(jcr, mdb, mdb->cmd); /* TODO: get a message ? */
133 * Update Client record
134 * Returns: 0 on failure
135 Index: src/cats/make_sqlite3_tables.in
136 ===================================================================
137 --- src/cats/make_sqlite3_tables.in (revision 6595)
138 +++ src/cats/make_sqlite3_tables.in (working copy)
141 CREATE INDEX inx6 ON Job (Name);
143 +-- Create a table like Job for long term statistics
144 +CREATE TABLE JobStat (LIKE Job);
146 CREATE TABLE Location (
148 Location TEXT NOT NULL,
149 Index: src/cats/make_postgresql_tables.in
150 ===================================================================
151 --- src/cats/make_postgresql_tables.in (revision 6595)
152 +++ src/cats/make_postgresql_tables.in (working copy)
155 CREATE INDEX job_name_idx on job (name);
157 +-- Create a table like Job for long term statistics
158 +CREATE TABLE jobstat (LIKE job);
160 CREATE TABLE Location (
161 LocationId serial not null,
162 Location text not null,
163 Index: src/cats/protos.h
164 ===================================================================
165 --- src/cats/protos.h (revision 6595)
166 +++ src/cats/protos.h (working copy)
170 bool db_update_job_start_record(JCR *jcr, B_DB *db, JOB_DBR *jr);
171 -int db_update_job_end_record(JCR *jcr, B_DB *db, JOB_DBR *jr);
172 +int db_update_job_end_record(JCR *jcr, B_DB *db, JOB_DBR *jr, bool stats_enabled);
173 int db_update_client_record(JCR *jcr, B_DB *mdb, CLIENT_DBR *cr);
174 int db_update_pool_record(JCR *jcr, B_DB *db, POOL_DBR *pr);
175 bool db_update_storage_record(JCR *jcr, B_DB *mdb, STORAGE_DBR *sr);
176 Index: src/cats/make_sqlite_tables.in
177 ===================================================================
178 --- src/cats/make_sqlite_tables.in (revision 6595)
179 +++ src/cats/make_sqlite_tables.in (working copy)
182 CREATE INDEX inx6 ON Job (Name);
184 +-- Create a table like Job for long term statistics
185 +CREATE TABLE JobStat (LIKE Job);
187 CREATE TABLE Location (
189 Location TEXT NOT NULL,
190 Index: src/cats/sql_create.c
191 ===================================================================
192 --- src/cats/sql_create.c (revision 6595)
193 +++ src/cats/sql_create.c (working copy)
196 db_create_jobmedia_record(JCR *jcr, B_DB *mdb, JOBMEDIA_DBR *jm)
201 char ed1[50], ed2[50];
209 /* Create Unique Pool record
210 * Returns: false on failure
212 Index: src/cats/make_mysql_tables.in
213 ===================================================================
214 --- src/cats/make_mysql_tables.in (revision 6595)
215 +++ src/cats/make_mysql_tables.in (working copy)
220 +-- Create a table like Job for long term statistics
221 +CREATE TABLE JobStat (LIKE Job);
223 CREATE TABLE Location (
224 LocationId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
225 Index: src/stored/bscan.c
226 ===================================================================
227 --- src/stored/bscan.c (revision 6595)
228 +++ src/stored/bscan.c (working copy)
230 jr.VolSessionTime = mjcr->VolSessionTime;
231 jr.JobTDate = (utime_t)mjcr->start_time;
232 jr.ClientId = mjcr->ClientId;
233 - if (!db_update_job_end_record(bjcr, db, &jr)) {
234 + if (!db_update_job_end_record(bjcr, db, &jr, false)) {
235 Pmsg1(0, _("Could not update job record. ERR=%s\n"), db_strerror(db));
237 mjcr->read_dcr = NULL;
238 @@ -1122,7 +1122,7 @@
242 - if (!db_update_job_end_record(bjcr, db, jr)) {
243 + if (!db_update_job_end_record(bjcr, db, jr, false)) {
244 Pmsg2(0, _("Could not update JobId=%u record. ERR=%s\n"), jr->JobId, db_strerror(db));
248 ===================================================================
249 --- src/jcr.h (revision 6595)
250 +++ src/jcr.h (working copy)
252 bool unlink_bsr; /* Unlink bsr file created */
253 bool VSS; /* VSS used by FD */
254 bool Encrypt; /* Encryption used by FD */
255 + bool stats_enabled; /* Keep all job records in a table for long term statistics */
256 #endif /* DIRECTOR_DAEMON */