char buf[MAXSTRING];
int recurse = 1;
if (res == NULL) {
- sendit(sock, _("Warning: no %s resource (%d) defined.\n"), res_to_str(type), type);
+ sendit(sock, _("Warning: no \"%s\" resource (%d) defined.\n"), res_to_str(type), type);
return;
}
sendit(sock, "dump_resource type=%d\n", type);
for (i=0; items[i].name; i++) {
if (items[i].flags & ITEM_REQUIRED) {
if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {
- Emsg2(M_ABORT, 0, _("%s item is required in %s resource, but not found.\n"),
+ Emsg2(M_ERROR_TERM, 0, _("\"%s\" item is required in \"%s\" resource, but not found.\n"),
items[i].name, resources[rindex]);
}
}
/* If this triggers, take a look at lib/parse_conf.h */
if (i >= MAX_RES_ITEMS) {
- Emsg1(M_ABORT, 0, _("Too many items in %s resource\n"), resources[rindex]);
+ Emsg1(M_ERROR_TERM, 0, _("Too many items in \"%s\" resource\n"), resources[rindex]);
}
}
/* Resources containing a resource */
case R_STORAGE:
if ((res = (URES *)GetResWithName(R_STORAGE, res_all.res_dir.hdr.name)) == NULL) {
- Emsg1(M_ABORT, 0, "Cannot find Storage resource %s\n", res_all.res_dir.hdr.name);
+ Emsg1(M_ERROR_TERM, 0, "Cannot find Storage resource \"%s\"\n", res_all.res_dir.hdr.name);
}
res->res_store.messages = res_all.res_store.messages;
break;
for (next=resources[rindex].res_head; next->next; next=next->next) {
if (strcmp(next->name, res->res_dir.hdr.name) == 0) {
Emsg2(M_ERROR_TERM, 0,
- _("Attempt to define second %s resource named \"%s\" is not permitted.\n"),
+ _("Attempt to define second \"%s\" resource named \"%s\" is not permitted.\n"),
resources[rindex].name, res->res_dir.hdr.name);
}
}
*
*/
/*
- Copyright (C) 2000-2003 Kern Sibbald and John Walker
+ Copyright (C) 2000-2004 Kern Sibbald and John Walker
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
#include "bacula.h"
#include "cats/cats.h"
+#include "dird/dird_conf.h"
typedef struct s_id_ctx {
uint32_t *Id; /* ids to be modified */
static void usage()
{
fprintf(stderr,
-"Usage: dbcheck [-d debug_level] <working-directory> <bacula-databse> <user> <password>\n"
+"Usage: dbcheck [-c config] [-C catalogname] [-d debug_level] <working-directory> <bacula-database> <user> <password> [<dbhost>]\n"
" -b batch mode\n"
+" -C catalogname in the director configfile\n"
+" -c director configfilename\n"
" -dnn set debug level to nn\n"
" -f fix inconsistencies\n"
" -v verbose\n"
int main (int argc, char *argv[])
{
int ch;
- char *user, *password, *db_name;
+ char *user, *password, *db_name, *dbhost;
+ char *configfile = NULL;
+ char *catalogname = NULL;
my_name_is(argc, argv, "dbcheck");
init_msg(NULL, NULL); /* setup message handler */
memset(&name_list, 0, sizeof(name_list));
- while ((ch = getopt(argc, argv, "bd:fv?")) != -1) {
+ while ((ch = getopt(argc, argv, "bc:C:d:fv?")) != -1) {
switch (ch) {
case 'b': /* batch */
batch = true;
break;
+ case 'C': /* CatalogName */
+ catalogname = optarg;
+ break;
+
+ case 'c': /* configfile */
+ configfile = optarg;
+ break;
+
case 'd': /* debug level */
debug_level = atoi(optarg);
if (debug_level <= 0)
argc -= optind;
argv += optind;
- if (argc > 4) {
- Pmsg0(0, _("Wrong number of arguments.\n"));
- usage();
- }
-
- if (argc < 1) {
- Pmsg0(0, _("Working directory not supplied.\n"));
- usage();
- }
+ if (configfile) {
+ CAT *catalog = NULL;
+ int found = 0;
+ if (argc > 0) {
+ Pmsg0(0, _("Warning skipping the additional parameters for working directory/dbname/user/password/host.\n"));
+ }
+ parse_config(configfile);
+ LockRes();
+ foreach_res(catalog, R_CATALOG) {
+ if (catalogname && !strcmp(catalog->hdr.name, catalogname)) {
+ ++found;
+ break;
+ } else if (!catalogname) { // stop on first if no catalogname is given
+ ++found;
+ break;
+ }
+ }
+ UnlockRes();
+ if (!found) {
+ if (catalogname) {
+ Pmsg2(0, "Error can not find the Catalog name[%s] in the given config file [%s]\n", catalogname, configfile);
+ } else {
+ Pmsg1(0, "Error there is no Catalog section in the given config file [%s]\n", configfile);
+ }
+ return 1;
+ } else {
+ db_name = catalog->db_name;
+ user = catalog->db_user;
+ password = catalog->db_password;
+ dbhost = (catalog->db_address[0] == '\0') ? NULL : catalog->db_address;
+ }
+ } else {
+ if (argc > 5) {
+ Pmsg0(0, _("Wrong number of arguments.\n"));
+ usage();
+ }
- /* This is needed by SQLite to find the db */
- working_directory = argv[0];
- db_name = "bacula";
- user = db_name;
- password = "";
+ if (argc < 1) {
+ Pmsg0(0, _("Working directory not supplied.\n"));
+ usage();
+ }
- if (argc == 2) {
- db_name = argv[1];
+ /* This is needed by SQLite to find the db */
+ working_directory = argv[0];
+ db_name = "bacula";
user = db_name;
- } else if (argc == 3) {
- db_name = argv[1];
- user = argv[2];
- } else if (argc == 4) {
- db_name = argv[1];
- user = argv[2];
- password = argv[3];
+ password = "";
+ dbhost = NULL;
+
+ if (argc == 2) {
+ db_name = argv[1];
+ user = db_name;
+ } else if (argc == 3) {
+ db_name = argv[1];
+ user = argv[2];
+ } else if (argc == 4) {
+ db_name = argv[1];
+ user = argv[2];
+ password = argv[3];
+ } else if (argc == 5) {
+ db_name = argv[1];
+ user = argv[2];
+ password = argv[3];
+ dbhost = argv[4];
+ }
}
/* Open database */
- db = db_init_database(NULL, db_name, user, password, NULL, 0, NULL);
+ db = db_init_database(NULL, db_name, user, password, dbhost, 0, NULL);
if (!db_open_database(NULL, db)) {
Emsg1(M_FATAL, 0, "%s", db_strerror(db));
+ return 1;
}
if (batch) {