]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/testing/jobstat.patch
ebl Add fix to avoid to expect the EndJob message with some
[bacula/bacula] / bacula / patches / testing / jobstat.patch
1 Index: src/dird/ua_update.c
2 ===================================================================
3 --- src/dird/ua_update.c        (révision 7144)
4 +++ src/dird/ua_update.c        (copie de travail)
5 @@ -42,6 +42,7 @@
6  static int update_volume(UAContext *ua);
7  static bool update_pool(UAContext *ua);
8  static bool update_job(UAContext *ua);
9 +static bool update_stats(UAContext *ua);
10  
11  /*
12   * Update a Pool Record in the database.
13 @@ -53,6 +54,8 @@
14   *         changes pool info for volume
15   *    update slots [scan=...]
16   *         updates autochanger slots
17 + *    update stats [days=...]
18 + *         updates long term statistics
19   */
20  int update_cmd(UAContext *ua, const char *cmd)
21  {
22 @@ -62,6 +65,7 @@
23        NT_("pool"),   /* 2 */
24        NT_("slots"),  /* 3 */
25        NT_("jobid"),  /* 4 */
26 +      NT_("stats"),  /* 5 */
27        NULL};
28  
29     if (!open_client_db(ua)) {
30 @@ -82,6 +86,9 @@
31     case 4:
32        update_job(ua);
33        return 1;
34 +   case 5:
35 +      update_stats(ua);
36 +      return 1;
37     default:
38        break;
39     }
40 @@ -90,6 +97,7 @@
41     add_prompt(ua, _("Volume parameters"));
42     add_prompt(ua, _("Pool from resource"));
43     add_prompt(ua, _("Slots from autochanger"));
44 +   add_prompt(ua, _("Long term statistics"));
45     switch (do_prompt(ua, _("item"), _("Choose catalog item to update"), NULL, 0)) {
46     case 0:
47        update_volume(ua);
48 @@ -100,6 +108,9 @@
49     case 2:
50        update_slots(ua);
51        break;
52 +   case 3:
53 +      update_stats(ua);
54 +      break;
55     default:
56        break;
57     }
58 @@ -789,6 +800,24 @@
59  }
60  
61  /*
62 + * Update long term statistics
63 + */
64 +static bool update_stats(UAContext *ua)
65 +{
66 +   int i = find_arg_with_value(ua, NT_("days"));
67 +   utime_t since=0;
68 +
69 +   if (i >= 0) {
70 +      since = atoi(ua->argv[i]) * 24*60*60;
71 +   }
72 +
73 +   int nb = db_update_stats(ua->jcr, ua->db, since);
74 +   ua->info_msg(_("Updating %i job(s).\n"), nb);
75 +
76 +   return true;
77 +}
78 +
79 +/*
80   * Update pool record -- pull info from current POOL resource
81   */
82  static bool update_pool(UAContext *ua)
83 Index: src/cats/sql_update.c
84 ===================================================================
85 --- src/cats/sql_update.c       (révision 7144)
86 +++ src/cats/sql_update.c       (copie de travail)
87 @@ -126,6 +126,28 @@
88  }
89  
90  /*
91 + * Update Long term statistics with all jobs that were run before
92 + * age seconds
93 + */
94 +int
95 +db_update_stats(JCR *jcr, B_DB *mdb, time_t age)
96 +{
97 +   char ed1[30];
98 +   utime_t now = (utime_t)time(NULL);
99 +   edit_uint64(now - age, ed1);
100 +
101 +   Mmsg(mdb->cmd,
102 +        "INSERT INTO JobStat " 
103 +         "SELECT * " 
104 +          "FROM Job "
105 +         "WHERE JobStatus IN ('T', 'f', 'A', 'E') "
106 +           "AND JobId NOT IN (SELECT JobId FROM JobStat) "
107 +           "AND JobTDate < %s ", ed1);
108 +   QUERY_DB(jcr, mdb, mdb->cmd); /* TODO: get a message ? */
109 +   return sql_affected_rows(mdb);
110 +}
111 +
112 +/*
113   * Given an incoming integer, set the string buffer to either NULL or the value
114   *
115   */
116 @@ -134,7 +156,6 @@
117     bsnprintf(s, n, id ? "%s" : "NULL", edit_int64(id, ed1));
118  }
119  
120 -
121  /*
122   * Update the Job record at end of Job
123   *
124 @@ -292,7 +313,6 @@
125  {
126     int stat;
127     char ed1[50];
128 -
129     db_lock(mdb);
130     Mmsg(mdb->cmd, "UPDATE Storage SET AutoChanger=%d WHERE StorageId=%s", 
131        sr->AutoChanger, edit_int64(sr->StorageId, ed1));
132 Index: src/cats/protos.h
133 ===================================================================
134 --- src/cats/protos.h   (révision 7144)
135 +++ src/cats/protos.h   (copie de travail)
136 @@ -134,5 +134,6 @@
137  int  db_add_digest_to_file_record(JCR *jcr, B_DB *mdb, FileId_t FileId, char *digest, int type);
138  int  db_mark_file_record(JCR *jcr, B_DB *mdb, FileId_t FileId, JobId_t JobId);
139  void db_make_inchanger_unique(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr);
140 +int db_update_stats(JCR *jcr, B_DB *mdb, time_t age);
141  
142  #endif /* __SQL_PROTOS_H */