]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/testing/jobstat.patch
ebl Add update stats [days=xxx] command
[bacula/bacula] / bacula / patches / testing / jobstat.patch
1 Index: src/dird/ua_update.c
2 ===================================================================
3 --- src/dird/ua_update.c        (révision 7132)
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,25 @@
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 +   if (nb > 1) {
75 +      ua->info_msg(_("Updating %i jobs.\n"), nb);
76 +   }
77 +   return true;
78 +}
79 +
80 +/*
81   * Update pool record -- pull info from current POOL resource
82   */
83  static bool update_pool(UAContext *ua)
84 Index: src/cats/sql_update.c
85 ===================================================================
86 --- src/cats/sql_update.c       (révision 7132)
87 +++ src/cats/sql_update.c       (copie de travail)
88 @@ -126,6 +126,28 @@
89  }
90  
91  /*
92 + * Update Long term statistics with all jobs that were run before
93 + * age seconds
94 + */
95 +int
96 +db_update_stats(JCR *jcr, B_DB *mdb, time_t age)
97 +{
98 +   char ed1[30];
99 +   utime_t now = (utime_t)time(NULL);
100 +   edit_uint64(now - age, ed1);
101 +
102 +   Mmsg(mdb->cmd,
103 +        "INSERT INTO JobStat " 
104 +         "SELECT * " 
105 +          "FROM Job "
106 +         "WHERE JobStatus IN ('T', 'f', 'A', 'E') "
107 +           "AND JobId NOT IN (SELECT JobId FROM JobStat) "
108 +           "AND JobTDate < %s ", ed1);
109 +   INSERT_DB(jcr, mdb, mdb->cmd); /* TODO: get a message ? */
110 +   return mdb->num_rows;
111 +}
112 +
113 +/*
114   * Given an incoming integer, set the string buffer to either NULL or the value
115   *
116   */
117 @@ -134,7 +156,6 @@
118     bsnprintf(s, n, id ? "%s" : "NULL", edit_int64(id, ed1));
119  }
120  
121 -
122  /*
123   * Update the Job record at end of Job
124   *
125 @@ -292,7 +313,6 @@
126  {
127     int stat;
128     char ed1[50];
129 -
130     db_lock(mdb);
131     Mmsg(mdb->cmd, "UPDATE Storage SET AutoChanger=%d WHERE StorageId=%s", 
132        sr->AutoChanger, edit_int64(sr->StorageId, ed1));
133 Index: src/cats/protos.h
134 ===================================================================
135 --- src/cats/protos.h   (révision 7132)
136 +++ src/cats/protos.h   (copie de travail)
137 @@ -134,5 +134,6 @@
138  int  db_add_digest_to_file_record(JCR *jcr, B_DB *mdb, FileId_t FileId, char *digest, int type);
139  int  db_mark_file_record(JCR *jcr, B_DB *mdb, FileId_t FileId, JobId_t JobId);
140  void db_make_inchanger_unique(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr);
141 +int db_update_stats(JCR *jcr, B_DB *mdb, time_t age);
142  
143  #endif /* __SQL_PROTOS_H */