]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/ua_update.c
ebl add character substitution in Job/JobDefs WriteBootStrap
[bacula/bacula] / bacula / src / dird / ua_update.c
1 /*
2  *
3  *   Bacula Director -- Update command processing
4  *     Split from ua_cmds.c March 2005
5  *
6  *     Kern Sibbald, September MM
7  *
8  *   Version $Id$
9  */
10 /*
11    Copyright (C) 2000-2006 Kern Sibbald
12
13    This program is free software; you can redistribute it and/or
14    modify it under the terms of the GNU General Public License
15    version 2 as amended with additional clauses defined in the
16    file LICENSE in the main source directory.
17
18    This program is distributed in the hope that it will be useful,
19    but WITHOUT ANY WARRANTY; without even the implied warranty of
20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
21    the file LICENSE for additional details.
22
23  */
24
25 #include "bacula.h"
26 #include "dird.h"
27
28 /* Imported functions */
29 void update_slots(UAContext *ua);
30
31
32
33 /* Forward referenced functions */
34 static int update_volume(UAContext *ua);
35 static bool update_pool(UAContext *ua);
36
37 /*
38  * Update a Pool Record in the database.
39  *  It is always updated from the Resource record.
40  *
41  *    update pool=<pool-name>
42  *         updates pool from Pool resource
43  *    update media pool=<pool-name> volume=<volume-name>
44  *         changes pool info for volume
45  *    update slots [scan=...]
46  *         updates autochanger slots
47  */
48 int update_cmd(UAContext *ua, const char *cmd)
49 {
50    static const char *kw[] = {
51       NT_("media"),  /* 0 */
52       NT_("volume"), /* 1 */
53       NT_("pool"),   /* 2 */
54       NT_("slots"),  /* 3 */
55       NULL};
56
57    if (!open_db(ua)) {
58       return 1;
59    }
60
61    switch (find_arg_keyword(ua, kw)) {
62    case 0:
63    case 1:
64       update_volume(ua);
65       return 1;
66    case 2:
67       update_pool(ua);
68       return 1;
69    case 3:
70       update_slots(ua);
71       return 1;
72    default:
73       break;
74    }
75
76    start_prompt(ua, _("Update choice:\n"));
77    add_prompt(ua, _("Volume parameters"));
78    add_prompt(ua, _("Pool from resource"));
79    add_prompt(ua, _("Slots from autochanger"));
80    switch (do_prompt(ua, _("item"), _("Choose catalog item to update"), NULL, 0)) {
81    case 0:
82       update_volume(ua);
83       break;
84    case 1:
85       update_pool(ua);
86       break;
87    case 2:
88       update_slots(ua);
89       break;
90    default:
91       break;
92    }
93    return 1;
94 }
95
96 static void update_volstatus(UAContext *ua, const char *val, MEDIA_DBR *mr)
97 {
98    POOL_MEM query(PM_MESSAGE);
99    const char *kw[] = {
100       NT_("Append"),
101       NT_("Archive"),
102       NT_("Disabled"),
103       NT_("Full"),
104       NT_("Used"),
105       NT_("Cleaning"),
106       NT_("Recycle"),
107       NT_("Read-Only"),
108       NULL};
109    bool found = false;
110    int i;
111
112    for (i=0; kw[i]; i++) {
113       if (strcasecmp(val, kw[i]) == 0) {
114          found = true;
115          break;
116       }
117    }
118    if (!found) {
119       bsendmsg(ua, _("Invalid VolStatus specified: %s\n"), val);
120    } else {
121       char ed1[50];
122       bstrncpy(mr->VolStatus, kw[i], sizeof(mr->VolStatus));
123       Mmsg(query, "UPDATE Media SET VolStatus='%s' WHERE MediaId=%s",
124          mr->VolStatus, edit_int64(mr->MediaId,ed1));
125       if (!db_sql_query(ua->db, query.c_str(), NULL, NULL)) {
126          bsendmsg(ua, "%s", db_strerror(ua->db));
127       } else {
128          bsendmsg(ua, _("New Volume status is: %s\n"), mr->VolStatus);
129       }
130    }
131 }
132
133 static void update_volretention(UAContext *ua, char *val, MEDIA_DBR *mr)
134 {
135    char ed1[150], ed2[50];
136    POOL_MEM query(PM_MESSAGE);
137    if (!duration_to_utime(val, &mr->VolRetention)) {
138       bsendmsg(ua, _("Invalid retention period specified: %s\n"), val);
139       return;
140    }
141    Mmsg(query, "UPDATE Media SET VolRetention=%s WHERE MediaId=%s",
142       edit_uint64(mr->VolRetention, ed1), edit_int64(mr->MediaId,ed2));
143    if (!db_sql_query(ua->db, query.c_str(), NULL, NULL)) {
144       bsendmsg(ua, "%s", db_strerror(ua->db));
145    } else {
146       bsendmsg(ua, _("New retention period is: %s\n"),
147          edit_utime(mr->VolRetention, ed1, sizeof(ed1)));
148    }
149 }
150
151 static void update_voluseduration(UAContext *ua, char *val, MEDIA_DBR *mr)
152 {
153    char ed1[150], ed2[50];
154    POOL_MEM query(PM_MESSAGE);
155
156    if (!duration_to_utime(val, &mr->VolUseDuration)) {
157       bsendmsg(ua, _("Invalid use duration specified: %s\n"), val);
158       return;
159    }
160    Mmsg(query, "UPDATE Media SET VolUseDuration=%s WHERE MediaId=%s",
161       edit_uint64(mr->VolUseDuration, ed1), edit_int64(mr->MediaId,ed2));
162    if (!db_sql_query(ua->db, query.c_str(), NULL, NULL)) {
163       bsendmsg(ua, "%s", db_strerror(ua->db));
164    } else {
165       bsendmsg(ua, _("New use duration is: %s\n"),
166          edit_utime(mr->VolUseDuration, ed1, sizeof(ed1)));
167    }
168 }
169
170 static void update_volmaxjobs(UAContext *ua, char *val, MEDIA_DBR *mr)
171 {
172    POOL_MEM query(PM_MESSAGE);
173    char ed1[50];
174    Mmsg(query, "UPDATE Media SET MaxVolJobs=%s WHERE MediaId=%s",
175       val, edit_int64(mr->MediaId,ed1));
176    if (!db_sql_query(ua->db, query.c_str(), NULL, NULL)) {
177       bsendmsg(ua, "%s", db_strerror(ua->db));
178    } else {
179       bsendmsg(ua, _("New max jobs is: %s\n"), val);
180    }
181 }
182
183 static void update_volmaxfiles(UAContext *ua, char *val, MEDIA_DBR *mr)
184 {
185    POOL_MEM query(PM_MESSAGE);
186    char ed1[50];
187    Mmsg(query, "UPDATE Media SET MaxVolFiles=%s WHERE MediaId=%s",
188       val, edit_int64(mr->MediaId, ed1));
189    if (!db_sql_query(ua->db, query.c_str(), NULL, NULL)) {
190       bsendmsg(ua, "%s", db_strerror(ua->db));
191    } else {
192       bsendmsg(ua, _("New max files is: %s\n"), val);
193    }
194 }
195
196 static void update_volmaxbytes(UAContext *ua, char *val, MEDIA_DBR *mr)
197 {
198    uint64_t maxbytes;
199    char ed1[50], ed2[50];
200    POOL_MEM query(PM_MESSAGE);
201
202    if (!size_to_uint64(val, strlen(val), &maxbytes)) {
203       bsendmsg(ua, _("Invalid max. bytes specification: %s\n"), val);
204       return;
205    }
206    Mmsg(query, "UPDATE Media SET MaxVolBytes=%s WHERE MediaId=%s",
207       edit_uint64(maxbytes, ed1), edit_int64(mr->MediaId, ed2));
208    if (!db_sql_query(ua->db, query.c_str(), NULL, NULL)) {
209       bsendmsg(ua, "%s", db_strerror(ua->db));
210    } else {
211       bsendmsg(ua, _("New Max bytes is: %s\n"), edit_uint64(maxbytes, ed1));
212    }
213 }
214
215 static void update_volrecycle(UAContext *ua, char *val, MEDIA_DBR *mr)
216 {
217    int recycle;
218    char ed1[50];
219
220    POOL_MEM query(PM_MESSAGE);
221    if (!is_yesno(val, &recycle)) {
222       bsendmsg(ua, _("Invalid value. It must be yes or no.\n"));
223       return;
224    }
225    Mmsg(query, "UPDATE Media SET Recycle=%d WHERE MediaId=%s",
226       recycle, edit_int64(mr->MediaId, ed1));
227    if (!db_sql_query(ua->db, query.c_str(), NULL, NULL)) {
228       bsendmsg(ua, "%s", db_strerror(ua->db));
229    } else {
230       bsendmsg(ua, _("New Recycle flag is: %s\n"),
231          mr->Recycle==1?_("yes"):_("no"));
232    }
233 }
234
235 static void update_volinchanger(UAContext *ua, char *val, MEDIA_DBR *mr)
236 {
237    int InChanger;
238    char ed1[50];
239
240    POOL_MEM query(PM_MESSAGE);
241    if (!is_yesno(val, &InChanger)) {
242       bsendmsg(ua, _("Invalid value. It must be yes or no.\n"));
243       return;
244    }
245    Mmsg(query, "UPDATE Media SET InChanger=%d WHERE MediaId=%s",
246       InChanger, edit_int64(mr->MediaId, ed1));
247    if (!db_sql_query(ua->db, query.c_str(), NULL, NULL)) {
248       bsendmsg(ua, "%s", db_strerror(ua->db));
249    } else {
250       bsendmsg(ua, _("New InChanger flag is: %s\n"),
251          mr->InChanger==1?_("yes"):_("no"));
252    }
253 }
254
255
256 static void update_volslot(UAContext *ua, char *val, MEDIA_DBR *mr)
257 {
258    POOL_DBR pr;
259
260    memset(&pr, 0, sizeof(POOL_DBR));
261    pr.PoolId = mr->PoolId;
262    if (!db_get_pool_record(ua->jcr, ua->db, &pr)) {
263       bsendmsg(ua, "%s", db_strerror(ua->db));
264       return;
265    }
266    mr->Slot = atoi(val);
267    if (pr.MaxVols > 0 && mr->Slot > (int)pr.MaxVols) {
268       bsendmsg(ua, _("Invalid slot, it must be between 0 and MaxVols=%d\n"),
269          pr.MaxVols);
270       return;
271    }
272    /*
273     * Make sure to use db_update... rather than doing this directly,
274     *   so that any Slot is handled correctly.
275     */
276    if (!db_update_media_record(ua->jcr, ua->db, mr)) {
277       bsendmsg(ua, _("Error updating media record Slot: ERR=%s"), db_strerror(ua->db));
278    } else {
279       bsendmsg(ua, _("New Slot is: %d\n"), mr->Slot);
280    }
281 }
282
283 /* Modify the Pool in which this Volume is located */
284 static void update_vol_pool(UAContext *ua, char *val, MEDIA_DBR *mr, POOL_DBR *opr)
285 {
286    POOL_DBR pr;
287    POOLMEM *query;
288    char ed1[50], ed2[50];
289
290    memset(&pr, 0, sizeof(pr));
291    bstrncpy(pr.Name, val, sizeof(pr.Name));
292    if (!get_pool_dbr(ua, &pr)) {
293       return;
294    }
295    mr->PoolId = pr.PoolId;            /* set new PoolId */
296    /*
297     */
298    query = get_pool_memory(PM_MESSAGE);
299    db_lock(ua->db);
300    Mmsg(query, "UPDATE Media SET PoolId=%s WHERE MediaId=%s",
301       edit_int64(mr->PoolId, ed1),
302       edit_int64(mr->MediaId, ed2));
303    if (!db_sql_query(ua->db, query, NULL, NULL)) {
304       bsendmsg(ua, "%s", db_strerror(ua->db));
305    } else {
306       bsendmsg(ua, _("New Pool is: %s\n"), pr.Name);
307       opr->NumVols--;
308       if (!db_update_pool_record(ua->jcr, ua->db, opr)) {
309          bsendmsg(ua, "%s", db_strerror(ua->db));
310       }
311       pr.NumVols++;
312       if (!db_update_pool_record(ua->jcr, ua->db, &pr)) {
313          bsendmsg(ua, "%s", db_strerror(ua->db));
314       }
315    }
316    db_unlock(ua->db);
317    free_pool_memory(query);
318 }
319
320 /*
321  * Refresh the Volume information from the Pool record
322  */
323 static void update_vol_from_pool(UAContext *ua, MEDIA_DBR *mr)
324 {
325    POOL_DBR pr;
326
327    memset(&pr, 0, sizeof(pr));
328    pr.PoolId = mr->PoolId;
329    if (!db_get_pool_record(ua->jcr, ua->db, &pr) ||
330        !acl_access_ok(ua, Pool_ACL, pr.Name)) {
331       return;
332    }
333    set_pool_dbr_defaults_in_media_dbr(mr, &pr);
334    if (!db_update_media_defaults(ua->jcr, ua->db, mr)) {
335       bsendmsg(ua, _("Error updating Volume record: ERR=%s"), db_strerror(ua->db));
336    } else {
337       bsendmsg(ua, _("Volume defaults updated from \"%s\" Pool record.\n"),
338          pr.Name);
339    }
340 }
341
342 /*
343  * Refresh the Volume information from the Pool record
344  *   for all Volumes
345  */
346 static void update_all_vols_from_pool(UAContext *ua)
347 {
348    POOL_DBR pr;
349    MEDIA_DBR mr;
350
351    memset(&pr, 0, sizeof(pr));
352    memset(&mr, 0, sizeof(mr));
353    if (!get_pool_dbr(ua, &pr)) {
354       return;
355    }
356    set_pool_dbr_defaults_in_media_dbr(&mr, &pr);
357    mr.PoolId = pr.PoolId;
358    if (!db_update_media_defaults(ua->jcr, ua->db, &mr)) {
359       bsendmsg(ua, _("Error updating Volume records: ERR=%s"), db_strerror(ua->db));
360    } else {
361       bsendmsg(ua, _("All Volume defaults updated from Pool record.\n"));
362    }
363 }
364
365 static void update_volenabled(UAContext *ua, char *val, MEDIA_DBR *mr)
366 {
367    mr->Enabled = get_enabled(ua, val);
368    if (mr->Enabled < 0) {
369       return;
370    }
371    if (!db_update_media_record(ua->jcr, ua->db, mr)) {
372       bsendmsg(ua, _("Error updating media record Enabled: ERR=%s"), db_strerror(ua->db));
373    } else {
374       bsendmsg(ua, _("New Enabled is: %d\n"), mr->Enabled);
375    }
376 }
377
378
379
380 /*
381  * Update a media record -- allows you to change the
382  *  Volume status. E.g. if you want Bacula to stop
383  *  writing on the volume, set it to anything other
384  *  than Append.
385  */
386 static int update_volume(UAContext *ua)
387 {
388    MEDIA_DBR mr;
389    POOL_DBR pr;
390    POOLMEM *query;
391    char ed1[130];
392    bool done = false;
393    int i;
394    const char *kw[] = {
395       _("VolStatus"),                /* 0 */
396       _("VolRetention"),             /* 1 */
397       _("VolUse"),                   /* 2 */
398       _("MaxVolJobs"),               /* 3 */
399       _("MaxVolFiles"),              /* 4 */
400       _("MaxVolBytes"),              /* 5 */
401       _("Recycle"),                  /* 6 */
402       _("InChanger"),                /* 7 */
403       _("Slot"),                     /* 8 */
404       _("Pool"),                     /* 9 */
405       _("FromPool"),                 /* 10 */
406       _("AllFromPool"),              /* 11 !!! see below !!! */
407       _("Enabled"),                  /* 12 */
408       NULL };
409
410 #define AllFromPool 11               /* keep this updated with above */
411
412    for (i=0; kw[i]; i++) {
413       int j;
414       POOL_DBR pr;
415       if ((j=find_arg_with_value(ua, kw[i])) > 0) {
416          /* If all from pool don't select a media record */
417          if (i != AllFromPool && !select_media_dbr(ua, &mr)) {
418             return 0;
419          }
420          switch (i) {
421          case 0:
422             update_volstatus(ua, ua->argv[j], &mr);
423             break;
424          case 1:
425             update_volretention(ua, ua->argv[j], &mr);
426             break;
427          case 2:
428             update_voluseduration(ua, ua->argv[j], &mr);
429             break;
430          case 3:
431             update_volmaxjobs(ua, ua->argv[j], &mr);
432             break;
433          case 4:
434             update_volmaxfiles(ua, ua->argv[j], &mr);
435             break;
436          case 5:
437             update_volmaxbytes(ua, ua->argv[j], &mr);
438             break;
439          case 6:
440             update_volrecycle(ua, ua->argv[j], &mr);
441             break;
442          case 7:
443             update_volinchanger(ua, ua->argv[j], &mr);
444             break;
445          case 8:
446             update_volslot(ua, ua->argv[j], &mr);
447             break;
448          case 9:
449             memset(&pr, 0, sizeof(POOL_DBR));
450             pr.PoolId = mr.PoolId;
451             if (!db_get_pool_record(ua->jcr, ua->db, &pr)) {
452                bsendmsg(ua, "%s", db_strerror(ua->db));
453                break;
454             }
455             update_vol_pool(ua, ua->argv[j], &mr, &pr);
456             break;
457          case 10:
458             update_vol_from_pool(ua, &mr);
459             return 1;
460          case 11:
461             update_all_vols_from_pool(ua);
462             return 1;
463          case 12:
464             update_volenabled(ua, ua->argv[j], &mr);
465             break;
466          }
467          done = true;
468       }
469    }
470
471    for ( ; !done; ) {
472       start_prompt(ua, _("Parameters to modify:\n"));
473       add_prompt(ua, _("Volume Status"));              /* 0 */
474       add_prompt(ua, _("Volume Retention Period"));    /* 1 */
475       add_prompt(ua, _("Volume Use Duration"));        /* 2 */
476       add_prompt(ua, _("Maximum Volume Jobs"));        /* 3 */
477       add_prompt(ua, _("Maximum Volume Files"));       /* 4 */
478       add_prompt(ua, _("Maximum Volume Bytes"));       /* 5 */
479       add_prompt(ua, _("Recycle Flag"));               /* 6 */
480       add_prompt(ua, _("Slot"));                       /* 7 */
481       add_prompt(ua, _("InChanger Flag"));             /* 8 */
482       add_prompt(ua, _("Volume Files"));               /* 9 */
483       add_prompt(ua, _("Pool"));                       /* 10 */
484       add_prompt(ua, _("Volume from Pool"));           /* 11 */
485       add_prompt(ua, _("All Volumes from Pool"));      /* 12 */
486       add_prompt(ua, _("Enabled")),                    /* 13 */
487       add_prompt(ua, _("Done"));                       /* 14 */
488       i = do_prompt(ua, "", _("Select parameter to modify"), NULL, 0);  
489
490       /* For All Volumes from Pool and Done, we don't need a Volume record */
491       if (i != 12 && i != 14) {
492          if (!select_media_dbr(ua, &mr)) {  /* Get Volume record */
493             return 0;
494          }
495          bsendmsg(ua, _("Updating Volume \"%s\"\n"), mr.VolumeName);
496       }
497       switch (i) {
498       case 0:                         /* Volume Status */
499          /* Modify Volume Status */
500          bsendmsg(ua, _("Current Volume status is: %s\n"), mr.VolStatus);
501          start_prompt(ua, _("Possible Values are:\n"));
502          add_prompt(ua, NT_("Append")); 
503          add_prompt(ua, NT_("Archive"));
504          add_prompt(ua, NT_("Disabled"));
505          add_prompt(ua, NT_("Full"));
506          add_prompt(ua, NT_("Used"));
507          add_prompt(ua, NT_("Cleaning"));
508          if (strcmp(mr.VolStatus, NT_("Purged")) == 0) {
509             add_prompt(ua, NT_("Recycle"));
510          }
511          add_prompt(ua, NT_("Read-Only"));
512          if (do_prompt(ua, "", _("Choose new Volume Status"), ua->cmd, sizeof(mr.VolStatus)) < 0) {
513             return 1;
514          }
515          update_volstatus(ua, ua->cmd, &mr);
516          break;
517       case 1:                         /* Retention */
518          bsendmsg(ua, _("Current retention period is: %s\n"),
519             edit_utime(mr.VolRetention, ed1, sizeof(ed1)));
520          if (!get_cmd(ua, _("Enter Volume Retention period: "))) {
521             return 0;
522          }
523          update_volretention(ua, ua->cmd, &mr);
524          break;
525
526       case 2:                         /* Use Duration */
527          bsendmsg(ua, _("Current use duration is: %s\n"),
528             edit_utime(mr.VolUseDuration, ed1, sizeof(ed1)));
529          if (!get_cmd(ua, _("Enter Volume Use Duration: "))) {
530             return 0;
531          }
532          update_voluseduration(ua, ua->cmd, &mr);
533          break;
534
535       case 3:                         /* Max Jobs */
536          bsendmsg(ua, _("Current max jobs is: %u\n"), mr.MaxVolJobs);
537          if (!get_pint(ua, _("Enter new Maximum Jobs: "))) {
538             return 0;
539          }
540          update_volmaxjobs(ua, ua->cmd, &mr);
541          break;
542
543       case 4:                         /* Max Files */
544          bsendmsg(ua, _("Current max files is: %u\n"), mr.MaxVolFiles);
545          if (!get_pint(ua, _("Enter new Maximum Files: "))) {
546             return 0;
547          }
548          update_volmaxfiles(ua, ua->cmd, &mr);
549          break;
550
551       case 5:                         /* Max Bytes */
552          bsendmsg(ua, _("Current value is: %s\n"), edit_uint64(mr.MaxVolBytes, ed1));
553          if (!get_cmd(ua, _("Enter new Maximum Bytes: "))) {
554             return 0;
555          }
556          update_volmaxbytes(ua, ua->cmd, &mr);
557          break;
558
559
560       case 6:                         /* Recycle */
561          bsendmsg(ua, _("Current recycle flag is: %s\n"),
562             mr.Recycle==1?_("yes"):_("no"));
563          if (!get_yesno(ua, _("Enter new Recycle status: "))) {
564             return 0;
565          }
566          update_volrecycle(ua, ua->cmd, &mr);
567          break;
568
569       case 7:                         /* Slot */
570          bsendmsg(ua, _("Current Slot is: %d\n"), mr.Slot);
571          if (!get_pint(ua, _("Enter new Slot: "))) {
572             return 0;
573          }
574          update_volslot(ua, ua->cmd, &mr);
575          break;
576          
577       case 8:                         /* InChanger */
578          bsendmsg(ua, _("Current InChanger flag is: %d\n"), mr.InChanger);
579          if (!get_yesno(ua, _("Set InChanger flag? yes/no: "))) {
580             return 0;
581          }
582          mr.InChanger = ua->pint32_val;
583          /*
584           * Make sure to use db_update... rather than doing this directly,
585           *   so that any Slot is handled correctly.
586           */
587          if (!db_update_media_record(ua->jcr, ua->db, &mr)) {
588             bsendmsg(ua, _("Error updating media record Slot: ERR=%s"), db_strerror(ua->db));
589          } else {
590             bsendmsg(ua, _("New InChanger flag is: %d\n"), mr.InChanger);
591          }
592          break;
593
594
595       case 9:                         /* Volume Files */
596          int32_t VolFiles;
597          bsendmsg(ua, _("Warning changing Volume Files can result\n"
598                         "in loss of data on your Volume\n\n"));
599          bsendmsg(ua, _("Current Volume Files is: %u\n"), mr.VolFiles);
600          if (!get_pint(ua, _("Enter new number of Files for Volume: "))) {
601             return 0;
602          }
603          VolFiles = ua->pint32_val;
604          if (VolFiles != (int)(mr.VolFiles + 1)) {
605             bsendmsg(ua, _("Normally, you should only increase Volume Files by one!\n"));
606             if (!get_yesno(ua, _("Continue? (yes/no): ")) || ua->pint32_val == 0) {
607                break;
608             }
609          }
610          query = get_pool_memory(PM_MESSAGE);
611          Mmsg(query, "UPDATE Media SET VolFiles=%u WHERE MediaId=%s",
612             VolFiles, edit_int64(mr.MediaId, ed1));
613          if (!db_sql_query(ua->db, query, NULL, NULL)) {
614             bsendmsg(ua, "%s", db_strerror(ua->db));
615          } else {
616             bsendmsg(ua, _("New Volume Files is: %u\n"), VolFiles);
617          }
618          free_pool_memory(query);
619          break;
620
621       case 10:                        /* Volume's Pool */
622          memset(&pr, 0, sizeof(POOL_DBR));
623          pr.PoolId = mr.PoolId;
624          if (!db_get_pool_record(ua->jcr, ua->db, &pr)) {
625             bsendmsg(ua, "%s", db_strerror(ua->db));
626             return 0;
627          }
628          bsendmsg(ua, _("Current Pool is: %s\n"), pr.Name);
629          if (!get_cmd(ua, _("Enter new Pool name: "))) {
630             return 0;
631          }
632          update_vol_pool(ua, ua->cmd, &mr, &pr);
633          return 1;
634
635       case 11:
636          update_vol_from_pool(ua, &mr);
637          return 1;
638       case 12:
639          update_all_vols_from_pool(ua);
640          return 1;
641
642       case 13:
643          bsendmsg(ua, _("Current Enabled is: %d\n"), mr.Enabled);
644          if (!get_cmd(ua, _("Enter new Enabled: "))) {
645             return 0;
646          }
647          if (strcasecmp(ua->cmd, "yes") == 0 || strcasecmp(ua->cmd, "true") == 0) {
648             mr.Enabled = 1;
649          } else if (strcasecmp(ua->cmd, "no") == 0 || strcasecmp(ua->cmd, "false") == 0) {
650             mr.Enabled = 0;
651          } else if (strcasecmp(ua->cmd, "archived") == 0) { 
652             mr.Enabled = 2;
653          } else {
654             mr.Enabled = atoi(ua->cmd);
655          }
656          update_volenabled(ua, ua->cmd, &mr);
657          break;
658
659       default:                        /* Done or error */
660          bsendmsg(ua, _("Selection terminated.\n"));
661          return 1;
662       }
663    }
664    return 1;
665 }
666
667 /*
668  * Update pool record -- pull info from current POOL resource
669  */
670 static bool update_pool(UAContext *ua)
671 {
672    POOL_DBR  pr;
673    int id;
674    POOL *pool;
675    POOLMEM *query;
676    char ed1[50];
677
678    pool = get_pool_resource(ua);
679    if (!pool) {
680       return false;
681    }
682
683    memset(&pr, 0, sizeof(pr));
684    bstrncpy(pr.Name, pool->hdr.name, sizeof(pr.Name));
685    if (!get_pool_dbr(ua, &pr)) {
686       return false;
687    }
688
689    set_pooldbr_from_poolres(&pr, pool, POOL_OP_UPDATE); /* update */
690
691    id = db_update_pool_record(ua->jcr, ua->db, &pr);
692    if (id <= 0) {
693       bsendmsg(ua, _("db_update_pool_record returned %d. ERR=%s\n"),
694          id, db_strerror(ua->db));
695    }
696    query = get_pool_memory(PM_MESSAGE);
697    Mmsg(query, list_pool, edit_int64(pr.PoolId, ed1));
698    db_list_sql_query(ua->jcr, ua->db, query, prtit, ua, 1, HORZ_LIST);
699    free_pool_memory(query);
700    bsendmsg(ua, _("Pool DB record updated from resource.\n"));
701    return true;
702 }