From: Kern Sibbald Date: Mon, 24 Jul 2006 13:43:18 +0000 (+0000) Subject: - Change cats/sql.c to elimate %-*s format, which I think is turned X-Git-Tag: Release-7.0.0~7843 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=8d262dc5e14711375fa82bd4282ca078f4a4e6a8;p=bacula%2Fbacula - Change cats/sql.c to elimate %-*s format, which I think is turned off in bsnprintf. - Add Comment field to llist of a volume. - Allow true/false in some yes/no questions. - Implement update volume enable=(on|off|true|false|archived|0|1|2) - Remove a few /n's when scanning commands from another daemon. This permits adding additional fields later. - Modify dbcheck to handle ctl-d and to delete Log table entries. - Update README.mingw git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@3175 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/kernstodo b/bacula/kernstodo index 3a1c4d1e6d..51d2a2c102 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -23,14 +23,13 @@ Document: - Document setting my.cnf to big file usage. - Add example of proper index output to doc. show index from File; +- Correct the Include syntax in the m4.xxx files in examples/conf Priority: For 1.39: - Remove queue.c code. -- Correct the Include syntax in the m4.xxx files in examples/conf -- Get Perl replacement for bregex.c -- Fix auth compatibility with 1.38 +- Fix ClientRunBefore/AfterJob compatibility. - Fix re-read of last block to check if job has actually written a block, and check if block was written by a different job (i.e. multiple simultaneous jobs writing). @@ -55,6 +54,8 @@ For 1.39: target slot. The catalog should be updated accordingly. .move transfer device=xxx fromslot=yyy toslot=zzz +Low priority: +- Get Perl replacement for bregex.c - Given all the problems with FIFOs, I think the solution is to do something a little different, though I will look at the code and see if there is not some @@ -1622,4 +1623,7 @@ Block Position: 0 LocationId NewState??? - Add Comment to Media record +- Fix auth compatibility with 1.38 +- Update dbcheck to include Log table +- Update llist to include new fields. diff --git a/bacula/kes-1.39 b/bacula/kes-1.39 index 3b4b6cf28e..d48a51b92a 100644 --- a/bacula/kes-1.39 +++ b/bacula/kes-1.39 @@ -2,6 +2,16 @@ Kern Sibbald General: +24Jul06 +- Change cats/sql.c to elimate %-*s format, which I think is turned + off in bsnprintf. +- Add Comment field to llist of a volume. +- Allow true/false in some yes/no questions. +- Implement update volume enable=(on|off|true|false|archived|0|1|2) +- Remove a few /n's when scanning commands from another daemon. This + permits adding additional fields later. +- Modify dbcheck to handle ctl-d and to delete Log table entries. +- Update README.mingw 22Jul06 - Tweak authentication to work with 1.38.x FDs. - Tweak catalog make scripts. diff --git a/bacula/src/cats/sql.c b/bacula/src/cats/sql.c index 9844f1458f..d1ab642672 100644 --- a/bacula/src/cats/sql.c +++ b/bacula/src/cats/sql.c @@ -485,9 +485,11 @@ list_result(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *send, void *ctx, e_list_type t send(ctx, "|"); sql_field_seek(mdb, 0); for (i = 0; i < sql_num_fields(mdb); i++) { + char fmtbuf[50]; Dmsg1(800, "list_result looking at field %d\n", i); field = sql_fetch_field(mdb); - bsnprintf(buf, sizeof(buf), " %-*s |", (int)field->max_length, field->name); + bsnprintf(fmtbuf, sizeof(fmtbuf), "%%-%ds }", (int)field->max_length); + bsnprintf(buf, sizeof(buf), fmtbuf, field->name); send(ctx, buf); } send(ctx, "\n"); diff --git a/bacula/src/cats/sql_list.c b/bacula/src/cats/sql_list.c index 1f6cbb6376..2eff15952a 100644 --- a/bacula/src/cats/sql_list.c +++ b/bacula/src/cats/sql_list.c @@ -151,7 +151,8 @@ db_list_media_records(JCR *jcr, B_DB *mdb, MEDIA_DBR *mdbr, "VolCapacityBytes,VolStatus,Enabled,Recycle,VolRetention," "VolUseDuration,MaxVolJobs,MaxVolFiles,MaxVolBytes,InChanger," "EndFile,EndBlock,VolParts,LabelType,StorageId,DeviceId," - "LocationId,RecycleCount,InitialWrite,ScratchPoolId,RecyclePoolId" + "LocationId,RecycleCount,InitialWrite,ScratchPoolId,RecyclePoolId, " + "Comment" " FROM Media WHERE Media.VolumeName='%s'", mdbr->VolumeName); } else { Mmsg(mdb->cmd, "SELECT MediaId,VolumeName,Slot,PoolId," @@ -160,7 +161,8 @@ db_list_media_records(JCR *jcr, B_DB *mdb, MEDIA_DBR *mdbr, "VolCapacityBytes,VolStatus,Enabled,Recycle,VolRetention," "VolUseDuration,MaxVolJobs,MaxVolFiles,MaxVolBytes,InChanger," "EndFile,EndBlock,VolParts,LabelType,StorageId,DeviceId," - "LocationId,RecycleCount,InitialWrite,ScratchPoolId,RecyclePoolId" + "LocationId,RecycleCount,InitialWrite,ScratchPoolId,RecyclePoolId, " + "Comment" " FROM Media WHERE Media.PoolId=%s ORDER BY MediaId", edit_int64(mdbr->PoolId, ed1)); } diff --git a/bacula/src/dird/run_conf.c b/bacula/src/dird/run_conf.c index b7eb4896d0..394fbe4731 100644 --- a/bacula/src/dird/run_conf.c +++ b/bacula/src/dird/run_conf.c @@ -197,10 +197,10 @@ void store_run(LEX *lc, RES_ITEM *item, int index, int pass) switch (RunFields[i].token) { case 's': /* Data spooling */ token = lex_get_token(lc, T_NAME); - if (strcasecmp(lc->str, "yes") == 0) { + if (strcasecmp(lc->str, "yes") == 0 || strcasecmp(lc->str, "true") == 0) { lrun.spool_data = true; lrun.spool_data_set = true; - } else if (strcasecmp(lc->str, "no") == 0) { + } else if (strcasecmp(lc->str, "no") == 0 || strcasecmp(lc->str, "false") == 0) { lrun.spool_data = false; lrun.spool_data_set = true; } else { @@ -209,10 +209,10 @@ void store_run(LEX *lc, RES_ITEM *item, int index, int pass) break; case 'W': /* Write part after job */ token = lex_get_token(lc, T_NAME); - if (strcasecmp(lc->str, "yes") == 0) { + if (strcasecmp(lc->str, "yes") == 0 || strcasecmp(lc->str, "true") == 0) { lrun.write_part_after_job = true; lrun.write_part_after_job_set = true; - } else if (strcasecmp(lc->str, "no") == 0) { + } else if (strcasecmp(lc->str, "no") == 0 || strcasecmp(lc->str, "false") == 0) { lrun.write_part_after_job = false; lrun.write_part_after_job_set = true; } else { diff --git a/bacula/src/dird/ua_update.c b/bacula/src/dird/ua_update.c index 2422f46a00..f8bf9c3f07 100644 --- a/bacula/src/dird/ua_update.c +++ b/bacula/src/dird/ua_update.c @@ -365,6 +365,29 @@ static void update_all_vols_from_pool(UAContext *ua) } } +static void update_volenabled(UAContext *ua, char *val, MEDIA_DBR *mr) +{ + if (strcasecmp(val, "yes") == 0 || strcasecmp(val, "true") == 0) { + mr->Enabled = 1; + } else if (strcasecmp(val, "no") == 0 || strcasecmp(val, "false") == 0) { + mr->Enabled = 0; + } else if (strcasecmp(val, "archived") == 0) { + mr->Enabled = 2; + } else { + mr->Enabled = atoi(val); + } + if (mr->Enabled < 0 || mr->Enabled > 2) { + bsendmsg(ua, _("Invalid Enabled, it must be 0, 1, or 2\n")); + return; + } + if (!db_update_media_record(ua->jcr, ua->db, mr)) { + bsendmsg(ua, _("Error updating media record Enabled: ERR=%s"), db_strerror(ua->db)); + } else { + bsendmsg(ua, _("New Enabled is: %d\n"), mr->Enabled); + } +} + + /* * Update a media record -- allows you to change the @@ -381,18 +404,19 @@ static int update_volume(UAContext *ua) bool done = false; int i; const char *kw[] = { - NT_("VolStatus"), /* 0 */ - NT_("VolRetention"), /* 1 */ - NT_("VolUse"), /* 2 */ - NT_("MaxVolJobs"), /* 3 */ - NT_("MaxVolFiles"), /* 4 */ - NT_("MaxVolBytes"), /* 5 */ - NT_("Recycle"), /* 6 */ - NT_("InChanger"), /* 7 */ - NT_("Slot"), /* 8 */ - NT_("Pool"), /* 9 */ - NT_("FromPool"), /* 10 */ - NT_("AllFromPool"), /* 11 !!! see below !!! */ + _("VolStatus"), /* 0 */ + _("VolRetention"), /* 1 */ + _("VolUse"), /* 2 */ + _("MaxVolJobs"), /* 3 */ + _("MaxVolFiles"), /* 4 */ + _("MaxVolBytes"), /* 5 */ + _("Recycle"), /* 6 */ + _("InChanger"), /* 7 */ + _("Slot"), /* 8 */ + _("Pool"), /* 9 */ + _("FromPool"), /* 10 */ + _("AllFromPool"), /* 11 !!! see below !!! */ + _("Enabled"), /* 12 */ NULL }; #define AllFromPool 11 /* keep this updated with above */ @@ -401,6 +425,7 @@ static int update_volume(UAContext *ua) int j; POOL_DBR pr; if ((j=find_arg_with_value(ua, kw[i])) > 0) { + /* If all from pool don't select a media record */ if (i != AllFromPool && !select_media_dbr(ua, &mr)) { return 0; } @@ -447,6 +472,9 @@ static int update_volume(UAContext *ua) case 11: update_all_vols_from_pool(ua); return 1; + case 12: + update_volenabled(ua, ua->argv[j], &mr); + break; } done = true; } @@ -467,11 +495,12 @@ static int update_volume(UAContext *ua) add_prompt(ua, _("Pool")); /* 10 */ add_prompt(ua, _("Volume from Pool")); /* 11 */ add_prompt(ua, _("All Volumes from Pool")); /* 12 */ - add_prompt(ua, _("Done")); /* 13 */ + add_prompt(ua, _("Enabled")), /* 13 */ + add_prompt(ua, _("Done")); /* 14 */ i = do_prompt(ua, "", _("Select parameter to modify"), NULL, 0); - /* For All Volumes from Pool we don't need a Volume record */ - if (i != 12 && i != 13) { + /* For All Volumes from Pool and Done, we don't need a Volume record */ + if (i != 12 && i != 14) { if (!select_media_dbr(ua, &mr)) { /* Get Volume record */ return 0; } @@ -621,6 +650,24 @@ static int update_volume(UAContext *ua) case 12: update_all_vols_from_pool(ua); return 1; + + case 13: + bsendmsg(ua, _("Current Enabled is: %d\n"), mr.Enabled); + if (!get_cmd(ua, _("Enter new Enabled: "))) { + return 0; + } + if (strcasecmp(ua->cmd, "yes") == 0 || strcasecmp(ua->cmd, "true") == 0) { + mr.Enabled = 1; + } else if (strcasecmp(ua->cmd, "no") == 0 || strcasecmp(ua->cmd, "false") == 0) { + mr.Enabled = 0; + } else if (strcasecmp(ua->cmd, "archived") == 0) { + mr.Enabled = 2; + } else { + mr.Enabled = atoi(ua->cmd); + } + update_volenabled(ua, ua->cmd, &mr); + break; + default: /* Done or error */ bsendmsg(ua, _("Selection terminated.\n")); return 1; diff --git a/bacula/src/filed/authenticate.c b/bacula/src/filed/authenticate.c index 556eff2e0b..0ca88dfdc7 100644 --- a/bacula/src/filed/authenticate.c +++ b/bacula/src/filed/authenticate.c @@ -59,8 +59,8 @@ static bool authenticate(int rcode, BSOCK *bs, JCR* jcr) dirname = check_pool_memory_size(dirname, bs->msglen); if (sscanf(bs->msg, "Hello Director %s calling", dirname) != 1) { - char addr[64]; - char *who = bnet_get_peer(bs, addr, sizeof(addr)) ? bs->who : addr; + char addr[64]; + char *who = bnet_get_peer(bs, addr, sizeof(addr)) ? bs->who : addr; bs->msg[100] = 0; Dmsg2(50, "Bad Hello command from Director at %s: %s\n", bs->who, bs->msg); diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index 5513b7da32..9142c8e818 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -97,15 +97,16 @@ static struct s_cmds cmds[] = { /* Commands received from director that need scanning */ static char jobcmd[] = "JobId=%d Job=%127s SDid=%d SDtime=%d Authorization=%100s"; -static char storaddr[] = "storage address=%s port=%d ssl=%d\n"; +static char storaddr[] = "storage address=%s port=%d ssl=%d"; static char sessioncmd[] = "session %127s %ld %ld %ld %ld %ld %ld\n"; static char restorecmd[] = "restore replace=%c prelinks=%d where=%s\n"; static char restorecmd1[] = "restore replace=%c prelinks=%d where=\n"; -static char verifycmd[] = "verify level=%30s\n"; -static char estimatecmd[] = "estimate listing=%d\n"; -static char runbefore[] = "RunBeforeJob %s\n"; -static char runafter[] = "RunAfterJob %s\n"; -static char runscript[] = "Run OnSuccess=%u OnFailure=%u AbortOnError=%u When=%u Command=%s\n"; +static char verifycmd[] = "verify level=%30s"; +static char estimatecmd[] = "estimate listing=%d"; +static char runbefore[] = "RunBeforeJob %s"; +static char runafter[] = "RunAfterJob %s"; +static char runscript[] = "Run OnSuccess=%u OnFailure=%u AbortOnError=%u When=%u Command=%s"; + /* Responses sent to Director */ static char errmsg[] = "2999 Invalid command\n"; static char no_auth[] = "2998 No Authorization\n"; diff --git a/bacula/src/tools/dbcheck.c b/bacula/src/tools/dbcheck.c index 66ae3858cd..d473899c36 100644 --- a/bacula/src/tools/dbcheck.c +++ b/bacula/src/tools/dbcheck.c @@ -56,7 +56,8 @@ static bool batch = false; static B_DB *db; static ID_LIST id_list; static NAME_LIST name_list; -static char buf[2000]; +static char buf[20000]; +static bool quit = false; #define MAX_ID_LIST_LEN 10000000 @@ -81,7 +82,7 @@ static void eliminate_restore_records(); static void repair_bad_paths(); static void repair_bad_filenames(); static void do_interactive_mode(); -static int yes_no(const char *prompt); +static bool yes_no(const char *prompt); static void usage() @@ -266,7 +267,6 @@ int main (int argc, char *argv[]) static void do_interactive_mode() { - bool quit = false; const char *cmd; printf(_("Hello, this is the database check/correct program.\n")); @@ -468,7 +468,7 @@ static int id_list_handler(void *ctx, int num_fields, char **row) } if (lst->num_ids == lst->max_ids) { if (lst->max_ids == 0) { - lst->max_ids = 1000; + lst->max_ids = 10000; lst->Id = (uint32_t *)bmalloc(sizeof(uint32_t) * lst->max_ids); } else { lst->max_ids = (lst->max_ids * 3) / 2; @@ -522,7 +522,7 @@ static int name_list_handler(void *ctx, int num_fields, char **row) } if (name->num_ids == name->max_ids) { if (name->max_ids == 0) { - name->max_ids = 1000; + name->max_ids = 10000; name->name = (char **)bmalloc(sizeof(char *) * name->max_ids); } else { name->max_ids = (name->max_ids * 3) / 2; @@ -590,6 +590,9 @@ static void eliminate_duplicate_filenames() if (name_list.num_ids && verbose && yes_no(_("Print the list? (yes/no): "))) { print_name_list(&name_list); } + if (quit) { + return; + } if (fix) { /* Loop through list of duplicate names */ for (int i=0; i 0) { printf(_("Deleting %d orphaned JobMedia records.\n"), id_list.num_ids); @@ -733,7 +742,9 @@ static void eliminate_orphaned_file_records() } } } - + if (quit) { + return; + } if (fix && id_list.num_ids > 0) { printf(_("Deleting %d orphaned File records.\n"), id_list.num_ids); delete_id_list("DELETE FROM File WHERE FileId=%u", &id_list); @@ -761,7 +772,9 @@ static void eliminate_orphaned_path_records() db_sql_query(db, buf, print_name_handler, NULL); } } - + if (quit) { + return; + } if (fix && id_list.num_ids > 0) { printf(_("Deleting %d orphaned Path records.\n"), id_list.num_ids); delete_id_list("DELETE FROM Path WHERE PathId=%u", &id_list); @@ -789,7 +802,9 @@ static void eliminate_orphaned_filename_records() db_sql_query(db, buf, print_name_handler, NULL); } } - + if (quit) { + return; + } if (fix && id_list.num_ids > 0) { printf(_("Deleting %d orphaned Filename records.\n"), id_list.num_ids); delete_id_list("DELETE FROM Filename WHERE FilenameId=%u", &id_list); @@ -820,7 +835,9 @@ static void eliminate_orphaned_fileset_records() } } } - + if (quit) { + return; + } if (fix && id_list.num_ids > 0) { printf(_("Deleting %d orphaned FileSet records.\n"), id_list.num_ids); delete_id_list("DELETE FROM FileSet WHERE FileSetId=%u", &id_list); @@ -858,7 +875,9 @@ static void eliminate_orphaned_client_records() } } } - + if (quit) { + return; + } if (fix && id_list.num_ids > 0) { printf(_("Deleting %d orphaned Client records.\n"), id_list.num_ids); delete_id_list("DELETE FROM Client WHERE ClientId=%u", &id_list); @@ -896,10 +915,16 @@ static void eliminate_orphaned_job_records() } } } - + if (quit) { + return; + } if (fix && id_list.num_ids > 0) { printf(_("Deleting %d orphaned Job records.\n"), id_list.num_ids); delete_id_list("DELETE FROM Job WHERE JobId=%u", &id_list); + printf(_("Deleting JobMedia records of orphaned Job records.\n")); + delete_id_list("DELETE FROM JobMedia WHERE JobId=%u", &id_list); + printf(_("Deleting Log records of orphaned Job records.\n")); + delete_id_list("DELETE FROM Log WHERE JobId=%u", &id_list); } } @@ -927,7 +952,9 @@ static void eliminate_admin_records() } } } - + if (quit) { + return; + } if (fix && id_list.num_ids > 0) { printf(_("Deleting %d Admin Job records.\n"), id_list.num_ids); delete_id_list("DELETE FROM Job WHERE JobId=%u", &id_list); @@ -957,7 +984,9 @@ static void eliminate_restore_records() } } } - + if (quit) { + return; + } if (fix && id_list.num_ids > 0) { printf(_("Deleting %d Restore Job records.\n"), id_list.num_ids); delete_id_list("DELETE FROM Job WHERE JobId=%u", &id_list); @@ -991,7 +1020,9 @@ static void repair_bad_filenames() } } } - + if (quit) { + return; + } if (fix && id_list.num_ids > 0) { POOLMEM *name = get_pool_memory(PM_FNAME); char esc_name[5000]; @@ -1049,7 +1080,9 @@ static void repair_bad_paths() } } } - + if (quit) { + return; + } if (fix && id_list.num_ids > 0) { POOLMEM *name = get_pool_memory(PM_FNAME); char esc_name[5000]; @@ -1087,17 +1120,23 @@ static char *get_cmd(const char *prompt) static char cmd[1000]; printf("%s", prompt); - if (fgets(cmd, sizeof(cmd), stdin) == NULL) + if (fgets(cmd, sizeof(cmd), stdin) == NULL) { + printf("\n"); + quit = true; return NULL; - printf("\n"); + } strip_trailing_junk(cmd); return cmd; } -static int yes_no(const char *prompt) +static bool yes_no(const char *prompt) { char *cmd; cmd = get_cmd(prompt); + if (!cmd) { + quit = true; + return false; + } return (strcasecmp(cmd, "yes") == 0) || (strcasecmp(cmd, _("yes")) == 0); }