]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/testing/jobstat.patch
ebl add new hash lib test code
[bacula/bacula] / bacula / patches / testing / jobstat.patch
1 Index: src/dird/job.c
2 ===================================================================
3 --- src/dird/job.c      (revision 6595)
4 +++ src/dird/job.c      (working copy)
5 @@ -806,7 +806,7 @@
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));
13     }
14 Index: src/dird/ua_prune.c
15 ===================================================================
16 --- src/dird/ua_prune.c (revision 6595)
17 +++ src/dird/ua_prune.c (working copy)
18 @@ -107,6 +107,7 @@
19   *    prune files (from) client=xxx
20   *    prune jobs (from) client=xxx
21   *    prune volume=xxx
22 + *    prune stats
23   */
24  int prunecmd(UAContext *ua, const char *cmd)
25  {
26 @@ -119,6 +120,7 @@
27        NT_("Files"),
28        NT_("Jobs"),
29        NT_("Volume"),
30 +      NT_("Stats"),
31        NULL};
32  
33     if (!open_client_db(ua)) {
34 @@ -127,7 +129,7 @@
35  
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);
42     }
43 @@ -162,6 +164,9 @@
44        }
45        prune_volume(ua, &mr);
46        return true;
47 +   case 3:  /* prune stats */
48 +      /* TODO: prune JobStat table */
49 +      return true;
50     default:
51        break;
52     }
53 Index: src/dird/dird_conf.c
54 ===================================================================
55 --- src/dird/dird_conf.c        (revision 6595)
56 +++ src/dird/dird_conf.c        (working copy)
57 @@ -133,6 +133,7 @@
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}
63  };
64  
65 @@ -322,6 +323,7 @@
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},
73 @@ -652,6 +654,9 @@
74        if (res->res_job.RegexWhere) {
75             sendit(sock, _("  --> RegexWhere=%s\n"), NPRT(res->res_job.RegexWhere));
76        }
77 +      if (res->res_job.stats_enabled) {
78 +           sendit(sock, _("  --> StatsEnabled=%d\n"), res->res_job.stats_enabled);
79 +      }
80        if (res->res_job.RestoreBootstrap) {
81           sendit(sock, _("  --> Bootstrap=%s\n"), NPRT(res->res_job.RestoreBootstrap));
82        }
83 Index: src/dird/dird_conf.h
84 ===================================================================
85 --- src/dird/dird_conf.h        (revision 6595)
86 +++ src/dird/dird_conf.h        (working copy)
87 @@ -129,6 +129,7 @@
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 */
92  
93     /* Methods */
94     char *name() const;
95 @@ -426,6 +427,7 @@
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)
107 @@ -142,7 +142,7 @@
108   *           1 on success
109   */
110  int
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)
113  {
114     char dt[MAX_TIME_LENGTH];
115     char rdt[MAX_TIME_LENGTH];
116 @@ -192,11 +192,17 @@
117        edit_int64(jr->JobId, ed3));
118  
119     stat = UPDATE_DB(jcr, mdb, mdb->cmd);
120 +
121 +   if (stat && stats_enabled) {
122 +      Mmsg(mdb->cmd,
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 ? */
126 +   }
127     db_unlock(mdb);
128     return stat;
129  }
130  
131 -
132  /*
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)
139 @@ -75,6 +75,9 @@
140     );
141  CREATE INDEX inx6 ON Job (Name);
142  
143 +-- Create a table like Job for long term statistics 
144 +CREATE TABLE JobStat (LIKE Job);
145 +
146  CREATE TABLE Location (
147     LocationId INTEGER,
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)
153 @@ -81,6 +81,9 @@
154  
155  CREATE INDEX job_name_idx on job (name);
156  
157 +-- Create a table like Job for long term statistics 
158 +CREATE TABLE jobstat (LIKE job);
159 +
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)
167 @@ -124,7 +124,7 @@
168  
169  /* sql_update.c */
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)
180 @@ -75,6 +75,9 @@
181     );
182  CREATE INDEX inx6 ON Job (Name);
183  
184 +-- Create a table like Job for long term statistics 
185 +CREATE TABLE JobStat (LIKE Job);
186 +
187  CREATE TABLE Location (
188     LocationId INTEGER,
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)
194 @@ -112,7 +112,7 @@
195  bool
196  db_create_jobmedia_record(JCR *jcr, B_DB *mdb, JOBMEDIA_DBR *jm)
197  {
198 -   bool ok = true;;
199 +   bool ok = true;
200     int count;
201     char ed1[50], ed2[50];
202  
203 @@ -162,8 +162,6 @@
204     return ok;
205  }
206  
207 -
208 -
209  /* Create Unique Pool record
210   * Returns: false on failure
211   *          true  on success
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)
216 @@ -115,6 +115,8 @@
217     INDEX (Name(128))
218     );
219  
220 +-- Create a table like Job for long term statistics 
221 +CREATE TABLE JobStat (LIKE Job);
222  
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)
229 @@ -619,7 +619,7 @@
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));
236                 }
237                 mjcr->read_dcr = NULL;
238 @@ -1122,7 +1122,7 @@
239        return 1;
240     }
241  
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));
245        free_jcr(mjcr);
246        return 0;
247 Index: src/jcr.h
248 ===================================================================
249 --- src/jcr.h   (revision 6595)
250 +++ src/jcr.h   (working copy)
251 @@ -289,6 +289,7 @@
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 */
257  
258