From e42ec5702200d4195b643ccc1bb26abd146c1d2e Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Fri, 30 Apr 2004 07:28:02 +0000 Subject: [PATCH] Add Exclude to new FileSet git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1326 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/kernstodo | 1 + bacula/src/dird/fd_cmds.c | 176 ++++++++++++++++++++----------------- bacula/src/dird/inc_conf.c | 38 ++++---- bacula/src/filed/job.c | 52 ++++++++++- bacula/src/findlib/find.c | 3 + bacula/src/findlib/find.h | 2 + bacula/src/tools/bsmtp.c | 6 +- bacula/src/version.h | 4 +- 8 files changed, 180 insertions(+), 102 deletions(-) diff --git a/bacula/kernstodo b/bacula/kernstodo index 33dc4e148b..fa36594998 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -43,6 +43,7 @@ For 1.33 Testing/Documentation: For version 1.35: +- Max wait time or max run time causes seg fault -- see runtime-bug.txt - Document writing to a CD/DVD with Bacula. - Add check for tape alerts. - Add a "base" package to the window installer for pthreadsVCE.dll diff --git a/bacula/src/dird/fd_cmds.c b/bacula/src/dird/fd_cmds.c index c60c2d3420..27c41b68b2 100644 --- a/bacula/src/dird/fd_cmds.c +++ b/bacula/src/dird/fd_cmds.c @@ -350,98 +350,114 @@ static int send_fileset(JCR *jcr) { FILESET *fileset = jcr->fileset; BSOCK *fd = jcr->file_bsock; - int num = fileset->num_includes; - - for (int i=0; iinclude_items[i]; - bnet_fsend(fd, "I\n"); + int num; + bool include = true; - for (j=0; jnum_opts; j++) { - FOPTS *fo = ie->opts_list[j]; - bnet_fsend(fd, "O %s\n", fo->opts); - for (k=0; kregex.size(); k++) { - bnet_fsend(fd, "R %s\n", fo->regex.get(k)); - } - for (k=0; kwild.size(); k++) { - bnet_fsend(fd, "W %s\n", fo->wild.get(k)); - } - for (k=0; kbase.size(); k++) { - bnet_fsend(fd, "B %s\n", fo->base.get(k)); + for ( ;; ) { + if (include) { + num = fileset->num_includes; + } else { + num = fileset->num_excludes; + } + for (int i=0; iinclude_items[i]; + bnet_fsend(fd, "I\n"); + } else { + ie = fileset->exclude_items[i]; + bnet_fsend(fd, "E\n"); + } + for (j=0; jnum_opts; j++) { + FOPTS *fo = ie->opts_list[j]; + bnet_fsend(fd, "O %s\n", fo->opts); + for (k=0; kregex.size(); k++) { + bnet_fsend(fd, "R %s\n", fo->regex.get(k)); + } + for (k=0; kwild.size(); k++) { + bnet_fsend(fd, "W %s\n", fo->wild.get(k)); + } + for (k=0; kbase.size(); k++) { + bnet_fsend(fd, "B %s\n", fo->base.get(k)); + } + bnet_fsend(fd, "N\n"); } - bnet_fsend(fd, "N\n"); - } - for (j=0; jname_list.size(); j++) { - p = (char *)ie->name_list.get(j); - switch (*p) { - case '|': - p++; /* skip over the | */ - fd->msg = edit_job_codes(jcr, fd->msg, p, ""); - bpipe = open_bpipe(fd->msg, 0, "r"); - if (!bpipe) { - Jmsg(jcr, M_FATAL, 0, _("Cannot run program: %s. ERR=%s\n"), - p, strerror(errno)); - goto bail_out; - } - bstrncpy(buf, "F ", sizeof(buf)); - Dmsg1(100, "Opts=%s\n", buf); - optlen = strlen(buf); - while (fgets(buf+optlen, sizeof(buf)-optlen, bpipe->rfd)) { - fd->msglen = Mmsg(&fd->msg, "%s", buf); - Dmsg2(200, "Inc/exc len=%d: %s", fd->msglen, fd->msg); - if (!bnet_send(fd)) { - Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n")); + for (j=0; jname_list.size(); j++) { + p = (char *)ie->name_list.get(j); + switch (*p) { + case '|': + p++; /* skip over the | */ + fd->msg = edit_job_codes(jcr, fd->msg, p, ""); + bpipe = open_bpipe(fd->msg, 0, "r"); + if (!bpipe) { + Jmsg(jcr, M_FATAL, 0, _("Cannot run program: %s. ERR=%s\n"), + p, strerror(errno)); goto bail_out; } - } - if ((stat=close_bpipe(bpipe)) != 0) { - Jmsg(jcr, M_FATAL, 0, _("Error running program: %s. RtnStat=%d ERR=%s\n"), - p, stat, strerror(errno)); - goto bail_out; - } - break; - case '<': - p++; /* skip over < */ - if ((ffd = fopen(p, "r")) == NULL) { - Jmsg(jcr, M_FATAL, 0, _("Cannot open included file: %s. ERR=%s\n"), - p, strerror(errno)); - goto bail_out; - } - bstrncpy(buf, "F ", sizeof(buf)); - Dmsg1(100, "Opts=%s\n", buf); - optlen = strlen(buf); - while (fgets(buf+optlen, sizeof(buf)-optlen, ffd)) { - fd->msglen = Mmsg(&fd->msg, "%s", buf); + bstrncpy(buf, "F ", sizeof(buf)); + Dmsg1(100, "Opts=%s\n", buf); + optlen = strlen(buf); + while (fgets(buf+optlen, sizeof(buf)-optlen, bpipe->rfd)) { + fd->msglen = Mmsg(&fd->msg, "%s", buf); + Dmsg2(200, "Inc/exc len=%d: %s", fd->msglen, fd->msg); + if (!bnet_send(fd)) { + Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n")); + goto bail_out; + } + } + if ((stat=close_bpipe(bpipe)) != 0) { + Jmsg(jcr, M_FATAL, 0, _("Error running program: %s. RtnStat=%d ERR=%s\n"), + p, stat, strerror(errno)); + goto bail_out; + } + break; + case '<': + p++; /* skip over < */ + if ((ffd = fopen(p, "r")) == NULL) { + Jmsg(jcr, M_FATAL, 0, _("Cannot open included file: %s. ERR=%s\n"), + p, strerror(errno)); + goto bail_out; + } + bstrncpy(buf, "F ", sizeof(buf)); + Dmsg1(100, "Opts=%s\n", buf); + optlen = strlen(buf); + while (fgets(buf+optlen, sizeof(buf)-optlen, ffd)) { + fd->msglen = Mmsg(&fd->msg, "%s", buf); + if (!bnet_send(fd)) { + Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n")); + goto bail_out; + } + } + fclose(ffd); + break; + case '\\': + p++; /* skip over \ */ + /* Note, fall through wanted */ + default: + pm_strcpy(&fd->msg, "F "); + fd->msglen = pm_strcat(&fd->msg, p); + Dmsg1(100, "Inc/Exc name=%s\n", fd->msg); if (!bnet_send(fd)) { Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n")); goto bail_out; } + break; } - fclose(ffd); - break; - case '\\': - p++; /* skip over \ */ - /* Note, fall through wanted */ - default: - pm_strcpy(&fd->msg, "F "); - fd->msglen = pm_strcat(&fd->msg, p); - Dmsg1(100, "Inc/Exc name=%s\n", fd->msg); - if (!bnet_send(fd)) { - Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n")); - goto bail_out; - } - break; } + bnet_fsend(fd, "N\n"); + } + if (!include) { /* If we just did excludes */ + break; /* all done */ } - bnet_fsend(fd, "N\n"); + include = false; /* Now do excludes */ } bnet_sig(fd, BNET_EOD); /* end of data */ diff --git a/bacula/src/dird/inc_conf.c b/bacula/src/dird/inc_conf.c index 998b74e745..e99e70771b 100644 --- a/bacula/src/dird/inc_conf.c +++ b/bacula/src/dird/inc_conf.c @@ -81,27 +81,32 @@ static RES_ITEM options_items[] = { {"regex", store_regex, NULL, 0, 0, 0}, {"base", store_base, NULL, 0, 0, 0}, {"wild", store_wild, NULL, 0, 0, 0}, + {"exclude", store_opts, NULL, 0, 0, 0}, {NULL, NULL, NULL, 0, 0, 0} }; /* Define FileSet KeyWord values */ -#define INC_KW_NONE 0 -#define INC_KW_COMPRESSION 1 -#define INC_KW_SIGNATURE 2 -#define INC_KW_ENCRYPTION 3 -#define INC_KW_VERIFY 4 -#define INC_KW_ONEFS 5 -#define INC_KW_RECURSE 6 -#define INC_KW_SPARSE 7 -#define INC_KW_REPLACE 8 /* restore options */ -#define INC_KW_READFIFO 9 /* Causes fifo data to be read */ -#define INC_KW_PORTABLE 10 -#define INC_KW_MTIMEONLY 11 -#define INC_KW_KEEPATIME 12 - -/* Include keywords -- these are keywords that can appear +enum { + INC_KW_NONE, + INC_KW_COMPRESSION, + INC_KW_SIGNATURE, + INC_KW_ENCRYPTION, + INC_KW_VERIFY, + INC_KW_ONEFS, + INC_KW_RECURSE, + INC_KW_SPARSE, + INC_KW_REPLACE, /* restore options */ + INC_KW_READFIFO, /* Causes fifo data to be read */ + INC_KW_PORTABLE, + INC_KW_MTIMEONLY, + INC_KW_KEEPATIME, + INC_KW_EXCLUDE +}; + +/* + * Include keywords -- these are keywords that can appear * in the options lists of an old include ( Include = compression= ...) */ static struct s_kw FS_option_kw[] = { @@ -117,6 +122,7 @@ static struct s_kw FS_option_kw[] = { {"portable", INC_KW_PORTABLE}, {"mtimeonly", INC_KW_MTIMEONLY}, {"keepatime", INC_KW_KEEPATIME}, + {"exclude", INC_KW_EXCLUDE}, {NULL, 0} }; @@ -166,6 +172,8 @@ static struct s_fs_opt FS_options[] = { {"no", INC_KW_MTIMEONLY, "0"}, {"yes", INC_KW_KEEPATIME, "k"}, {"no", INC_KW_KEEPATIME, "0"}, + {"yes", INC_KW_EXCLUDE, "e"}, + {"no", INC_KW_EXCLUDE, "0"}, {NULL, 0, 0} }; diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index 20f49058b8..dbc02531d4 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -224,6 +224,7 @@ void *handle_client_request(void *dirp) findFILESET *fileset = ff->fileset; if (fileset) { int i, j; + /* Delete FileSet Include lists */ for (i=0; iinclude_list.size(); i++) { findINCEXE *incexe = (findINCEXE *)fileset->include_list.get(i); for (j=0; jopts_list.size(); j++) { @@ -236,6 +237,20 @@ void *handle_client_request(void *dirp) incexe->name_list.destroy(); } fileset->include_list.destroy(); + + /* Delete FileSet Exclude lists */ + for (i=0; iexclude_list.size(); i++) { + findINCEXE *incexe = (findINCEXE *)fileset->exclude_list.get(i); + for (j=0; jopts_list.size(); j++) { + findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j); + fo->regex.destroy(); + fo->wild.destroy(); + fo->base.destroy(); + } + incexe->opts_list.destroy(); + incexe->name_list.destroy(); + } + fileset->exclude_list.destroy(); free(fileset); } Dmsg0(100, "Calling term_find_files\n"); @@ -278,7 +293,10 @@ static int cancel_cmd(JCR *jcr) P(cjcr->mutex); cjcr->store_bsock->timed_out = 1; cjcr->store_bsock->terminated = 1; -#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32) +/* + * #if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32) + */ +#if !defined(HAVE_CYGWIN) pthread_kill(cjcr->my_thread_id, TIMEOUT_SIGNAL); #endif V(cjcr->mutex); @@ -563,6 +581,7 @@ static bool init_fileset(JCR *jcr) ff->fileset = fileset; fileset->state = state_none; fileset->include_list.init(1, true); + fileset->exclude_list.init(1, true); return true; } @@ -592,6 +611,7 @@ static void add_fileset(JCR *jcr, const char *item) findFILESET *fileset = ff->fileset; int state = fileset->state; findFOPTS *current_opts; + int code = item[0]; if (item[1] == ' ') { /* If string follows */ item += 2; /* point to string */ @@ -609,6 +629,14 @@ static void add_fileset(JCR *jcr, const char *item) fileset->incexe->name_list.init(1, true); fileset->include_list.append(fileset->incexe); break; + case 'E': + /* New exclude */ + fileset->incexe = (findINCEXE *)malloc(sizeof(findINCEXE)); + memset(fileset->incexe, 0, sizeof(findINCEXE)); + fileset->incexe->opts_list.init(1, true); + fileset->incexe->name_list.init(1, true); + fileset->exclude_list.append(fileset->incexe); + break; case 'N': state = state_none; break; @@ -653,6 +681,27 @@ static bool term_fileset(JCR *jcr) for (i=0; iinclude_list.size(); i++) { findINCEXE *incexe = (findINCEXE *)fileset->include_list.get(i); + Dmsg0(400, "I\n"); + for (j=0; jopts_list.size(); j++) { + findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j); + Dmsg1(400, "O %s\n", fo->opts); + for (k=0; kregex.size(); k++) { + Dmsg1(400, "R %s\n", (char *)fo->regex.get(k)); + } + for (k=0; kwild.size(); k++) { + Dmsg1(400, "W %s\n", (char *)fo->wild.get(k)); + } + for (k=0; kbase.size(); k++) { + Dmsg1(400, "B %s\n", (char *)fo->base.get(k)); + } + } + for (j=0; jname_list.size(); j++) { + Dmsg1(400, "F %s\n", (char *)incexe->name_list.get(j)); + } + } + for (i=0; iexclude_list.size(); i++) { + findINCEXE *incexe = (findINCEXE *)fileset->exclude_list.get(i); + Dmsg0(400, "E\n"); for (j=0; jopts_list.size(); j++) { findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j); Dmsg1(400, "O %s\n", fo->opts); @@ -669,7 +718,6 @@ static bool term_fileset(JCR *jcr) for (j=0; jname_list.size(); j++) { Dmsg1(400, "F %s\n", (char *)incexe->name_list.get(j)); } - } diff --git a/bacula/src/findlib/find.c b/bacula/src/findlib/find.c index 43fbca9581..45a5228d1f 100644 --- a/bacula/src/findlib/find.c +++ b/bacula/src/findlib/find.c @@ -160,6 +160,9 @@ static void set_options(FF_PKT *ff, const char *opts) case 'a': /* alway replace */ case '0': /* no option */ break; + case 'e': + ff->flags |= FO_EXCLUDE; + break; case 'f': ff->flags |= FO_MULTIFS; break; diff --git a/bacula/src/findlib/find.h b/bacula/src/findlib/find.h index 9c2ef7dbde..c3698fd29c 100755 --- a/bacula/src/findlib/find.h +++ b/bacula/src/findlib/find.h @@ -85,6 +85,7 @@ enum { #define FO_PORTABLE (1<<10) /* Use portable data format -- no BackupWrite */ #define FO_MTIMEONLY (1<<11) /* Use mtime rather than mtime & ctime */ #define FO_KEEPATIME (1<<12) /* Reset access time */ +#define FO_EXCLUDE (1<<13) /* Exclude file */ struct s_included_file { struct s_included_file *next; @@ -141,6 +142,7 @@ struct findFILESET { int state; findINCEXE *incexe; /* current item */ alist include_list; + alist exclude_list; }; diff --git a/bacula/src/tools/bsmtp.c b/bacula/src/tools/bsmtp.c index 1b4fbdc970..bee50054ab 100644 --- a/bacula/src/tools/bsmtp.c +++ b/bacula/src/tools/bsmtp.c @@ -291,15 +291,15 @@ hp: */ get_response(); /* banner */ chat("helo %s\r\n", my_hostname); - chat("mail from: <%s>\r\n", from_addr); + chat("mail from:<%s>\r\n", from_addr); for (i = 0; i < argc; i++) { Dmsg1(20, "rcpt to: %s\n", argv[i]); - chat("rcpt to: <%s>\r\n", argv[i]); + chat("rcpt to:<%s>\r\n", argv[i]); } if (cc_addr) { - chat("rcpt to: <%s>\r\n", cc_addr); + chat("rcpt to:<%s>\r\n", cc_addr); } Dmsg0(20, "Data\n"); chat("data\r\n"); diff --git a/bacula/src/version.h b/bacula/src/version.h index b0630023f4..74f16583e8 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -2,8 +2,8 @@ #undef VERSION #define VERSION "1.34.3" #define VSTRING "1" -#define BDATE "28 Apr 2004" -#define LSMDATE "28Apr04" +#define BDATE "30 Apr 2004" +#define LSMDATE "30Apr04" /* Debug flags */ #undef DEBUG -- 2.39.5