3 * Bacula Director -- User Agent Commands
5 * Kern Sibbald, September MM
11 Copyright (C) 2000-2004 Kern Sibbald and John Walker
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of
16 the License, or (at your option) any later version.
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 GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public
24 License along with this program; if not, write to the Free
25 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
33 /* Imported subroutines */
35 /* Imported variables */
38 extern struct s_res resources[];
39 extern char my_name[];
40 extern jobq_t job_queue; /* job queue */
43 extern char *list_pool;
45 /* Imported functions */
46 extern int status_cmd(UAContext *ua, const char *cmd);
47 extern int list_cmd(UAContext *ua, const char *cmd);
48 extern int llist_cmd(UAContext *ua, const char *cmd);
49 extern int show_cmd(UAContext *ua, const char *cmd);
50 extern int messagescmd(UAContext *ua, const char *cmd);
51 extern int autodisplay_cmd(UAContext *ua, const char *cmd);
52 extern int gui_cmd(UAContext *ua, const char *cmd);
53 extern int sqlquerycmd(UAContext *ua, const char *cmd);
54 extern int querycmd(UAContext *ua, const char *cmd);
55 extern int run_cmd(UAContext *ua, const char *cmd);
56 extern int retentioncmd(UAContext *ua, const char *cmd);
57 extern int prunecmd(UAContext *ua, const char *cmd);
58 extern int purgecmd(UAContext *ua, const char *cmd);
59 extern int restore_cmd(UAContext *ua, const char *cmd);
60 extern int label_cmd(UAContext *ua, const char *cmd);
61 extern int relabel_cmd(UAContext *ua, const char *cmd);
62 extern int update_slots(UAContext *ua); /* ua_label.c */
64 /* Forward referenced functions */
65 static int add_cmd(UAContext *ua, const char *cmd);
66 static int create_cmd(UAContext *ua, const char *cmd);
67 static int cancel_cmd(UAContext *ua, const char *cmd);
68 static int setdebug_cmd(UAContext *ua, const char *cmd);
69 static int trace_cmd(UAContext *ua, const char *cmd);
70 static int var_cmd(UAContext *ua, const char *cmd);
71 static int estimate_cmd(UAContext *ua, const char *cmd);
72 static int help_cmd(UAContext *ua, const char *cmd);
73 static int delete_cmd(UAContext *ua, const char *cmd);
74 static int use_cmd(UAContext *ua, const char *cmd);
75 static int unmount_cmd(UAContext *ua, const char *cmd);
76 static int version_cmd(UAContext *ua, const char *cmd);
77 static int automount_cmd(UAContext *ua, const char *cmd);
78 static int time_cmd(UAContext *ua, const char *cmd);
79 static int reload_cmd(UAContext *ua, const char *cmd);
80 static int update_volume(UAContext *ua);
81 static int update_pool(UAContext *ua);
82 static int delete_volume(UAContext *ua);
83 static int delete_pool(UAContext *ua);
84 static int delete_job(UAContext *ua);
85 static int mount_cmd(UAContext *ua, const char *cmd);
86 static int release_cmd(UAContext *ua, const char *cmd);
87 static int update_cmd(UAContext *ua, const char *cmd);
88 static int wait_cmd(UAContext *ua, const char *cmd);
89 static int setip_cmd(UAContext *ua, const char *cmd);
91 int quit_cmd(UAContext *ua, const char *cmd);
94 struct cmdstruct { const char *key; int (*func)(UAContext *ua, const char *cmd); const char *help; };
95 static struct cmdstruct commands[] = {
96 { N_("add"), add_cmd, _("add media to a pool")},
97 { N_("autodisplay"), autodisplay_cmd, _("autodisplay [on/off] -- console messages")},
98 { N_("automount"), automount_cmd, _("automount [on/off] -- after label")},
99 { N_("cancel"), cancel_cmd, _("cancel job=nnn -- cancel a job")},
100 { N_("create"), create_cmd, _("create DB Pool from resource")},
101 { N_("delete"), delete_cmd, _("delete [pool=<pool-name> | media volume=<volume-name>]")},
102 { N_("estimate"), estimate_cmd, _("performs FileSet estimate, listing gives full listing")},
103 { N_("exit"), quit_cmd, _("exit = quit")},
104 { N_("gui"), gui_cmd, _("gui [on/off] -- non-interactive gui mode")},
105 { N_("help"), help_cmd, _("print this command")},
106 { N_("list"), list_cmd, _("list [pools | jobs | jobtotals | media <pool> | files jobid=<nn>]; from catalog")},
107 { N_("label"), label_cmd, _("label a tape")},
108 { N_("llist"), llist_cmd, _("full or long list like list command")},
109 { N_("messages"), messagescmd, _("messages")},
110 { N_("mount"), mount_cmd, _("mount <storage-name>")},
111 { N_("prune"), prunecmd, _("prune expired records from catalog")},
112 { N_("purge"), purgecmd, _("purge records from catalog")},
113 { N_("quit"), quit_cmd, _("quit")},
114 { N_("query"), querycmd, _("query catalog")},
115 { N_("restore"), restore_cmd, _("restore files")},
116 { N_("relabel"), relabel_cmd, _("relabel a tape")},
117 { N_("release"), release_cmd, _("release <storage-name>")},
118 { N_("reload"), reload_cmd, _("reload conf file")},
119 { N_("run"), run_cmd, _("run <job-name>")},
120 { N_("status"), status_cmd, _("status [storage | client]=<name>")},
121 { N_("setdebug"), setdebug_cmd, _("sets debug level")},
122 { N_("setip"), setip_cmd, _("sets new client address -- if authorized")},
123 { N_("show"), show_cmd, _("show (resource records) [jobs | pools | ... | all]")},
124 { N_("sqlquery"), sqlquerycmd, _("use SQL to query catalog")},
125 { N_("time"), time_cmd, _("print current time")},
126 { N_("trace"), trace_cmd, _("turn on/off trace to file")},
127 { N_("unmount"), unmount_cmd, _("unmount <storage-name>")},
128 { N_("update"), update_cmd, _("update Volume or Pool")},
129 { N_("use"), use_cmd, _("use catalog xxx")},
130 { N_("var"), var_cmd, _("does variable expansion")},
131 { N_("version"), version_cmd, _("print Director version")},
132 { N_("wait"), wait_cmd, _("wait until no jobs are running")},
134 #define comsize (sizeof(commands)/sizeof(struct cmdstruct))
137 * Execute a command from the UA
139 int do_a_command(UAContext *ua, const char *cmd)
147 Dmsg1(200, "Command: %s\n", ua->UA_sock->msg);
152 len = strlen(ua->argk[0]);
153 for (i=0; i<comsize; i++) { /* search for command */
154 if (strncasecmp(ua->argk[0], _(commands[i].key), len) == 0) {
155 if (!acl_access_ok(ua, Command_ACL, ua->argk[0], len)) {
158 stat = (*commands[i].func)(ua, cmd); /* go execute command */
164 bnet_fsend(ua->UA_sock, _("%s: is an illegal command.\n"), ua->argk[0]);
170 * This is a common routine used to stuff the Pool DB record defaults
171 * into the Media DB record just before creating a media (Volume)
174 void set_pool_dbr_defaults_in_media_dbr(MEDIA_DBR *mr, POOL_DBR *pr)
176 mr->PoolId = pr->PoolId;
177 bstrncpy(mr->VolStatus, "Append", sizeof(mr->VolStatus));
178 mr->Recycle = pr->Recycle;
179 mr->VolRetention = pr->VolRetention;
180 mr->VolUseDuration = pr->VolUseDuration;
181 mr->MaxVolJobs = pr->MaxVolJobs;
182 mr->MaxVolFiles = pr->MaxVolFiles;
183 mr->MaxVolBytes = pr->MaxVolBytes;
188 * Add Volumes to an existing Pool
190 static int add_cmd(UAContext *ua, const char *cmd)
194 int num, i, max, startnum;
196 char name[MAX_NAME_LENGTH];
198 int Slot = 0, InChanger = 0;
201 "You probably don't want to be using this command since it\n"
202 "creates database records without labeling the Volumes.\n"
203 "You probably want to use the \"label\" command.\n\n"));
209 memset(&pr, 0, sizeof(pr));
210 memset(&mr, 0, sizeof(mr));
212 if (!get_pool_dbr(ua, &pr)) {
216 Dmsg4(120, "id=%d Num=%d Max=%d type=%s\n", pr.PoolId, pr.NumVols,
217 pr.MaxVols, pr.PoolType);
219 while (pr.MaxVols > 0 && pr.NumVols >= pr.MaxVols) {
220 bsendmsg(ua, _("Pool already has maximum volumes = %d\n"), pr.MaxVols);
222 if (!get_pint(ua, _("Enter new maximum (zero for unlimited): "))) {
225 pr.MaxVols = ua->pint32_val;
230 if ((store = get_storage_resource(ua, 0)) != NULL) {
231 bstrncpy(mr.MediaType, store->media_type, sizeof(mr.MediaType));
232 } else if (!get_media_type(ua, mr.MediaType, sizeof(mr.MediaType))) {
236 if (pr.MaxVols == 0) {
239 max = pr.MaxVols - pr.NumVols;
243 bsnprintf(buf, sizeof(buf), _("Enter number of Volumes to create. 0=>fixed name. Max=%d: "), max);
244 if (!get_pint(ua, buf)) {
247 num = ua->pint32_val;
248 if (num < 0 || num > max) {
249 bsendmsg(ua, _("The number must be between 0 and %d\n"), max);
256 if (!get_cmd(ua, _("Enter Volume name: "))) {
260 if (!get_cmd(ua, _("Enter base volume name: "))) {
264 /* Don't allow | in Volume name because it is the volume separator character */
265 if (!is_volume_name_legal(ua, ua->cmd)) {
268 if (strlen(ua->cmd) >= MAX_NAME_LENGTH-10) {
269 bsendmsg(ua, _("Volume name too long.\n"));
272 if (strlen(ua->cmd) == 0) {
273 bsendmsg(ua, _("Volume name must be at least one character long.\n"));
277 bstrncpy(name, ua->cmd, sizeof(name));
279 strcat(name, "%04d");
282 if (!get_pint(ua, _("Enter the starting number: "))) {
285 startnum = ua->pint32_val;
287 bsendmsg(ua, _("Start number must be greater than zero.\n"));
297 if (store && store->autochanger) {
298 if (!get_pint(ua, _("Enter slot (0 for none): "))) {
301 Slot = ua->pint32_val;
302 if (!get_yesno(ua, _("InChanger? yes/no: "))) {
305 InChanger = ua->pint32_val;
308 set_pool_dbr_defaults_in_media_dbr(&mr, &pr);
309 for (i=startnum; i < num+startnum; i++) {
310 bsnprintf(mr.VolumeName, sizeof(mr.VolumeName), name, i);
312 mr.InChanger = InChanger;
313 Dmsg1(200, "Create Volume %s\n", mr.VolumeName);
314 if (!db_create_media_record(ua->jcr, ua->db, &mr)) {
315 bsendmsg(ua, db_strerror(ua->db));
319 first_id = mr.PoolId;
323 Dmsg0(200, "Update pool record.\n");
324 if (db_update_pool_record(ua->jcr, ua->db, &pr) != 1) {
325 bsendmsg(ua, db_strerror(ua->db));
328 bsendmsg(ua, _("%d Volumes created in pool %s\n"), num, pr.Name);
334 * Turn auto mount on/off
339 int automount_cmd(UAContext *ua, const char *cmd)
344 if (!get_cmd(ua, _("Turn on or off? "))) {
352 ua->automount = (strcasecmp(onoff, _("off")) == 0) ? 0 : 1;
360 static int cancel_cmd(UAContext *ua, const char *cmd)
365 char JobName[MAX_NAME_LENGTH];
371 for (i=1; i<ua->argc; i++) {
372 if (strcasecmp(ua->argk[i], _("jobid")) == 0) {
377 JobId = str_to_int64(ua->argv[i]);
378 if (!(jcr=get_jcr_by_id(JobId))) {
379 bsendmsg(ua, _("JobId %d is not running.\n"), JobId);
383 } else if (strcasecmp(ua->argk[i], _("job")) == 0) {
387 if (!(jcr=get_jcr_by_partial_name(ua->argv[i]))) {
388 bsendmsg(ua, _("Job %s is not running.\n"), ua->argv[i]);
394 /* If we still do not have a jcr,
395 * throw up a list and ask the user to select one.
398 /* Count Jobs running */
401 if (jcr->JobId == 0) { /* this is us */
402 free_locked_jcr(jcr);
405 free_locked_jcr(jcr);
411 bsendmsg(ua, _("No Jobs running.\n"));
414 start_prompt(ua, _("Select Job:\n"));
417 if (jcr->JobId == 0) { /* this is us */
418 free_locked_jcr(jcr);
421 add_prompt(ua, jcr->Job);
422 free_locked_jcr(jcr);
426 if (do_prompt(ua, _("Job"), _("Choose Job to cancel"), JobName, sizeof(JobName)) < 0) {
430 if (!get_yesno(ua, _("Confirm cancel (yes/no): ")) || ua->pint32_val == 0) {
434 /* NOTE! This increments the ref_count */
435 jcr = get_jcr_by_full_name(JobName);
437 bsendmsg(ua, _("Job %s not found.\n"), JobName);
442 ret = cancel_job(ua, jcr);
449 * This is a common routine to create or update a
450 * Pool DB base record from a Pool Resource. We handle
451 * the setting of MaxVols and NumVols slightly differently
452 * depending on if we are creating the Pool or we are
453 * simply bringing it into agreement with the resource (updage).
455 static void set_pooldbr_from_poolres(POOL_DBR *pr, POOL *pool, e_pool_op op)
457 strcpy(pr->PoolType, pool->pool_type);
458 if (op == POOL_OP_CREATE) {
459 pr->MaxVols = pool->max_volumes;
461 } else { /* update pool */
462 if (pr->MaxVols != pool->max_volumes) {
463 pr->MaxVols = pool->max_volumes;
465 if (pr->MaxVols != 0 && pr->MaxVols < pr->NumVols) {
466 pr->MaxVols = pr->NumVols;
469 pr->UseOnce = pool->use_volume_once;
470 pr->UseCatalog = pool->use_catalog;
471 pr->AcceptAnyVolume = pool->accept_any_volume;
472 pr->Recycle = pool->Recycle;
473 pr->VolRetention = pool->VolRetention;
474 pr->VolUseDuration = pool->VolUseDuration;
475 pr->MaxVolJobs = pool->MaxVolJobs;
476 pr->MaxVolFiles = pool->MaxVolFiles;
477 pr->MaxVolBytes = pool->MaxVolBytes;
478 pr->AutoPrune = pool->AutoPrune;
479 pr->Recycle = pool->Recycle;
480 if (pool->label_format) {
481 strcpy(pr->LabelFormat, pool->label_format);
483 strcpy(pr->LabelFormat, "*"); /* none */
489 * Create a pool record from a given Pool resource
490 * Also called from backup.c
491 * Returns: -1 on error
492 * 0 record already exists
496 int create_pool(JCR *jcr, B_DB *db, POOL *pool, e_pool_op op)
500 memset(&pr, 0, sizeof(POOL_DBR));
502 strcpy(pr.Name, pool->hdr.name);
504 if (db_get_pool_record(jcr, db, &pr)) {
506 if (op == POOL_OP_UPDATE) { /* update request */
507 set_pooldbr_from_poolres(&pr, pool, op);
508 db_update_pool_record(jcr, db, &pr);
510 return 0; /* exists */
513 set_pooldbr_from_poolres(&pr, pool, op);
515 if (!db_create_pool_record(jcr, db, &pr)) {
516 return -1; /* error */
524 * Create a Pool Record in the database.
525 * It is always created from the Resource record.
527 static int create_cmd(UAContext *ua, const char *cmd)
535 pool = get_pool_resource(ua);
540 switch (create_pool(ua->jcr, ua->db, pool, POOL_OP_CREATE)) {
542 bsendmsg(ua, _("Error: Pool %s already exists.\n"
543 "Use update to change it.\n"), pool->hdr.name);
547 bsendmsg(ua, db_strerror(ua->db));
553 bsendmsg(ua, _("Pool %s created.\n"), pool->hdr.name);
559 * Set a new address in a Client resource. We do this only
560 * if the Console name is the same as the Client name
561 * and the Console can access the client.
563 static int setip_cmd(UAContext *ua, const char *cmd)
566 if (!ua->cons || !acl_access_ok(ua, Client_ACL, ua->cons->hdr.name)) {
567 bsendmsg(ua, _("Illegal command from this console.\n"));
571 client = (CLIENT *)GetResWithName(R_CLIENT, ua->cons->hdr.name);
574 bsendmsg(ua, _("Client \"%s\" not found.\n"), ua->cons->hdr.name);
577 if (client->address) {
578 free(client->address);
580 client->address = bstrdup(inet_ntoa(ua->UA_sock->client_addr.sin_addr));
581 bsendmsg(ua, _("Client \"%s\" address set to %s\n"),
582 client->hdr.name, client->address);
590 * Update a Pool Record in the database.
591 * It is always updated from the Resource record.
593 * update pool=<pool-name>
594 * updates pool from Pool resource
595 * update media pool=<pool-name> volume=<volume-name>
596 * changes pool info for volume
597 * update slots [scan=...]
598 * updates autochanger slots
600 static int update_cmd(UAContext *ua, const char *cmd)
602 static const char *kw[] = {
604 N_("volume"), /* 1 */
613 switch (find_arg_keyword(ua, kw)) {
628 start_prompt(ua, _("Update choice:\n"));
629 add_prompt(ua, _("Volume parameters"));
630 add_prompt(ua, _("Pool from resource"));
631 add_prompt(ua, _("Slots from autochanger"));
632 switch (do_prompt(ua, _("item"), _("Choose catalog item to update"), NULL, 0)) {
648 static void update_volstatus(UAContext *ua, const char *val, MEDIA_DBR *mr)
650 POOLMEM *query = get_pool_memory(PM_MESSAGE);
664 for (i=0; kw[i]; i++) {
665 if (strcasecmp(val, kw[i]) == 0) {
671 bsendmsg(ua, _("Invalid VolStatus specified: %s\n"), val);
673 bstrncpy(mr->VolStatus, kw[i], sizeof(mr->VolStatus));
674 Mmsg(&query, "UPDATE Media SET VolStatus='%s' WHERE MediaId=%u",
675 mr->VolStatus, mr->MediaId);
676 if (!db_sql_query(ua->db, query, NULL, NULL)) {
677 bsendmsg(ua, "%s", db_strerror(ua->db));
679 bsendmsg(ua, _("New Volume status is: %s\n"), mr->VolStatus);
682 free_pool_memory(query);
685 static void update_volretention(UAContext *ua, char *val, MEDIA_DBR *mr)
689 if (!duration_to_utime(val, &mr->VolRetention)) {
690 bsendmsg(ua, _("Invalid retention period specified: %s\n"), val);
693 query = get_pool_memory(PM_MESSAGE);
694 Mmsg(&query, "UPDATE Media SET VolRetention=%s WHERE MediaId=%u",
695 edit_uint64(mr->VolRetention, ed1), mr->MediaId);
696 if (!db_sql_query(ua->db, query, NULL, NULL)) {
697 bsendmsg(ua, "%s", db_strerror(ua->db));
699 bsendmsg(ua, _("New retention seconds is: %s\n"),
700 edit_utime(mr->VolRetention, ed1));
702 free_pool_memory(query);
705 static void update_voluseduration(UAContext *ua, char *val, MEDIA_DBR *mr)
710 if (!duration_to_utime(val, &mr->VolUseDuration)) {
711 bsendmsg(ua, _("Invalid use duration specified: %s\n"), val);
714 query = get_pool_memory(PM_MESSAGE);
715 Mmsg(&query, "UPDATE Media SET VolUseDuration=%s WHERE MediaId=%u",
716 edit_uint64(mr->VolUseDuration, ed1), mr->MediaId);
717 if (!db_sql_query(ua->db, query, NULL, NULL)) {
718 bsendmsg(ua, "%s", db_strerror(ua->db));
720 bsendmsg(ua, _("New use duration is: %s\n"),
721 edit_utime(mr->VolUseDuration, ed1));
723 free_pool_memory(query);
726 static void update_volmaxjobs(UAContext *ua, char *val, MEDIA_DBR *mr)
728 POOLMEM *query = get_pool_memory(PM_MESSAGE);
729 Mmsg(&query, "UPDATE Media SET MaxVolJobs=%s WHERE MediaId=%u",
731 if (!db_sql_query(ua->db, query, NULL, NULL)) {
732 bsendmsg(ua, "%s", db_strerror(ua->db));
734 bsendmsg(ua, _("New max jobs is: %s\n"), val);
736 free_pool_memory(query);
739 static void update_volmaxfiles(UAContext *ua, char *val, MEDIA_DBR *mr)
741 POOLMEM *query = get_pool_memory(PM_MESSAGE);
742 Mmsg(&query, "UPDATE Media SET MaxVolFiles=%s WHERE MediaId=%u",
744 if (!db_sql_query(ua->db, query, NULL, NULL)) {
745 bsendmsg(ua, "%s", db_strerror(ua->db));
747 bsendmsg(ua, _("New max files is: %s\n"), val);
749 free_pool_memory(query);
752 static void update_volmaxbytes(UAContext *ua, char *val, MEDIA_DBR *mr)
758 if (!size_to_uint64(val, strlen(val), &maxbytes)) {
759 bsendmsg(ua, _("Invalid max. bytes specification: %s\n"), val);
762 query = get_pool_memory(PM_MESSAGE);
763 Mmsg(&query, "UPDATE Media SET MaxVolBytes=%s WHERE MediaId=%u",
764 edit_uint64(maxbytes, ed1), mr->MediaId);
765 if (!db_sql_query(ua->db, query, NULL, NULL)) {
766 bsendmsg(ua, "%s", db_strerror(ua->db));
768 bsendmsg(ua, _("New Max bytes is: %s\n"), edit_uint64(maxbytes, ed1));
770 free_pool_memory(query);
773 static void update_volrecycle(UAContext *ua, char *val, MEDIA_DBR *mr)
777 if (strcasecmp(val, _("yes")) == 0) {
779 } else if (strcasecmp(val, _("no")) == 0) {
782 bsendmsg(ua, _("Invalid value. It must by yes or no.\n"));
785 query = get_pool_memory(PM_MESSAGE);
786 Mmsg(&query, "UPDATE Media SET Recycle=%d WHERE MediaId=%u",
787 recycle, mr->MediaId);
788 if (!db_sql_query(ua->db, query, NULL, NULL)) {
789 bsendmsg(ua, "%s", db_strerror(ua->db));
791 bsendmsg(ua, _("New Recycle flag is: %s\n"),
792 mr->Recycle==1?_("yes"):_("no"));
794 free_pool_memory(query);
797 /* Modify the Pool in which this Volume is located */
798 static void update_volpool(UAContext *ua, char *val, MEDIA_DBR *mr)
803 memset(&pr, 0, sizeof(pr));
804 bstrncpy(pr.Name, val, sizeof(pr.Name));
805 if (!get_pool_dbr(ua, &pr)) {
808 mr->PoolId = pr.PoolId; /* set new PoolId */
811 query = get_pool_memory(PM_MESSAGE);
813 Mmsg(&query, "UPDATE Media SET PoolId=%d WHERE MediaId=%u",
814 mr->PoolId, mr->MediaId);
815 if (!db_sql_query(ua->db, query, NULL, NULL)) {
816 bsendmsg(ua, "%s", db_strerror(ua->db));
818 bsendmsg(ua, _("New Pool is: %s\n"), pr.Name);
820 db_make_inchanger_unique(ua->jcr, ua->db, mr);
822 free_pool_memory(query);
825 static void update_volfrompool(UAContext *ua, MEDIA_DBR *mr)
830 memset(&pr, 0, sizeof(pr));
831 pr.PoolId = mr->PoolId;
832 if (!get_pool_dbr(ua, &pr)) {
835 bstrncpy(VolStatus, mr->VolStatus, sizeof(VolStatus));
836 set_pool_dbr_defaults_in_media_dbr(mr, &pr);
837 bstrncpy(mr->VolStatus, VolStatus, sizeof(mr->VolStatus));
838 if (!db_update_media_record(ua->jcr, ua->db, mr)) {
839 bsendmsg(ua, _("Error updating Volume record: ERR=%s"), db_strerror(ua->db));
841 bsendmsg(ua, _("Volume defaults updated from Pool record.\n"));
846 * Update a media record -- allows you to change the
847 * Volume status. E.g. if you want Bacula to stop
848 * writing on the volume, set it to anything other
851 static int update_volume(UAContext *ua)
859 N_("VolStatus"), /* 0 */
860 N_("VolRetention"), /* 1 */
861 N_("VolUse"), /* 2 */
862 N_("MaxVolJobs"), /* 3 */
863 N_("MaxVolFiles"), /* 4 */
864 N_("MaxVolBytes"), /* 5 */
865 N_("Recycle"), /* 6 */
867 N_("FromPool"), /* 8 */
870 for (int i=0; kw[i]; i++) {
872 if ((j=find_arg_with_value(ua, kw[i])) > 0) {
873 if (!select_media_dbr(ua, &mr)) {
878 update_volstatus(ua, ua->argv[j], &mr);
881 update_volretention(ua, ua->argv[j], &mr);
884 update_voluseduration(ua, ua->argv[j], &mr);
887 update_volmaxjobs(ua, ua->argv[j], &mr);
890 update_volmaxfiles(ua, ua->argv[j], &mr);
893 update_volmaxbytes(ua, ua->argv[j], &mr);
896 update_volrecycle(ua, ua->argv[j], &mr);
899 update_volpool(ua, ua->argv[j], &mr);
902 update_volfrompool(ua, &mr);
910 if (!select_media_dbr(ua, &mr)) {
913 bsendmsg(ua, _("Updating Volume \"%s\"\n"), mr.VolumeName);
914 start_prompt(ua, _("Parameters to modify:\n"));
915 add_prompt(ua, _("Volume Status"));
916 add_prompt(ua, _("Volume Retention Period"));
917 add_prompt(ua, _("Volume Use Duration"));
918 add_prompt(ua, _("Maximum Volume Jobs"));
919 add_prompt(ua, _("Maximum Volume Files"));
920 add_prompt(ua, _("Maximum Volume Bytes"));
921 add_prompt(ua, _("Recycle Flag"));
922 add_prompt(ua, _("Slot"));
923 add_prompt(ua, _("InChanger Flag"));
924 add_prompt(ua, _("Volume Files"));
925 add_prompt(ua, _("Pool"));
926 add_prompt(ua, _("Done"));
927 switch (do_prompt(ua, "", _("Select parameter to modify"), NULL, 0)) {
928 case 0: /* Volume Status */
929 /* Modify Volume Status */
930 bsendmsg(ua, _("Current Volume status is: %s\n"), mr.VolStatus);
931 start_prompt(ua, _("Possible Values are:\n"));
932 add_prompt(ua, "Append"); /* Better not translate these as */
933 add_prompt(ua, "Archive"); /* They are known in the database code */
934 add_prompt(ua, "Disabled");
935 add_prompt(ua, "Full");
936 add_prompt(ua, "Used");
937 add_prompt(ua, "Cleaning");
938 if (strcmp(mr.VolStatus, "Purged") == 0) {
939 add_prompt(ua, "Recycle");
941 add_prompt(ua, "Read-Only");
942 if (do_prompt(ua, "", _("Choose new Volume Status"), ua->cmd, sizeof(mr.VolStatus)) < 0) {
945 update_volstatus(ua, ua->cmd, &mr);
947 case 1: /* Retention */
948 bsendmsg(ua, _("Current retention seconds is: %s\n"),
949 edit_utime(mr.VolRetention, ed1));
950 if (!get_cmd(ua, _("Enter Volume Retention period: "))) {
953 update_volretention(ua, ua->cmd, &mr);
956 case 2: /* Use Duration */
957 bsendmsg(ua, _("Current use duration is: %s\n"),
958 edit_utime(mr.VolUseDuration, ed1));
959 if (!get_cmd(ua, _("Enter Volume Use Duration: "))) {
962 update_voluseduration(ua, ua->cmd, &mr);
965 case 3: /* Max Jobs */
966 bsendmsg(ua, _("Current max jobs is: %u\n"), mr.MaxVolJobs);
967 if (!get_pint(ua, _("Enter new Maximum Jobs: "))) {
970 update_volmaxjobs(ua, ua->cmd, &mr);
973 case 4: /* Max Files */
974 bsendmsg(ua, _("Current max files is: %u\n"), mr.MaxVolFiles);
975 if (!get_pint(ua, _("Enter new Maximum Files: "))) {
978 update_volmaxfiles(ua, ua->cmd, &mr);
981 case 5: /* Max Bytes */
982 bsendmsg(ua, _("Current value is: %s\n"), edit_uint64(mr.MaxVolBytes, ed1));
983 if (!get_cmd(ua, _("Enter new Maximum Bytes: "))) {
986 update_volmaxbytes(ua, ua->cmd, &mr);
990 case 6: /* Recycle */
991 bsendmsg(ua, _("Current recycle flag is: %s\n"),
992 mr.Recycle==1?_("yes"):_("no"));
993 if (!get_yesno(ua, _("Enter new Recycle status: "))) {
996 update_volrecycle(ua, ua->cmd, &mr);
1002 memset(&pr, 0, sizeof(POOL_DBR));
1003 pr.PoolId = mr.PoolId;
1004 if (!db_get_pool_record(ua->jcr, ua->db, &pr)) {
1005 bsendmsg(ua, "%s", db_strerror(ua->db));
1008 bsendmsg(ua, _("Current Slot is: %d\n"), mr.Slot);
1009 if (!get_pint(ua, _("Enter new Slot: "))) {
1012 Slot = ua->pint32_val;
1013 if (pr.MaxVols > 0 && Slot > (int)pr.MaxVols) {
1014 bsendmsg(ua, _("Invalid slot, it must be between 0 and %d\n"),
1020 * Make sure to use db_update... rather than doing this directly,
1021 * so that any Slot is handled correctly.
1023 if (!db_update_media_record(ua->jcr, ua->db, &mr)) {
1024 bsendmsg(ua, _("Error updating media record Slot: ERR=%s"), db_strerror(ua->db));
1026 bsendmsg(ua, _("New Slot is: %d\n"), mr.Slot);
1030 case 8: /* InChanger */
1031 bsendmsg(ua, _("Current InChanger flag is: %d\n"), mr.InChanger);
1032 if (!get_yesno(ua, _("Set InChanger flag? yes/no: "))) {
1035 mr.InChanger = ua->pint32_val;
1037 * Make sure to use db_update... rather than doing this directly,
1038 * so that any Slot is handled correctly.
1040 if (!db_update_media_record(ua->jcr, ua->db, &mr)) {
1041 bsendmsg(ua, _("Error updating media record Slot: ERR=%s"), db_strerror(ua->db));
1043 bsendmsg(ua, _("New InChanger flag is: %d\n"), mr.InChanger);
1048 case 9: /* Volume Files */
1050 bsendmsg(ua, _("Warning changing Volume Files can result\n"
1051 "in loss of data on your Volume\n\n"));
1052 bsendmsg(ua, _("Current Volume Files is: %u\n"), mr.VolFiles);
1053 if (!get_pint(ua, _("Enter new number of Files for Volume: "))) {
1056 VolFiles = ua->pint32_val;
1057 if (VolFiles != (int)(mr.VolFiles + 1)) {
1058 bsendmsg(ua, _("Normally, you should only increase Volume Files by one!\n"));
1059 if (!get_yesno(ua, _("Continue? (yes/no): ")) || ua->pint32_val == 0) {
1063 query = get_pool_memory(PM_MESSAGE);
1064 Mmsg(&query, "UPDATE Media SET VolFiles=%u WHERE MediaId=%u",
1065 VolFiles, mr.MediaId);
1066 if (!db_sql_query(ua->db, query, NULL, NULL)) {
1067 bsendmsg(ua, "%s", db_strerror(ua->db));
1069 bsendmsg(ua, _("New Volume Files is: %u\n"), VolFiles);
1071 free_pool_memory(query);
1074 case 10: /* Volume's Pool */
1075 memset(&pr, 0, sizeof(POOL_DBR));
1076 pr.PoolId = mr.PoolId;
1077 if (!db_get_pool_record(ua->jcr, ua->db, &pr)) {
1078 bsendmsg(ua, "%s", db_strerror(ua->db));
1081 bsendmsg(ua, _("Current Pool is: %s\n"), pr.Name);
1082 if (!get_cmd(ua, _("Enter new Pool name: "))) {
1085 update_volpool(ua, ua->cmd, &mr);
1088 default: /* Done or error */
1089 bsendmsg(ua, "Selection done.\n");
1097 * Update pool record -- pull info from current POOL resource
1099 static int update_pool(UAContext *ua)
1106 pool = get_pool_resource(ua);
1111 memset(&pr, 0, sizeof(pr));
1112 strcpy(pr.Name, pool->hdr.name);
1113 if (!get_pool_dbr(ua, &pr)) {
1117 set_pooldbr_from_poolres(&pr, pool, POOL_OP_UPDATE); /* update */
1119 id = db_update_pool_record(ua->jcr, ua->db, &pr);
1121 bsendmsg(ua, _("db_update_pool_record returned %d. ERR=%s\n"),
1122 id, db_strerror(ua->db));
1124 query = get_pool_memory(PM_MESSAGE);
1125 Mmsg(&query, list_pool, pr.PoolId);
1126 db_list_sql_query(ua->jcr, ua->db, query, prtit, ua, 1, HORZ_LIST);
1127 free_pool_memory(query);
1128 bsendmsg(ua, _("Pool DB record updated from resource.\n"));
1133 static void do_storage_setdebug(UAContext *ua, STORE *store, int level, int trace_flag)
1137 ua->jcr->store = store;
1138 /* Try connecting for up to 15 seconds */
1139 bsendmsg(ua, _("Connecting to Storage daemon %s at %s:%d\n"),
1140 store->hdr.name, store->address, store->SDport);
1141 if (!connect_to_storage_daemon(ua->jcr, 1, 15, 0)) {
1142 bsendmsg(ua, _("Failed to connect to Storage daemon.\n"));
1145 Dmsg0(120, _("Connected to storage daemon\n"));
1146 sd = ua->jcr->store_bsock;
1147 bnet_fsend(sd, "setdebug=%d trace=%d\n", level, trace_flag);
1148 if (bnet_recv(sd) >= 0) {
1149 bsendmsg(ua, "%s", sd->msg);
1151 bnet_sig(sd, BNET_TERMINATE);
1153 ua->jcr->store_bsock = NULL;
1157 static void do_client_setdebug(UAContext *ua, CLIENT *client, int level, int trace_flag)
1161 /* Connect to File daemon */
1163 ua->jcr->client = client;
1164 /* Try to connect for 15 seconds */
1165 bsendmsg(ua, _("Connecting to Client %s at %s:%d\n"),
1166 client->hdr.name, client->address, client->FDport);
1167 if (!connect_to_file_daemon(ua->jcr, 1, 15, 0)) {
1168 bsendmsg(ua, _("Failed to connect to Client.\n"));
1171 Dmsg0(120, "Connected to file daemon\n");
1172 fd = ua->jcr->file_bsock;
1173 bnet_fsend(fd, "setdebug=%d trace=%d\n", level, trace_flag);
1174 if (bnet_recv(fd) >= 0) {
1175 bsendmsg(ua, "%s", fd->msg);
1177 bnet_sig(fd, BNET_TERMINATE);
1179 ua->jcr->file_bsock = NULL;
1184 static void do_all_setdebug(UAContext *ua, int level, int trace_flag)
1186 STORE *store, **unique_store;
1187 CLIENT *client, **unique_client;
1191 debug_level = level;
1193 /* Count Storage items */
1196 for (i=0; (store = (STORE *)GetNextRes(R_STORAGE, (RES *)store)); i++)
1198 unique_store = (STORE **) malloc(i * sizeof(STORE));
1199 /* Find Unique Storage address/port */
1200 store = (STORE *)GetNextRes(R_STORAGE, NULL);
1202 unique_store[i++] = store;
1203 while ((store = (STORE *)GetNextRes(R_STORAGE, (RES *)store))) {
1205 for (j=0; j<i; j++) {
1206 if (strcmp(unique_store[j]->address, store->address) == 0 &&
1207 unique_store[j]->SDport == store->SDport) {
1213 unique_store[i++] = store;
1214 Dmsg2(140, "Stuffing: %s:%d\n", store->address, store->SDport);
1219 /* Call each unique Storage daemon */
1220 for (j=0; j<i; j++) {
1221 do_storage_setdebug(ua, unique_store[j], level, trace_flag);
1225 /* Count Client items */
1228 for (i=0; (client = (CLIENT *)GetNextRes(R_CLIENT, (RES *)client)); i++)
1230 unique_client = (CLIENT **) malloc(i * sizeof(CLIENT));
1231 /* Find Unique Client address/port */
1232 client = (CLIENT *)GetNextRes(R_CLIENT, NULL);
1234 unique_client[i++] = client;
1235 while ((client = (CLIENT *)GetNextRes(R_CLIENT, (RES *)client))) {
1237 for (j=0; j<i; j++) {
1238 if (strcmp(unique_client[j]->address, client->address) == 0 &&
1239 unique_client[j]->FDport == client->FDport) {
1245 unique_client[i++] = client;
1246 Dmsg2(140, "Stuffing: %s:%d\n", client->address, client->FDport);
1251 /* Call each unique File daemon */
1252 for (j=0; j<i; j++) {
1253 do_client_setdebug(ua, unique_client[j], level, trace_flag);
1255 free(unique_client);
1259 * setdebug level=nn all trace=1/0
1261 static int setdebug_cmd(UAContext *ua, const char *cmd)
1266 int trace_flag = -1;
1272 Dmsg1(120, "setdebug:%s:\n", cmd);
1275 i = find_arg_with_value(ua, _("level"));
1277 level = atoi(ua->argv[i]);
1280 if (!get_pint(ua, _("Enter new debug level: "))) {
1283 level = ua->pint32_val;
1286 /* Look for trace flag. -1 => not change */
1287 i = find_arg_with_value(ua, _("trace"));
1289 trace_flag = atoi(ua->argv[i]);
1290 if (trace_flag > 0) {
1295 /* General debug? */
1296 for (i=1; i<ua->argc; i++) {
1297 if (strcasecmp(ua->argk[i], _("all")) == 0) {
1298 do_all_setdebug(ua, level, trace_flag);
1301 if (strcasecmp(ua->argk[i], _("dir")) == 0 ||
1302 strcasecmp(ua->argk[i], _("director")) == 0) {
1303 debug_level = level;
1304 set_trace(trace_flag);
1307 if (strcasecmp(ua->argk[i], _("client")) == 0 ||
1308 strcasecmp(ua->argk[i], _("fd")) == 0) {
1311 client = (CLIENT *)GetResWithName(R_CLIENT, ua->argv[i]);
1313 do_client_setdebug(ua, client, level, trace_flag);
1317 client = select_client_resource(ua);
1319 do_client_setdebug(ua, client, level, trace_flag);
1324 if (strcasecmp(ua->argk[i], _("store")) == 0 ||
1325 strcasecmp(ua->argk[i], _("storage")) == 0 ||
1326 strcasecmp(ua->argk[i], _("sd")) == 0) {
1329 store = (STORE *)GetResWithName(R_STORAGE, ua->argv[i]);
1331 do_storage_setdebug(ua, store, level, trace_flag);
1335 store = get_storage_resource(ua, 0);
1337 do_storage_setdebug(ua, store, level, trace_flag);
1343 * We didn't find an appropriate keyword above, so
1346 start_prompt(ua, _("Available daemons are: \n"));
1347 add_prompt(ua, _("Director"));
1348 add_prompt(ua, _("Storage"));
1349 add_prompt(ua, _("Client"));
1350 add_prompt(ua, _("All"));
1351 switch(do_prompt(ua, "", _("Select daemon type to set debug level"), NULL, 0)) {
1352 case 0: /* Director */
1353 debug_level = level;
1354 set_trace(trace_flag);
1357 store = get_storage_resource(ua, 0);
1359 do_storage_setdebug(ua, store, level, trace_flag);
1363 client = select_client_resource(ua);
1365 do_client_setdebug(ua, client, level, trace_flag);
1369 do_all_setdebug(ua, level, trace_flag);
1378 * Turn debug tracing to file on/off
1380 static int trace_cmd(UAContext *ua, const char *cmd)
1384 if (ua->argc != 2) {
1385 if (!get_cmd(ua, _("Turn on or off? "))) {
1390 onoff = ua->argk[1];
1393 set_trace((strcasecmp(onoff, _("off")) == 0) ? false : true);
1398 static int var_cmd(UAContext *ua, const char *cmd)
1400 POOLMEM *val = get_pool_memory(PM_FNAME);
1406 for (var=ua->cmd; *var != ' '; ) { /* skip command */
1409 while (*var == ' ') { /* skip spaces */
1412 Dmsg1(100, "Var=%s:\n", var);
1413 variable_expansion(ua->jcr, var, &val);
1414 bsendmsg(ua, "%s\n", val);
1415 free_pool_memory(val);
1419 static int estimate_cmd(UAContext *ua, const char *cmd)
1422 CLIENT *client = NULL;
1423 FILESET *fileset = NULL;
1426 char since[MAXSTRING];
1428 for (int i=1; i<ua->argc; i++) {
1429 if (strcasecmp(ua->argk[i], _("client")) == 0 ||
1430 strcasecmp(ua->argk[i], _("fd")) == 0) {
1432 client = (CLIENT *)GetResWithName(R_CLIENT, ua->argv[i]);
1436 if (strcasecmp(ua->argk[i], _("job")) == 0) {
1438 job = (JOB *)GetResWithName(R_JOB, ua->argv[i]);
1442 if (strcasecmp(ua->argk[i], _("fileset")) == 0) {
1444 fileset = (FILESET *)GetResWithName(R_FILESET, ua->argv[i]);
1448 if (strcasecmp(ua->argk[i], _("listing")) == 0) {
1452 if (!job && !(client && fileset)) {
1453 if (!(job = select_job_resource(ua))) {
1458 job = (JOB *)GetResWithName(R_JOB, ua->argk[1]);
1461 client = job->client;
1464 fileset = job->fileset;
1466 ua->jcr->client = client;
1467 ua->jcr->fileset = fileset;
1469 ua->catalog = client->catalog;
1475 get_level_since_time(ua->jcr, since, sizeof(since));
1477 bsendmsg(ua, _("Connecting to Client %s at %s:%d\n"),
1478 job->client->hdr.name, job->client->address, job->client->FDport);
1479 if (!connect_to_file_daemon(ua->jcr, 1, 15, 0)) {
1480 bsendmsg(ua, _("Failed to connect to Client.\n"));
1483 fd = ua->jcr->file_bsock;
1485 if (!send_include_list(ua->jcr)) {
1486 bsendmsg(ua, _("Error sending include list.\n"));
1490 if (!send_exclude_list(ua->jcr)) {
1491 bsendmsg(ua, _("Error sending exclude list.\n"));
1495 if (!send_level_command(ua->jcr)) {
1499 bnet_fsend(fd, "estimate listing=%d\n", listing);
1500 while (bnet_recv(fd) >= 0) {
1501 bsendmsg(ua, "%s", fd->msg);
1504 bnet_sig(fd, BNET_TERMINATE);
1506 ua->jcr->file_bsock = NULL;
1515 static int time_cmd(UAContext *ua, const char *cmd)
1518 time_t ttime = time(NULL);
1520 localtime_r(&ttime, &tm);
1521 strftime(sdt, sizeof(sdt), "%d-%b-%Y %H:%M:%S", &tm);
1522 bsendmsg(ua, "%s\n", sdt);
1527 * reload the conf file
1529 extern void reload_config(int sig);
1531 static int reload_cmd(UAContext *ua, const char *cmd)
1540 * Delete Pool records (should purge Media with it).
1542 * delete pool=<pool-name>
1543 * delete volume pool=<pool-name> volume=<name>
1544 * delete job jobid=xxx
1546 static int delete_cmd(UAContext *ua, const char *cmd)
1548 static const char *keywords[] = {
1559 switch (find_arg_keyword(ua, keywords)) {
1569 while ((i=find_arg(ua, _("jobid"))) > 0) {
1571 *ua->argk[i] = 0; /* zap keyword already visited */
1579 "In general it is not a good idea to delete either a\n"
1580 "Pool or a Volume since they may contain data.\n\n"));
1582 switch (do_keyword_prompt(ua, _("Choose catalog item to delete"), keywords)) {
1593 bsendmsg(ua, _("Nothing done.\n"));
1599 static int delete_job(UAContext *ua)
1601 POOLMEM *query = get_pool_memory(PM_MESSAGE);
1604 int i = find_arg_with_value(ua, _("jobid"));
1606 JobId = str_to_int64(ua->argv[i]);
1607 } else if (!get_pint(ua, _("Enter JobId to delete: "))) {
1610 JobId = ua->pint32_val;
1612 Mmsg(&query, "DELETE FROM Job WHERE JobId=%u", JobId);
1613 db_sql_query(ua->db, query, NULL, (void *)NULL);
1614 Mmsg(&query, "DELETE FROM File WHERE JobId=%u", JobId);
1615 db_sql_query(ua->db, query, NULL, (void *)NULL);
1616 Mmsg(&query, "DELETE FROM JobMedia WHERE JobId=%u", JobId);
1617 db_sql_query(ua->db, query, NULL, (void *)NULL);
1618 free_pool_memory(query);
1619 bsendmsg(ua, _("Job %u and associated records deleted from the catalog.\n"), JobId);
1624 * Delete media records from database -- dangerous
1626 static int delete_volume(UAContext *ua)
1630 if (!select_media_dbr(ua, &mr)) {
1633 bsendmsg(ua, _("\nThis command will delete volume %s\n"
1634 "and all Jobs saved on that volume from the Catalog\n"),
1637 if (!get_yesno(ua, _("Are you sure you want to delete this Volume? (yes/no): "))) {
1640 if (ua->pint32_val) {
1641 db_delete_media_record(ua->jcr, ua->db, &mr);
1647 * Delete a pool record from the database -- dangerous
1649 static int delete_pool(UAContext *ua)
1653 memset(&pr, 0, sizeof(pr));
1655 if (!get_pool_dbr(ua, &pr)) {
1658 if (!get_yesno(ua, _("Are you sure you want to delete this Pool? (yes/no): "))) {
1661 if (ua->pint32_val) {
1662 db_delete_pool_record(ua->jcr, ua->db, &pr);
1668 static void do_mount_cmd(UAContext *ua, const char *command)
1672 char dev_name[MAX_NAME_LENGTH];
1678 Dmsg2(120, "%s: %s\n", command, ua->UA_sock->msg);
1680 store = get_storage_resource(ua, 1);
1685 Dmsg2(120, "Found storage, MediaType=%s DevName=%s\n",
1686 store->media_type, store->dev_name);
1688 ua->jcr->store = store;
1689 if (!connect_to_storage_daemon(ua->jcr, 10, SDConnectTimeout, 1)) {
1690 bsendmsg(ua, _("Failed to connect to Storage daemon.\n"));
1693 sd = ua->jcr->store_bsock;
1694 strcpy(dev_name, store->dev_name);
1695 bash_spaces(dev_name);
1696 bnet_fsend(sd, "%s %s", command, dev_name);
1697 while (bnet_recv(sd) >= 0) {
1698 bsendmsg(ua, "%s", sd->msg);
1700 bnet_sig(sd, BNET_TERMINATE);
1702 ua->jcr->store_bsock = NULL;
1706 * mount [storage | device] <name>
1708 static int mount_cmd(UAContext *ua, const char *cmd)
1710 do_mount_cmd(ua, "mount"); /* mount */
1716 * unmount [storage | device] <name>
1718 static int unmount_cmd(UAContext *ua, const char *cmd)
1720 do_mount_cmd(ua, "unmount"); /* unmount */
1726 * release [storage | device] <name>
1728 static int release_cmd(UAContext *ua, const char *cmd)
1730 do_mount_cmd(ua, "release"); /* release */
1737 * use catalog=<name>
1739 static int use_cmd(UAContext *ua, const char *cmd)
1741 CAT *oldcatalog, *catalog;
1744 close_db(ua); /* close any previously open db */
1745 oldcatalog = ua->catalog;
1747 if (!(catalog = get_catalog_resource(ua))) {
1748 ua->catalog = oldcatalog;
1750 ua->catalog = catalog;
1753 bsendmsg(ua, _("Using Catalog name=%s DB=%s\n"),
1754 ua->catalog->hdr.name, ua->catalog->db_name);
1759 int quit_cmd(UAContext *ua, const char *cmd)
1766 * Wait until no job is running
1768 int wait_cmd(UAContext *ua, const char *cmd)
1771 bmicrosleep(0, 200000); /* let job actually start */
1772 for (bool running=true; running; ) {
1776 if (jcr->JobId != 0) {
1778 free_locked_jcr(jcr);
1781 free_locked_jcr(jcr);
1792 static int help_cmd(UAContext *ua, const char *cmd)
1796 bsendmsg(ua, _(" Command Description\n ======= ===========\n"));
1797 for (i=0; i<comsize; i++) {
1798 bsendmsg(ua, _(" %-10s %s\n"), _(commands[i].key), _(commands[i].help));
1800 bsendmsg(ua, _("\nWhen at a prompt, entering a period cancels the command.\n\n"));
1804 static int version_cmd(UAContext *ua, const char *cmd)
1806 bsendmsg(ua, "%s Version: " VERSION " (" BDATE ")\n", my_name);
1811 /* A bit brain damaged in that if the user has not done
1812 * a "use catalog xxx" command, we simply find the first
1813 * catalog resource and open it.
1815 int open_db(UAContext *ua)
1822 ua->catalog = (CAT *)GetNextRes(R_CATALOG, NULL);
1825 bsendmsg(ua, _("Could not find a Catalog resource\n"));
1828 bsendmsg(ua, _("Using default Catalog name=%s DB=%s\n"),
1829 ua->catalog->hdr.name, ua->catalog->db_name);
1833 ua->jcr->catalog = ua->catalog;
1835 Dmsg0(150, "Open database\n");
1836 ua->db = db_init_database(ua->jcr, ua->catalog->db_name, ua->catalog->db_user,
1837 ua->catalog->db_password, ua->catalog->db_address,
1838 ua->catalog->db_port, ua->catalog->db_socket);
1839 if (!ua->db || !db_open_database(ua->jcr, ua->db)) {
1840 bsendmsg(ua, _("Could not open database \"%s\".\n"),
1841 ua->catalog->db_name);
1843 bsendmsg(ua, "%s", db_strerror(ua->db));
1848 ua->jcr->db = ua->db;
1849 Dmsg1(150, "DB %s opened\n", ua->catalog->db_name);
1853 void close_db(UAContext *ua)
1856 db_close_database(ua->jcr, ua->db);