/* Imported functions */
int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons);
-
+/* Dummy functions */
+int generate_daemon_event(JCR *jcr, const char *event) { return 1; }
/* Forward referenced functions */
static void terminate_console(int sig);
static BSOCK *UA_sock = NULL;
static DIRRES *dir;
static FILE *output = stdout;
-static bool tee = false; /* output to output and stdout */
+static bool tee = false; /* output to output and stdout */
static bool stop = false;
static int argc;
static POOLMEM *args;
{ N_("version"), versioncmd, _("print Console's version")},
{ N_("exit"), quitcmd, _("exit = quit")},
{ N_("zed_keyst"), zed_keyscmd, _("zed_keys = use zed keys instead of bash keys")},
- };
+ };
#define comsize (sizeof(commands)/sizeof(struct cmdstruct))
static int do_a_command(FILE *input, BSOCK *UA_sock)
return 1;
}
len = strlen(cmd);
- for (i=0; i<comsize; i++) { /* search for command */
+ for (i=0; i<comsize; i++) { /* search for command */
if (strncasecmp(cmd, _(commands[i].key), len) == 0) {
- stat = (*commands[i].func)(input, UA_sock); /* go execute command */
- found = 1;
- break;
+ stat = (*commands[i].func)(input, UA_sock); /* go execute command */
+ found = 1;
+ break;
}
}
if (!found) {
prompt = "";
} else {
prompt = "*";
- at_prompt = true;
+ at_prompt = true;
}
if (tty_input) {
- stat = get_cmd(input, prompt, UA_sock, 30);
- if (usrbrk() == 1) {
- clrbrk();
- }
- if (usrbrk()) {
- break;
- }
+ stat = get_cmd(input, prompt, UA_sock, 30);
+ if (usrbrk() == 1) {
+ clrbrk();
+ }
+ if (usrbrk()) {
+ break;
+ }
} else {
- /* Reading input from a file */
- int len = sizeof_pool_memory(UA_sock->msg) - 1;
- if (usrbrk()) {
- break;
- }
- if (fgets(UA_sock->msg, len, input) == NULL) {
- stat = -1;
- } else {
- sendit(UA_sock->msg); /* echo to terminal */
- strip_trailing_junk(UA_sock->msg);
- UA_sock->msglen = strlen(UA_sock->msg);
- stat = 1;
- }
+ /* Reading input from a file */
+ int len = sizeof_pool_memory(UA_sock->msg) - 1;
+ if (usrbrk()) {
+ break;
+ }
+ if (fgets(UA_sock->msg, len, input) == NULL) {
+ stat = -1;
+ } else {
+ sendit(UA_sock->msg); /* echo to terminal */
+ strip_trailing_junk(UA_sock->msg);
+ UA_sock->msglen = strlen(UA_sock->msg);
+ stat = 1;
+ }
}
if (stat < 0) {
- break; /* error or interrupt */
- } else if (stat == 0) { /* timeout */
+ break; /* error or interrupt */
+ } else if (stat == 0) { /* timeout */
if (strcmp(prompt, "*") == 0) {
bnet_fsend(UA_sock, ".messages");
- } else {
- continue;
- }
+ } else {
+ continue;
+ }
} else {
- at_prompt = FALSE;
- /* @ => internal command for us */
+ at_prompt = FALSE;
+ /* @ => internal command for us */
if (UA_sock->msg[0] == '@') {
- parse_args(UA_sock->msg, &args, &argc, argk, argv, MAX_CMD_ARGS);
- if (!do_a_command(input, UA_sock)) {
- break;
- }
- continue;
- }
- if (!bnet_send(UA_sock)) { /* send command */
- break; /* error */
- }
+ parse_args(UA_sock->msg, &args, &argc, argk, argv, MAX_CMD_ARGS);
+ if (!do_a_command(input, UA_sock)) {
+ break;
+ }
+ continue;
+ }
+ if (!bnet_send(UA_sock)) { /* send command */
+ break; /* error */
+ }
}
if (strcmp(UA_sock->msg, ".quit") == 0 || strcmp(UA_sock->msg, ".exit") == 0) {
- break;
+ break;
}
while ((stat = bnet_recv(UA_sock)) >= 0) {
- if (at_prompt) {
- if (!stop) {
+ if (at_prompt) {
+ if (!stop) {
sendit("\n");
- }
- at_prompt = false;
- }
- /* Suppress output if running in background or user hit ctl-c */
- if (!stop && !usrbrk()) {
- sendit(UA_sock->msg);
- }
+ }
+ at_prompt = false;
+ }
+ /* Suppress output if running in background or user hit ctl-c */
+ if (!stop && !usrbrk()) {
+ sendit(UA_sock->msg);
+ }
}
if (usrbrk() > 1) {
- break;
+ break;
} else {
- clrbrk();
+ clrbrk();
}
if (!stop) {
- fflush(stdout);
+ fflush(stdout);
}
if (is_bnet_stop(UA_sock)) {
- break; /* error or term */
+ break; /* error or term */
} else if (stat == BNET_SIGNAL) {
- if (UA_sock->msglen == BNET_PROMPT) {
- at_prompt = true;
- }
+ if (UA_sock->msglen == BNET_PROMPT) {
+ at_prompt = true;
+ }
Dmsg1(100, "Got poll %s\n", bnet_sig_to_ascii(UA_sock));
}
}
/*********************************************************************
*
- * Main Bacula Console -- User Interface Program
+ * Main Bacula Console -- User Interface Program
*
*/
int main(int argc, char *argv[])
while ((ch = getopt(argc, argv, "bc:d:r:st?")) != -1) {
switch (ch) {
case 'c': /* configuration file */
- if (configfile != NULL) {
- free(configfile);
- }
- configfile = bstrdup(optarg);
- break;
+ if (configfile != NULL) {
+ free(configfile);
+ }
+ configfile = bstrdup(optarg);
+ break;
case 'd':
- debug_level = atoi(optarg);
- if (debug_level <= 0) {
- debug_level = 1;
- }
- break;
+ debug_level = atoi(optarg);
+ if (debug_level <= 0) {
+ debug_level = 1;
+ }
+ break;
case 's': /* turn off signals */
- no_signals = true;
- break;
+ no_signals = true;
+ break;
case 't':
- test_config = true;
- break;
+ test_config = true;
+ break;
case '?':
default:
- usage();
- con_term();
- exit(1);
+ usage();
+ con_term();
+ exit(1);
}
}
argc -= optind;
memset(&jcr, 0, sizeof(jcr));
- (void)WSA_Init(); /* Initialize Windows sockets */
+ (void)WSA_Init(); /* Initialize Windows sockets */
if (ndir > 1) {
struct sockaddr client_addr;
ndir = 0;
foreach_res(dir, R_DIRECTOR) {
senditf( _("%d %s at %s:%d\n"), 1+ndir++, dir->hdr.name, dir->address,
- dir->DIRport);
+ dir->DIRport);
}
UnlockRes();
if (get_cmd(stdin, _("Select Director: "), UA_sock, 600) < 0) {
- (void)WSACleanup(); /* Cleanup Windows sockets */
- return 1;
+ (void)WSACleanup(); /* Cleanup Windows sockets */
+ return 1;
}
item = atoi(UA_sock->msg);
if (item < 0 || item > ndir) {
senditf(_("You must enter a number between 1 and %d\n"), ndir);
- goto try_again;
+ goto try_again;
}
LockRes();
dir = NULL;
for (i=0; i<item; i++) {
- dir = (DIRRES *)GetNextRes(R_DIRECTOR, (RES *)dir);
+ dir = (DIRRES *)GetNextRes(R_DIRECTOR, (RES *)dir);
}
UnlockRes();
term_bsock(UA_sock);
senditf(_("Connecting to Director %s:%d\n"), dir->address,dir->DIRport);
UA_sock = bnet_connect(NULL, 5, 15, "Director daemon", dir->address,
- NULL, dir->DIRport, 0);
+ NULL, dir->DIRport, 0);
if (UA_sock == NULL) {
terminate_console(0);
return 1;
pm_strcat(&UA_sock->msg, "/.bconsolerc");
fd = fopen(UA_sock->msg, "r");
if (fd) {
- read_and_process_input(fd, UA_sock);
- fclose(fd);
+ read_and_process_input(fd, UA_sock);
+ fclose(fd);
}
}
static bool already_here = false;
- if (already_here) { /* avoid recursive temination problems */
+ if (already_here) { /* avoid recursive temination problems */
exit(1);
}
already_here = true;
free_pool_memory(args);
con_term();
- (void)WSACleanup(); /* Cleanup Windows sockets */
+ (void)WSACleanup(); /* Cleanup Windows sockets */
if (sig != 0) {
exit(1);
}
{
char *line;
- rl_catch_signals = 0; /* do it ourselves */
+ rl_catch_signals = 0; /* do it ourselves */
line = readline((char *)prompt); /* cast needed for old readlines */
if (!line) {
/*
* Returns: 1 if data available
- * 0 if timeout
- * -1 if error
+ * 0 if timeout
+ * -1 if error
*/
static int
wait_for_data(int fd, int sec)
FD_ZERO(&fdset);
FD_SET((unsigned)fd, &fdset);
switch(select(fd + 1, &fdset, NULL, NULL, &tv)) {
- case 0: /* timeout */
- return 0;
+ case 0: /* timeout */
+ return 0;
case -1:
- if (errno == EINTR || errno == EAGAIN) {
- continue;
- }
- return -1; /* error return */
+ if (errno == EINTR || errno == EAGAIN) {
+ continue;
+ }
+ return -1; /* error return */
default:
- return 1;
+ return 1;
}
}
}
* Get next input command from terminal.
*
* Returns: 1 if got input
- * 0 if timeout
- * -1 if EOF or error
+ * 0 if timeout
+ * -1 if EOF or error
*/
int
get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec)
int len;
if (!stop) {
if (output == stdout || tee) {
- sendit(prompt);
+ sendit(prompt);
}
}
again:
switch (wait_for_data(fileno(input), sec)) {
case 0:
- return 0; /* timeout */
+ return 0; /* timeout */
case -1:
- return -1; /* error */
+ return -1; /* error */
default:
len = sizeof_pool_memory(sock->msg) - 1;
if (stop) {
- sleep(1);
- goto again;
+ sleep(1);
+ goto again;
}
#ifdef HAVE_CONIO
if (isatty(fileno(input))) {
- input_line(sock->msg, len);
- break;
+ input_line(sock->msg, len);
+ break;
}
#endif
if (fgets(sock->msg, len, input) == NULL) {
- return -1;
+ return -1;
}
break;
}
fd = fopen(argk[1], "r");
if (!fd) {
senditf(_("Cannot open file %s for input. ERR=%s\n"),
- argk[1], strerror(errno));
+ argk[1], strerror(errno));
return 1;
}
read_and_process_input(fd, UA_sock);
}
if (argc == 1) {
if (output != stdout) {
- fclose(output);
- output = stdout;
- tee = false;
+ fclose(output);
+ output = stdout;
+ tee = false;
}
return 1;
}
fd = fopen(argk[1], mode);
if (!fd) {
senditf(_("Cannot open file %s for output. ERR=%s\n"),
- argk[1], strerror(errno));
+ argk[1], strerror(errno));
return 1;
}
output = fd;
char *p, *q;
/*
* Here, we convert every \n into \r\n because the
- * terminal is in raw mode when we are using
- * conio.
- */
+ * terminal is in raw mode when we are using
+ * conio.
+ */
for (p=q=buf; (p=strchr(q, '\n')); ) {
- if (p-q > 0) {
- t_sendl(q, p-q);
- }
+ if (p-q > 0) {
+ t_sendl(q, p-q);
+ }
t_sendl("\r\n", 2);
q = ++p; /* point after \n */
}
if (*q) {
- t_send(q);
+ t_send(q);
}
}
if (output != stdout) {
#include "cats/cats.h"
#include "dird/dird_conf.h"
+/* Dummy functions */
+int generate_daemon_event(JCR *jcr, const char *event)
+ { return 1; }
+
typedef struct s_id_ctx {
- uint32_t *Id; /* ids to be modified */
- int num_ids; /* ids stored */
- int max_ids; /* size of array */
- int num_del; /* number deleted */
- int tot_ids; /* total to process */
+ uint32_t *Id; /* ids to be modified */
+ int num_ids; /* ids stored */
+ int max_ids; /* size of array */
+ int num_del; /* number deleted */
+ int tot_ids; /* total to process */
} ID_LIST;
typedef struct s_name_ctx {
- char **name; /* list of names */
- int num_ids; /* ids stored */
- int max_ids; /* size of array */
- int num_del; /* number deleted */
- int tot_ids; /* total to process */
+ char **name; /* list of names */
+ int num_ids; /* ids stored */
+ int max_ids; /* size of array */
+ int num_del; /* number deleted */
+ int tot_ids; /* total to process */
} NAME_LIST;
char *catalogname = NULL;
my_name_is(argc, argv, "dbcheck");
- init_msg(NULL, NULL); /* setup message handler */
+ init_msg(NULL, NULL); /* setup message handler */
memset(&id_list, 0, sizeof(id_list));
memset(&name_list, 0, sizeof(name_list));
while ((ch = getopt(argc, argv, "bc:C:d:fv?")) != -1) {
switch (ch) {
case 'b': /* batch */
- batch = true;
- break;
+ batch = true;
+ break;
case 'C': /* CatalogName */
- catalogname = optarg;
- break;
+ catalogname = optarg;
+ break;
case 'c': /* configfile */
- configfile = optarg;
- break;
+ configfile = optarg;
+ break;
case 'd': /* debug level */
- debug_level = atoi(optarg);
- if (debug_level <= 0)
- debug_level = 1;
- break;
+ debug_level = atoi(optarg);
+ if (debug_level <= 0)
+ debug_level = 1;
+ break;
case 'f': /* fix inconsistencies */
- fix = true;
- break;
+ fix = true;
+ break;
case 'v':
- verbose++;
- break;
+ verbose++;
+ break;
case '?':
default:
- usage();
+ usage();
}
}
argc -= optind;
CAT *catalog = NULL;
int found = 0;
if (argc > 0) {
- Pmsg0(0, _("Warning skipping the additional parameters for working directory/dbname/user/password/host.\n"));
+ 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;
- }
+ 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);
- }
- exit(1);
+ 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);
+ }
+ exit(1);
} else {
- DIRRES *director;
- LockRes();
- director = (DIRRES *)GetNextRes(R_DIRECTOR, NULL);
- UnlockRes();
- if (!director) {
- Pmsg0(0, "Error no Director resource defined.\n");
- exit(1);
- }
- set_working_directory(director->working_directory);
- db_name = catalog->db_name;
- user = catalog->db_user;
- password = catalog->db_password;
- dbhost = catalog->db_address;
- if (dbhost && dbhost[0] == 0) {
- dbhost = NULL;
- }
+ DIRRES *director;
+ LockRes();
+ director = (DIRRES *)GetNextRes(R_DIRECTOR, NULL);
+ UnlockRes();
+ if (!director) {
+ Pmsg0(0, "Error no Director resource defined.\n");
+ exit(1);
+ }
+ set_working_directory(director->working_directory);
+ db_name = catalog->db_name;
+ user = catalog->db_user;
+ password = catalog->db_password;
+ dbhost = catalog->db_address;
+ if (dbhost && dbhost[0] == 0) {
+ dbhost = NULL;
+ }
}
} else {
if (argc > 5) {
- Pmsg0(0, _("Wrong number of arguments.\n"));
- usage();
+ Pmsg0(0, _("Wrong number of arguments.\n"));
+ usage();
}
if (argc < 1) {
- Pmsg0(0, _("Working directory not supplied.\n"));
- usage();
+ Pmsg0(0, _("Working directory not supplied.\n"));
+ usage();
}
/* This is needed by SQLite to find the db */
dbhost = NULL;
if (argc == 2) {
- db_name = argv[1];
- user = db_name;
+ db_name = argv[1];
+ user = db_name;
} else if (argc == 3) {
- db_name = argv[1];
- user = argv[2];
+ db_name = argv[1];
+ user = argv[2];
} else if (argc == 4) {
- db_name = argv[1];
- user = argv[2];
- password = argv[3];
+ 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];
+ db_name = argv[1];
+ user = argv[2];
+ password = argv[3];
+ dbhost = argv[4];
}
}
db = db_init_database(NULL, db_name, user, password, dbhost, 0, NULL, 0);
if (!db_open_database(NULL, db)) {
Emsg1(M_FATAL, 0, "%s", db_strerror(db));
- return 1;
+ return 1;
}
if (batch) {
printf("Hello, this is the database check/correct program.\n"
"Modify database is %s. Verbose is %s.\n"
"Please select the fuction you want to perform.\n",
- fix?"On":"Off", verbose?"On":"Off");
+ fix?"On":"Off", verbose?"On":"Off");
while (!quit) {
if (fix) {
- printf(_("\n"
+ printf(_("\n"
" 1) Toggle modify database flag\n"
" 2) Toggle verbose flag\n"
" 3) Repair bad Filename records\n"
" 16) All (3-15)\n"
" 17) Quit\n"));
} else {
- printf(_("\n"
+ printf(_("\n"
" 1) Toggle modify database flag\n"
" 2) Toggle verbose flag\n"
" 3) Check for bad Filename records\n"
cmd = get_cmd(_("Select function number: "));
if (cmd) {
- int item = atoi(cmd);
- switch (item) {
- case 1:
- fix = !fix;
- printf(_("Database will %sbe modified.\n"), fix?"":_("NOT "));
- break;
- case 2:
- verbose = verbose?0:1;
- printf(_("Verbose is %s\n"), verbose?_("On"):_("Off"));
- break;
- case 3:
- repair_bad_filenames();
- break;
- case 4:
- repair_bad_paths();
- break;
- case 5:
- eliminate_duplicate_filenames();
- break;
- case 6:
- eliminate_duplicate_paths();
- break;
- case 7:
- eliminate_orphaned_jobmedia_records();
- break;
- case 8:
- eliminate_orphaned_file_records();
- break;
- case 9:
- eliminate_orphaned_path_records();
- break;
- case 10:
- eliminate_orphaned_filename_records();
- break;
- case 11:
- eliminate_orphaned_fileset_records();
- break;
- case 12:
- eliminate_orphaned_client_records();
- break;
- case 13:
- eliminate_orphaned_job_records();
- break;
- case 14:
- eliminate_admin_records();
- break;
- case 15:
- eliminate_restore_records();
- break;
- case 16:
- repair_bad_filenames();
- repair_bad_paths();
- eliminate_duplicate_filenames();
- eliminate_duplicate_paths();
- eliminate_orphaned_jobmedia_records();
- eliminate_orphaned_file_records();
- eliminate_orphaned_path_records();
- eliminate_orphaned_filename_records();
- eliminate_orphaned_fileset_records();
- eliminate_orphaned_client_records();
- eliminate_orphaned_job_records();
- eliminate_admin_records();
- eliminate_restore_records();
- break;
- case 17:
- quit = true;
- break;
- }
+ int item = atoi(cmd);
+ switch (item) {
+ case 1:
+ fix = !fix;
+ printf(_("Database will %sbe modified.\n"), fix?"":_("NOT "));
+ break;
+ case 2:
+ verbose = verbose?0:1;
+ printf(_("Verbose is %s\n"), verbose?_("On"):_("Off"));
+ break;
+ case 3:
+ repair_bad_filenames();
+ break;
+ case 4:
+ repair_bad_paths();
+ break;
+ case 5:
+ eliminate_duplicate_filenames();
+ break;
+ case 6:
+ eliminate_duplicate_paths();
+ break;
+ case 7:
+ eliminate_orphaned_jobmedia_records();
+ break;
+ case 8:
+ eliminate_orphaned_file_records();
+ break;
+ case 9:
+ eliminate_orphaned_path_records();
+ break;
+ case 10:
+ eliminate_orphaned_filename_records();
+ break;
+ case 11:
+ eliminate_orphaned_fileset_records();
+ break;
+ case 12:
+ eliminate_orphaned_client_records();
+ break;
+ case 13:
+ eliminate_orphaned_job_records();
+ break;
+ case 14:
+ eliminate_admin_records();
+ break;
+ case 15:
+ eliminate_restore_records();
+ break;
+ case 16:
+ repair_bad_filenames();
+ repair_bad_paths();
+ eliminate_duplicate_filenames();
+ eliminate_duplicate_paths();
+ eliminate_orphaned_jobmedia_records();
+ eliminate_orphaned_file_records();
+ eliminate_orphaned_path_records();
+ eliminate_orphaned_filename_records();
+ eliminate_orphaned_fileset_records();
+ eliminate_orphaned_client_records();
+ eliminate_orphaned_job_records();
+ eliminate_admin_records();
+ eliminate_restore_records();
+ break;
+ case 17:
+ quit = true;
+ break;
+ }
}
}
}
static int print_job_handler(void *ctx, int num_fields, char **row)
{
printf(_("JobId=%s Name=\"%s\" StartTime=%s\n"),
- NPRT(row[0]), NPRT(row[1]), NPRT(row[2]));
+ NPRT(row[0]), NPRT(row[1]), NPRT(row[2]));
return 0;
}
static int print_jobmedia_handler(void *ctx, int num_fields, char **row)
{
printf(_("Orphaned JobMediaId=%s JobId=%s Volume=\"%s\"\n"),
- NPRT(row[0]), NPRT(row[1]), NPRT(row[2]));
+ NPRT(row[0]), NPRT(row[1]), NPRT(row[2]));
return 0;
}
static int print_file_handler(void *ctx, int num_fields, char **row)
{
printf(_("Orphaned FileId=%s JobId=%s Volume=\"%s\"\n"),
- NPRT(row[0]), NPRT(row[1]), NPRT(row[2]));
+ NPRT(row[0]), NPRT(row[1]), NPRT(row[2]));
return 0;
}
static int print_fileset_handler(void *ctx, int num_fields, char **row)
{
printf(_("Orphaned FileSetId=%s FileSet=\"%s\" MD5=%s\n"),
- NPRT(row[0]), NPRT(row[1]), NPRT(row[2]));
+ NPRT(row[0]), NPRT(row[1]), NPRT(row[2]));
return 0;
}
static int print_client_handler(void *ctx, int num_fields, char **row)
{
printf(_("Orphaned ClientId=%s Name=\"%s\"\n"),
- NPRT(row[0]), NPRT(row[1]));
+ NPRT(row[0]), NPRT(row[1]));
return 0;
}
}
if (lst->num_ids == lst->max_ids) {
if (lst->max_ids == 0) {
- lst->max_ids = 1000;
- lst->Id = (uint32_t *)bmalloc(sizeof(uint32_t) * lst->max_ids);
+ lst->max_ids = 1000;
+ lst->Id = (uint32_t *)bmalloc(sizeof(uint32_t) * lst->max_ids);
} else {
- lst->max_ids = (lst->max_ids * 3) / 2;
- lst->Id = (uint32_t *)brealloc(lst->Id, sizeof(uint32_t) * lst->max_ids);
+ lst->max_ids = (lst->max_ids * 3) / 2;
+ lst->Id = (uint32_t *)brealloc(lst->Id, sizeof(uint32_t) * lst->max_ids);
}
}
lst->Id[lst->num_ids++] = (uint32_t)strtod(row[0], NULL);
for (int i=0; i < id_list->num_ids; i++) {
bsnprintf(buf, sizeof(buf), query, id_list->Id[i]);
if (verbose) {
- printf("Deleting: %s\n", buf);
+ printf("Deleting: %s\n", buf);
}
db_sql_query(db, buf, NULL, NULL);
}
}
if (name->num_ids == name->max_ids) {
if (name->max_ids == 0) {
- name->max_ids = 1000;
- name->name = (char **)bmalloc(sizeof(char *) * name->max_ids);
+ name->max_ids = 1000;
+ name->name = (char **)bmalloc(sizeof(char *) * name->max_ids);
} else {
- name->max_ids = (name->max_ids * 3) / 2;
- name->name = (char **)brealloc(name->name, sizeof(char *) * name->max_ids);
+ name->max_ids = (name->max_ids * 3) / 2;
+ name->name = (char **)brealloc(name->name, sizeof(char *) * name->max_ids);
}
}
name->name[name->num_ids++] = bstrdup(row[0]);
/* Make list of duplicated names */
query = "SELECT Name, count(Name) as Count FROM Filename GROUP BY Name "
- "HAVING count(Name) > 1";
+ "HAVING count(Name) > 1";
if (!make_name_list(query, &name_list)) {
exit(1);
if (fix) {
/* Loop through list of duplicate names */
for (int i=0; i<name_list.num_ids; i++) {
- /* Get all the Ids of each name */
- db_escape_string(esc_name, name_list.name[i], strlen(name_list.name[i]));
- bsnprintf(buf, sizeof(buf), "SELECT FilenameId FROM Filename WHERE Name='%s'", esc_name);
- if (verbose > 1) {
- printf("%s\n", buf);
- }
- if (!make_id_list(buf, &id_list)) {
- exit(1);
- }
- if (verbose) {
- printf("Found %d for: %s\n", id_list.num_ids, name_list.name[i]);
- }
- /* Force all records to use the first id then delete the other ids */
- for (int j=1; j<id_list.num_ids; j++) {
- bsnprintf(buf, sizeof(buf), "UPDATE File SET FilenameId=%u WHERE FilenameId=%u",
- id_list.Id[0], id_list.Id[j]);
- if (verbose > 1) {
- printf("%s\n", buf);
- }
- db_sql_query(db, buf, NULL, NULL);
- bsnprintf(buf, sizeof(buf), "DELETE FROM Filename WHERE FilenameId=%u",
- id_list.Id[j]);
- if (verbose > 2) {
- printf("%s\n", buf);
- }
- db_sql_query(db, buf, NULL, NULL);
- }
+ /* Get all the Ids of each name */
+ db_escape_string(esc_name, name_list.name[i], strlen(name_list.name[i]));
+ bsnprintf(buf, sizeof(buf), "SELECT FilenameId FROM Filename WHERE Name='%s'", esc_name);
+ if (verbose > 1) {
+ printf("%s\n", buf);
+ }
+ if (!make_id_list(buf, &id_list)) {
+ exit(1);
+ }
+ if (verbose) {
+ printf("Found %d for: %s\n", id_list.num_ids, name_list.name[i]);
+ }
+ /* Force all records to use the first id then delete the other ids */
+ for (int j=1; j<id_list.num_ids; j++) {
+ bsnprintf(buf, sizeof(buf), "UPDATE File SET FilenameId=%u WHERE FilenameId=%u",
+ id_list.Id[0], id_list.Id[j]);
+ if (verbose > 1) {
+ printf("%s\n", buf);
+ }
+ db_sql_query(db, buf, NULL, NULL);
+ bsnprintf(buf, sizeof(buf), "DELETE FROM Filename WHERE FilenameId=%u",
+ id_list.Id[j]);
+ if (verbose > 2) {
+ printf("%s\n", buf);
+ }
+ db_sql_query(db, buf, NULL, NULL);
+ }
}
}
free_name_list(&name_list);
/* Make list of duplicated names */
query = "SELECT Path, count(Path) as Count FROM Path "
- "GROUP BY Path HAVING count(Path) > 1";
+ "GROUP BY Path HAVING count(Path) > 1";
if (!make_name_list(query, &name_list)) {
exit(1);
if (fix) {
/* Loop through list of duplicate names */
for (int i=0; i<name_list.num_ids; i++) {
- /* Get all the Ids of each name */
- db_escape_string(esc_name, name_list.name[i], strlen(name_list.name[i]));
- bsnprintf(buf, sizeof(buf), "SELECT PathId FROM Path WHERE Path='%s'", esc_name);
- if (verbose > 1) {
- printf("%s\n", buf);
- }
- if (!make_id_list(buf, &id_list)) {
- exit(1);
- }
- if (verbose) {
- printf("Found %d for: %s\n", id_list.num_ids, name_list.name[i]);
- }
- /* Force all records to use the first id then delete the other ids */
- for (int j=1; j<id_list.num_ids; j++) {
- bsnprintf(buf, sizeof(buf), "UPDATE File SET PathId=%u WHERE PathId=%u",
- id_list.Id[0], id_list.Id[j]);
- if (verbose > 1) {
- printf("%s\n", buf);
- }
- db_sql_query(db, buf, NULL, NULL);
- bsnprintf(buf, sizeof(buf), "DELETE FROM Path WHERE PathId=%u",
- id_list.Id[j]);
- if (verbose > 2) {
- printf("%s\n", buf);
- }
- db_sql_query(db, buf, NULL, NULL);
- }
+ /* Get all the Ids of each name */
+ db_escape_string(esc_name, name_list.name[i], strlen(name_list.name[i]));
+ bsnprintf(buf, sizeof(buf), "SELECT PathId FROM Path WHERE Path='%s'", esc_name);
+ if (verbose > 1) {
+ printf("%s\n", buf);
+ }
+ if (!make_id_list(buf, &id_list)) {
+ exit(1);
+ }
+ if (verbose) {
+ printf("Found %d for: %s\n", id_list.num_ids, name_list.name[i]);
+ }
+ /* Force all records to use the first id then delete the other ids */
+ for (int j=1; j<id_list.num_ids; j++) {
+ bsnprintf(buf, sizeof(buf), "UPDATE File SET PathId=%u WHERE PathId=%u",
+ id_list.Id[0], id_list.Id[j]);
+ if (verbose > 1) {
+ printf("%s\n", buf);
+ }
+ db_sql_query(db, buf, NULL, NULL);
+ bsnprintf(buf, sizeof(buf), "DELETE FROM Path WHERE PathId=%u",
+ id_list.Id[j]);
+ if (verbose > 2) {
+ printf("%s\n", buf);
+ }
+ db_sql_query(db, buf, NULL, NULL);
+ }
}
}
free_name_list(&name_list);
printf("Checking for orphaned JobMedia entries.\n");
query = "SELECT JobMedia.JobMediaId,Job.JobId FROM JobMedia "
- "LEFT OUTER JOIN Job ON (JobMedia.JobId=Job.JobId) "
- "WHERE Job.JobId IS NULL";
+ "LEFT OUTER JOIN Job ON (JobMedia.JobId=Job.JobId) "
+ "WHERE Job.JobId IS NULL";
if (!make_id_list(query, &id_list)) {
exit(1);
}
printf("Found %d orphaned JobMedia records.\n", id_list.num_ids);
if (id_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) {
for (int i=0; i < id_list.num_ids; i++) {
- bsnprintf(buf, sizeof(buf),
+ bsnprintf(buf, sizeof(buf),
"SELECT JobMedia.JobMediaId,JobMedia.JobId,Media.VolumeName FROM JobMedia,Media "
"WHERE JobMedia.JobMediaId=%u AND Media.MediaId=JobMedia.MediaId", id_list.Id[i]);
- if (!db_sql_query(db, buf, print_jobmedia_handler, NULL)) {
- printf("%s\n", db_strerror(db));
- }
+ if (!db_sql_query(db, buf, print_jobmedia_handler, NULL)) {
+ printf("%s\n", db_strerror(db));
+ }
}
}
printf("Checking for orphaned File entries. This may take some time!\n");
query = "SELECT File.FileId,Job.JobId FROM File "
- "LEFT OUTER JOIN Job ON (File.JobId=Job.JobId) "
- "WHERE Job.JobId IS NULL";
+ "LEFT OUTER JOIN Job ON (File.JobId=Job.JobId) "
+ "WHERE Job.JobId IS NULL";
if (verbose > 1) {
printf("%s\n", query);
}
printf("Found %d orphaned File records.\n", id_list.num_ids);
if (name_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) {
for (int i=0; i < id_list.num_ids; i++) {
- bsnprintf(buf, sizeof(buf),
+ bsnprintf(buf, sizeof(buf),
"SELECT File.FileId,File.JobId,Filename.Name FROM File,Filename "
"WHERE File.FileId=%u AND File.FilenameId=Filename.FilenameId", id_list.Id[i]);
- if (!db_sql_query(db, buf, print_file_handler, NULL)) {
- printf("%s\n", db_strerror(db));
- }
+ if (!db_sql_query(db, buf, print_file_handler, NULL)) {
+ printf("%s\n", db_strerror(db));
+ }
}
}
printf("Checking for orphaned Path entries. This may take some time!\n");
query = "SELECT DISTINCT Path.PathId,File.PathId FROM Path "
- "LEFT OUTER JOIN File ON (Path.PathId=File.PathId) "
- "WHERE File.PathId IS NULL";
+ "LEFT OUTER JOIN File ON (Path.PathId=File.PathId) "
+ "WHERE File.PathId IS NULL";
if (verbose > 1) {
printf("%s\n", query);
}
printf("Found %d orphaned Path records.\n", id_list.num_ids);
if (id_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) {
for (int i=0; i < id_list.num_ids; i++) {
- bsnprintf(buf, sizeof(buf), "SELECT Path FROM Path WHERE PathId=%u", id_list.Id[i]);
- db_sql_query(db, buf, print_name_handler, NULL);
+ bsnprintf(buf, sizeof(buf), "SELECT Path FROM Path WHERE PathId=%u", id_list.Id[i]);
+ db_sql_query(db, buf, print_name_handler, NULL);
}
}
printf("Checking for orphaned Filename entries. This may take some time!\n");
query = "SELECT Filename.FilenameId,File.FilenameId FROM Filename "
- "LEFT OUTER JOIN File ON (Filename.FilenameId=File.FilenameId) "
- "WHERE File.FilenameId IS NULL";
+ "LEFT OUTER JOIN File ON (Filename.FilenameId=File.FilenameId) "
+ "WHERE File.FilenameId IS NULL";
if (verbose > 1) {
printf("%s\n", query);
}
printf("Found %d orphaned Filename records.\n", id_list.num_ids);
if (id_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) {
for (int i=0; i < id_list.num_ids; i++) {
- bsnprintf(buf, sizeof(buf), "SELECT Name FROM Filename WHERE FilenameId=%u", id_list.Id[i]);
- db_sql_query(db, buf, print_name_handler, NULL);
+ bsnprintf(buf, sizeof(buf), "SELECT Name FROM Filename WHERE FilenameId=%u", id_list.Id[i]);
+ db_sql_query(db, buf, print_name_handler, NULL);
}
}
printf("Checking for orphaned FileSet entries. This takes some time!\n");
query = "SELECT FileSet.FileSetId,Job.FileSetId FROM FileSet "
- "LEFT OUTER JOIN Job ON (FileSet.FileSetId=Job.FileSetId) "
- "WHERE Job.FileSetId IS NULL";
+ "LEFT OUTER JOIN Job ON (FileSet.FileSetId=Job.FileSetId) "
+ "WHERE Job.FileSetId IS NULL";
if (verbose > 1) {
printf("%s\n", query);
}
printf("Found %d orphaned FileSet records.\n", id_list.num_ids);
if (id_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) {
for (int i=0; i < id_list.num_ids; i++) {
- bsnprintf(buf, sizeof(buf), "SELECT FileSetId,FileSet,MD5 FROM FileSet "
- "WHERE FileSetId=%u", id_list.Id[i]);
- if (!db_sql_query(db, buf, print_fileset_handler, NULL)) {
- printf("%s\n", db_strerror(db));
- }
+ bsnprintf(buf, sizeof(buf), "SELECT FileSetId,FileSet,MD5 FROM FileSet "
+ "WHERE FileSetId=%u", id_list.Id[i]);
+ if (!db_sql_query(db, buf, print_fileset_handler, NULL)) {
+ printf("%s\n", db_strerror(db));
+ }
}
}
printf("Checking for orphaned Client entries.\n");
/* In English:
- * Wiffle through Client for every Client
- * joining with the Job table including every Client even if
- * there is not a match in Job (left outer join), then
- * filter out only those where no Job points to a Client
- * i.e. Job.Client is NULL
+ * Wiffle through Client for every Client
+ * joining with the Job table including every Client even if
+ * there is not a match in Job (left outer join), then
+ * filter out only those where no Job points to a Client
+ * i.e. Job.Client is NULL
*/
query = "SELECT Client.ClientId,Client.Name FROM Client "
- "LEFT OUTER JOIN Job ON (Client.ClientId=Job.ClientId) "
- "WHERE Job.ClientId IS NULL";
+ "LEFT OUTER JOIN Job ON (Client.ClientId=Job.ClientId) "
+ "WHERE Job.ClientId IS NULL";
if (verbose > 1) {
printf("%s\n", query);
}
printf("Found %d orphaned Client records.\n", id_list.num_ids);
if (id_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) {
for (int i=0; i < id_list.num_ids; i++) {
- bsnprintf(buf, sizeof(buf), "SELECT ClientId,Name FROM Client "
- "WHERE ClientId=%u", id_list.Id[i]);
- if (!db_sql_query(db, buf, print_client_handler, NULL)) {
- printf("%s\n", db_strerror(db));
- }
+ bsnprintf(buf, sizeof(buf), "SELECT ClientId,Name FROM Client "
+ "WHERE ClientId=%u", id_list.Id[i]);
+ if (!db_sql_query(db, buf, print_client_handler, NULL)) {
+ printf("%s\n", db_strerror(db));
+ }
}
}
printf("Checking for orphaned Job entries.\n");
/* In English:
- * Wiffle through Job for every Job
- * joining with the Client table including every Job even if
- * there is not a match in Client (left outer join), then
- * filter out only those where no Client exists
- * i.e. Client.Name is NULL
+ * Wiffle through Job for every Job
+ * joining with the Client table including every Job even if
+ * there is not a match in Client (left outer join), then
+ * filter out only those where no Client exists
+ * i.e. Client.Name is NULL
*/
query = "SELECT Job.JobId,Job.Name FROM Job "
- "LEFT OUTER JOIN Client ON (Job.ClientId=Client.ClientId) "
- "WHERE Client.Name IS NULL";
+ "LEFT OUTER JOIN Client ON (Job.ClientId=Client.ClientId) "
+ "WHERE Client.Name IS NULL";
if (verbose > 1) {
printf("%s\n", query);
}
printf("Found %d orphaned Job records.\n", id_list.num_ids);
if (id_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) {
for (int i=0; i < id_list.num_ids; i++) {
- bsnprintf(buf, sizeof(buf), "SELECT JobId,Name,StartTime FROM Job "
- "WHERE JobId=%u", id_list.Id[i]);
- if (!db_sql_query(db, buf, print_job_handler, NULL)) {
- printf("%s\n", db_strerror(db));
- }
+ bsnprintf(buf, sizeof(buf), "SELECT JobId,Name,StartTime FROM Job "
+ "WHERE JobId=%u", id_list.Id[i]);
+ if (!db_sql_query(db, buf, print_job_handler, NULL)) {
+ printf("%s\n", db_strerror(db));
+ }
}
}
printf("Checking for Admin Job entries.\n");
query = "SELECT Job.JobId FROM Job "
- "WHERE Job.Type='D'";
+ "WHERE Job.Type='D'";
if (verbose > 1) {
printf("%s\n", query);
}
printf("Found %d Admin Job records.\n", id_list.num_ids);
if (id_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) {
for (int i=0; i < id_list.num_ids; i++) {
- bsnprintf(buf, sizeof(buf), "SELECT JobId,Name,StartTime FROM Job "
- "WHERE JobId=%u", id_list.Id[i]);
- if (!db_sql_query(db, buf, print_job_handler, NULL)) {
- printf("%s\n", db_strerror(db));
- }
+ bsnprintf(buf, sizeof(buf), "SELECT JobId,Name,StartTime FROM Job "
+ "WHERE JobId=%u", id_list.Id[i]);
+ if (!db_sql_query(db, buf, print_job_handler, NULL)) {
+ printf("%s\n", db_strerror(db));
+ }
}
}
printf("Checking for Restore Job entries.\n");
query = "SELECT Job.JobId FROM Job "
- "WHERE Job.Type='R'";
+ "WHERE Job.Type='R'";
if (verbose > 1) {
printf("%s\n", query);
}
printf("Found %d Restore Job records.\n", id_list.num_ids);
if (id_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) {
for (int i=0; i < id_list.num_ids; i++) {
- bsnprintf(buf, sizeof(buf), "SELECT JobId,Name,StartTime FROM Job "
- "WHERE JobId=%u", id_list.Id[i]);
- if (!db_sql_query(db, buf, print_job_handler, NULL)) {
- printf("%s\n", db_strerror(db));
- }
+ bsnprintf(buf, sizeof(buf), "SELECT JobId,Name,StartTime FROM Job "
+ "WHERE JobId=%u", id_list.Id[i]);
+ if (!db_sql_query(db, buf, print_job_handler, NULL)) {
+ printf("%s\n", db_strerror(db));
+ }
}
}
printf("Checking for Filenames with a trailing slash\n");
query = "SELECT FilenameId,Name from Filename "
- "WHERE Name LIKE '%/'";
+ "WHERE Name LIKE '%/'";
if (verbose > 1) {
printf("%s\n", query);
}
printf("Found %d bad Filename records.\n", id_list.num_ids);
if (id_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) {
for (i=0; i < id_list.num_ids; i++) {
- bsnprintf(buf, sizeof(buf),
- "SELECT Name FROM Filename WHERE FilenameId=%u", id_list.Id[i]);
- if (!db_sql_query(db, buf, print_name_handler, NULL)) {
- printf("%s\n", db_strerror(db));
- }
+ bsnprintf(buf, sizeof(buf),
+ "SELECT Name FROM Filename WHERE FilenameId=%u", id_list.Id[i]);
+ if (!db_sql_query(db, buf, print_name_handler, NULL)) {
+ printf("%s\n", db_strerror(db));
+ }
}
}
char esc_name[5000];
printf("Reparing %d bad Filename records.\n", id_list.num_ids);
for (i=0; i < id_list.num_ids; i++) {
- int len;
- bsnprintf(buf, sizeof(buf),
- "SELECT Name FROM Filename WHERE FilenameId=%u", id_list.Id[i]);
- if (!db_sql_query(db, buf, get_name_handler, name)) {
- printf("%s\n", db_strerror(db));
- }
- /* Strip trailing slash(es) */
- for (len=strlen(name); len > 0 && name[len-1]=='/'; len--)
- { }
- if (len == 0) {
- len = 1;
- esc_name[0] = ' ';
- esc_name[1] = 0;
- } else {
- name[len-1] = 0;
- db_escape_string(esc_name, name, len);
- }
- bsnprintf(buf, sizeof(buf),
- "UPDATE Filename SET Name='%s' WHERE FilenameId=%u",
- esc_name, id_list.Id[i]);
- if (verbose > 1) {
- printf("%s\n", buf);
- }
- db_sql_query(db, buf, NULL, NULL);
+ int len;
+ bsnprintf(buf, sizeof(buf),
+ "SELECT Name FROM Filename WHERE FilenameId=%u", id_list.Id[i]);
+ if (!db_sql_query(db, buf, get_name_handler, name)) {
+ printf("%s\n", db_strerror(db));
+ }
+ /* Strip trailing slash(es) */
+ for (len=strlen(name); len > 0 && name[len-1]=='/'; len--)
+ { }
+ if (len == 0) {
+ len = 1;
+ esc_name[0] = ' ';
+ esc_name[1] = 0;
+ } else {
+ name[len-1] = 0;
+ db_escape_string(esc_name, name, len);
+ }
+ bsnprintf(buf, sizeof(buf),
+ "UPDATE Filename SET Name='%s' WHERE FilenameId=%u",
+ esc_name, id_list.Id[i]);
+ if (verbose > 1) {
+ printf("%s\n", buf);
+ }
+ db_sql_query(db, buf, NULL, NULL);
}
}
}
printf("Checking for Paths without a trailing slash\n");
query = "SELECT PathId,Path from Path "
- "WHERE Path NOT LIKE '%/'";
+ "WHERE Path NOT LIKE '%/'";
if (verbose > 1) {
printf("%s\n", query);
}
printf("Found %d bad Path records.\n", id_list.num_ids);
if (id_list.num_ids && verbose && yes_no("Print them? (yes/no): ")) {
for (i=0; i < id_list.num_ids; i++) {
- bsnprintf(buf, sizeof(buf),
- "SELECT Path FROM Path WHERE PathId=%u", id_list.Id[i]);
- if (!db_sql_query(db, buf, print_name_handler, NULL)) {
- printf("%s\n", db_strerror(db));
- }
+ bsnprintf(buf, sizeof(buf),
+ "SELECT Path FROM Path WHERE PathId=%u", id_list.Id[i]);
+ if (!db_sql_query(db, buf, print_name_handler, NULL)) {
+ printf("%s\n", db_strerror(db));
+ }
}
}
char esc_name[5000];
printf("Reparing %d bad Filename records.\n", id_list.num_ids);
for (i=0; i < id_list.num_ids; i++) {
- int len;
- bsnprintf(buf, sizeof(buf),
- "SELECT Path FROM Path WHERE PathId=%u", id_list.Id[i]);
- if (!db_sql_query(db, buf, get_name_handler, name)) {
- printf("%s\n", db_strerror(db));
- }
- /* Strip trailing blanks */
- for (len=strlen(name); len > 0 && name[len-1]==' '; len--) {
- name[len-1] = 0;
- }
- /* Add trailing slash */
- len = pm_strcat(&name, "/");
- db_escape_string(esc_name, name, len);
- bsnprintf(buf, sizeof(buf), "UPDATE Path SET Path='%s' WHERE PathId=%u",
- esc_name, id_list.Id[i]);
- if (verbose > 1) {
- printf("%s\n", buf);
- }
- db_sql_query(db, buf, NULL, NULL);
+ int len;
+ bsnprintf(buf, sizeof(buf),
+ "SELECT Path FROM Path WHERE PathId=%u", id_list.Id[i]);
+ if (!db_sql_query(db, buf, get_name_handler, name)) {
+ printf("%s\n", db_strerror(db));
+ }
+ /* Strip trailing blanks */
+ for (len=strlen(name); len > 0 && name[len-1]==' '; len--) {
+ name[len-1] = 0;
+ }
+ /* Add trailing slash */
+ len = pm_strcat(&name, "/");
+ db_escape_string(esc_name, name, len);
+ bsnprintf(buf, sizeof(buf), "UPDATE Path SET Path='%s' WHERE PathId=%u",
+ esc_name, id_list.Id[i]);
+ if (verbose > 1) {
+ printf("%s\n", buf);
+ }
+ db_sql_query(db, buf, NULL, NULL);
}
}
}