From 79774c7c223b633a83ae3bc3a8e4d5054edc3cad Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Fri, 21 Apr 2006 11:25:15 +0000 Subject: [PATCH] - Implement using pg_config for finding PostgreSQL files. Fixes bug #600. Patch supplied by user. - Remove -t option from mktemp in mtx_changer.in and use working directory. Fixes bug #578. - Update job start time after the any run before job so that files created by the script are only backed up once. Fixes bug #599. - Strip trailing newline only from filenames entered in the restore command when reading a file. This permits the user to enter filenames with trailing spaces. Fixes bug #549. The user supplied a patch that I modified slightly. - Use the most recent time (st_mtime, st_ctime) in the dir command in restore. This gives the user a better idea of what the newest file really is. This fixes bug #574. The fix was suggested by the user. - Implement a compatible version of base64. This permits external programs to duplicate Bacula's base64 algorithm using standard routines. This fixes bugs #296, and 565. Patch submitted by author of bug #565. ================= Note ======================== Previous Signatures stored in the database are no longer compatible with this. The main downside is for Verify jobs, and doing an InitCatalog run will fix the problem. Also, the authentication between the deamons is changed, so all daemons must be simultaneously upgraded. ============================================== If you don't like this fix, set: const bool compatible = true; to const bool compatible = false; in src/lib/base64.c git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2952 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/autoconf/bacula-macros/db.m4 | 7 ++- bacula/kes-1.39 | 32 +++++++++++++ bacula/scripts/mtx-changer.in | 2 +- bacula/src/dird/job.c | 14 +++++- bacula/src/dird/ua_restore.c | 2 +- bacula/src/dird/ua_tree.c | 9 +++- bacula/src/dird/ua_update.c | 33 +++++++------- bacula/src/lib/base64.c | 16 +++++-- bacula/src/lib/cram-md5.c | 2 +- bacula/src/lib/md5.c | 69 +++++++++++++++++++++++++++-- bacula/src/version.h | 4 +- 11 files changed, 160 insertions(+), 30 deletions(-) diff --git a/bacula/autoconf/bacula-macros/db.m4 b/bacula/autoconf/bacula-macros/db.m4 index 8428ab8a88..f3cc016021 100644 --- a/bacula/autoconf/bacula-macros/db.m4 +++ b/bacula/autoconf/bacula-macros/db.m4 @@ -288,7 +288,12 @@ AC_ARG_WITH(postgresql, AC_MSG_ERROR("You can configure for only one database."); fi if test "$withval" = "yes"; then - if test -f /usr/local/include/libpq-fe.h; then + PG_CONFIG=`which pg_config` + if test -n "$PG_CONFIG";then + POSTGRESQL_INCDIR=`"$PG_CONFIG" --includedir` + POSTGRESQL_LIBDIR=`"$PG_CONFIG" --libdir` + POSTGRESQL_BINDIR=`"$PG_CONFIG" --bindir` + elif test -f /usr/local/include/libpq-fe.h; then POSTGRESQL_INCDIR=/usr/local/include POSTGRESQL_LIBDIR=/usr/local/lib POSTGRESQL_BINDIR=/usr/local/bin diff --git a/bacula/kes-1.39 b/bacula/kes-1.39 index 878edca5f0..e4cfdb04f1 100644 --- a/bacula/kes-1.39 +++ b/bacula/kes-1.39 @@ -2,6 +2,38 @@ Kern Sibbald General: +21Apr06 +- Implement using pg_config for finding PostgreSQL files. + Fixes bug #600. Patch supplied by user. +- Remove -t option from mktemp in mtx_changer.in and use + working directory. Fixes bug #578. +- Update job start time after the any run before job so that + files created by the script are only backed up once. Fixes + bug #599. +- Strip trailing newline only from filenames entered in + the restore command when reading a file. This permits + the user to enter filenames with trailing spaces. Fixes + bug #549. The user supplied a patch that I modified slightly. +- Use the most recent time (st_mtime, st_ctime) in the dir + command in restore. This gives the user a better idea of what + the newest file really is. This fixes bug #574. The fix + was suggested by the user. +- Implement a compatible version of base64. This permits external + programs to duplicate Bacula's base64 algorithm using standard + routines. This fixes bugs #296, and 565. Patch submitted by + author of bug #565. + ================= Note ======================== + Previous Signatures stored in the database are no longer + compatible with this. The main downside is for Verify jobs, + and doing an InitCatalog run will fix the problem. Also, the + authentication between the deamons is changed, so all daemons + must be simultaneously upgraded. + ============================================== + If you don't like this fix, set: + const bool compatible = true; + to + const bool compatible = false; + in src/lib/base64.c 20Apr06 - Ensure that DB signature is never NULL. - Ensure that DB table names are not translated. diff --git a/bacula/scripts/mtx-changer.in b/bacula/scripts/mtx-changer.in index 152bda5979..5bd399fec7 100644 --- a/bacula/scripts/mtx-changer.in +++ b/bacula/scripts/mtx-changer.in @@ -54,7 +54,7 @@ debug() { # Create a temporary file # make_temp_file() { - TMPFILE=`mktemp -t mtx.XXXXXXXXXX` + TMPFILE=`mktemp @working_dir@/mtx.XXXXXXXXXX` if test x${TMPFILE} = x; then TMPFILE="@working_dir@/mtx.$$" if test -f ${TMPFILE}; then diff --git a/bacula/src/dird/job.c b/bacula/src/dird/job.c index 280159e84a..339fb40844 100644 --- a/bacula/src/dird/job.c +++ b/bacula/src/dird/job.c @@ -265,7 +265,19 @@ static void *job_thread(void *arg) goto bail_out; } } - + /* + * We re-update the job start record so that the start + * time is set after the run before job. This avoids + * that any files created by the run before job will + * be saved twice. They will be backed up in the current + * job, but not in the next one unless they are changed. + * Without this, they will be backed up in this job and + * in the next job run because in that case, their date + * is after the start of this run. + */ + if (!db_update_job_start_record(jcr, jcr->db, &jcr->jr)) { + Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db)); + } generate_job_event(jcr, "JobRun"); switch (jcr->JobType) { diff --git a/bacula/src/dird/ua_restore.c b/bacula/src/dird/ua_restore.c index 1034e1b420..428523aa71 100644 --- a/bacula/src/dird/ua_restore.c +++ b/bacula/src/dird/ua_restore.c @@ -722,7 +722,7 @@ static bool insert_file_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *f { char ed1[50]; - strip_trailing_junk(file); + strip_trailing_newline(file); split_path_and_filename(rx, file); if (*rx->JobIds == 0) { Mmsg(rx->query, uar_jobid_fileindex, date, rx->path, rx->fname, diff --git a/bacula/src/dird/ua_tree.c b/bacula/src/dird/ua_tree.c index 4011f18a54..a406436977 100644 --- a/bacula/src/dird/ua_tree.c +++ b/bacula/src/dird/ua_tree.c @@ -472,6 +472,7 @@ static void ls_output(char *buf, const char *fname, const char *tag, char ec1[30]; char en1[30], en2[30]; int n; + time_t time; p = encode_mode(statp->st_mode, buf); if (dot_cmd) { @@ -495,7 +496,13 @@ static void ls_output(char *buf, const char *fname, const char *tag, p += n; n = sprintf(p, "%10.10s ", edit_uint64(statp->st_size, ec1)); p += n; - p = encode_time(statp->st_ctime, p); + if (statp->st_ctime > statp->st_mtime) { + time = statp->st_ctime; + } else { + time = statp->st_mtime; + } + /* Display most recent time */ + p = encode_time(time, p); *p++ = ' '; *p++ = *tag; } diff --git a/bacula/src/dird/ua_update.c b/bacula/src/dird/ua_update.c index e08705d440..ccf7db8916 100644 --- a/bacula/src/dird/ua_update.c +++ b/bacula/src/dird/ua_update.c @@ -460,28 +460,29 @@ static int update_volume(UAContext *ua) } for ( ; !done; ) { - bsendmsg(ua, _("Updating Volume \"%s\"\n"), mr.VolumeName); start_prompt(ua, _("Parameters to modify:\n")); - add_prompt(ua, _("Volume Status")); - add_prompt(ua, _("Volume Retention Period")); - add_prompt(ua, _("Volume Use Duration")); - add_prompt(ua, _("Maximum Volume Jobs")); - add_prompt(ua, _("Maximum Volume Files")); - add_prompt(ua, _("Maximum Volume Bytes")); - add_prompt(ua, _("Recycle Flag")); - add_prompt(ua, _("Slot")); - add_prompt(ua, _("InChanger Flag")); - add_prompt(ua, _("Volume Files")); - add_prompt(ua, _("Pool")); - add_prompt(ua, _("Volume from Pool")); - add_prompt(ua, _("All Volumes from Pool")); - add_prompt(ua, _("Done")); + add_prompt(ua, _("Volume Status")); /* 0 */ + add_prompt(ua, _("Volume Retention Period")); /* 1 */ + add_prompt(ua, _("Volume Use Duration")); /* 2 */ + add_prompt(ua, _("Maximum Volume Jobs")); /* 3 */ + add_prompt(ua, _("Maximum Volume Files")); /* 4 */ + add_prompt(ua, _("Maximum Volume Bytes")); /* 5 */ + add_prompt(ua, _("Recycle Flag")); /* 6 */ + add_prompt(ua, _("Slot")); /* 7 */ + add_prompt(ua, _("InChanger Flag")); /* 8 */ + add_prompt(ua, _("Volume Files")); /* 9 */ + 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 */ 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) { + if (i != 12 && i != 13) { if (!select_media_dbr(ua, &mr)) { /* Get Volume record */ return 0; } + bsendmsg(ua, _("Updating Volume \"%s\"\n"), mr.VolumeName); } switch (i) { case 0: /* Volume Status */ diff --git a/bacula/src/lib/base64.c b/bacula/src/lib/base64.c index dbfcbd60bf..b59411dfb4 100644 --- a/bacula/src/lib/base64.c +++ b/bacula/src/lib/base64.c @@ -6,7 +6,7 @@ * Version $Id$ */ /* - Copyright (C) 2000-2005 Kern Sibbald + Copyright (C) 2000-2006 Kern Sibbald This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -23,6 +23,8 @@ #include "bacula.h" +const bool compatible = true; + #ifdef TEST_MODE #include #endif @@ -141,7 +143,11 @@ bin_to_base64(char *buf, char *bin, int len) for (i=0; i\n" +" -d decode the data file\n" +" -? print this message.\n" +"\n\n"); + + exit(1); +} + +static bool decode = false; + /* * Reads a single ASCII file and prints the HEX md5 sum. */ @@ -262,16 +277,35 @@ int main(int argc, char *argv[]) MD5Context ctx; char buf[5000]; char signature[20]; + int ch; + + while ((ch = getopt(argc, argv, "d?")) != -1) { + switch (ch) { + case 'd': + decode = true; + break; + case '?': + default: + usage(); + } + } + + argc -= optind; + argv += optind; if (argc < 1) { printf("Must have filename\n"); exit(1); } - fd = fopen(argv[1], "r"); + + fd = fopen(argv[0], "r"); if (!fd) { - printf("Could not open %s: ERR=%s\n", argv[1], strerror(errno)); + printf("Could not open %s: ERR=%s\n", argv[0], strerror(errno)); exit(1); } + if (decode) { + goto decode_it; + } MD5Init(&ctx); while (fgets(buf, sizeof(buf), fd)) { MD5Update(&ctx, (unsigned char *)buf, strlen(buf)); @@ -286,6 +320,35 @@ int main(int argc, char *argv[]) bin_to_base64(MD5buf, (char *)signature, 16); /* encode 16 bytes */ printf(" %s", MD5buf); #endif - printf(" %s\n", argv[1]); + printf(" %s\n", argv[0]); + exit(0); + +decode_it: + while (fgets(buf, sizeof(buf), fd)) { + char bin[40]; + unsigned char *p = (unsigned char *)buf; + unsigned char ch; + int val; + for (int i=0; i < 16; i++) { + if (*p <= '9') { + val = *p - '0'; + } else { + val = *p - 'a' + 10; + } + ch = val << 4; + p++; + if (*p <= '9') { + val = *p - '0'; + } else { + val = *p - 'a' + 10; + } + signature[i] = ch + val; + p++; + } + signature[16] = 0; + printf("%s", buf); + bin_to_base64(bin, (char *)signature, 16); + printf("%s\n", bin); + } } #endif diff --git a/bacula/src/version.h b/bacula/src/version.h index b3097e87e5..d69c836562 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -4,8 +4,8 @@ #undef VERSION #define VERSION "1.39.9" -#define BDATE "20 April 2006" -#define LSMDATE "20Apr06" +#define BDATE "21 April 2006" +#define LSMDATE "21Apr06" /* Debug flags */ #undef DEBUG -- 2.39.5