From: Radosław Korzeniewski Date: Fri, 5 Nov 2021 11:23:22 +0000 (+0100) Subject: pluginlib: Metaplugin avoid saving FT_PLUGIN_CONFIG Restore Options. X-Git-Tag: Beta-15.0.0~771 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9588109bc69813f67d7ffb9a0e348eb4830c145f;p=thirdparty%2Fbacula.git pluginlib: Metaplugin avoid saving FT_PLUGIN_CONFIG Restore Options. Add a new compile time variable: const bool DONOTSAVE_FT_PLUGIN_CONFIG = false; When `false` then Metaplugin will save plugin_items_dump[] Restore Options as usual. When `true` then save is avoided. --- diff --git a/bacula/src/plugins/fd/pluginlib/metaplugin.cpp b/bacula/src/plugins/fd/pluginlib/metaplugin.cpp index 46ebad105..713da99ce 100644 --- a/bacula/src/plugins/fd/pluginlib/metaplugin.cpp +++ b/bacula/src/plugins/fd/pluginlib/metaplugin.cpp @@ -381,9 +381,10 @@ bRC METAPLUGIN::handle_plugin_restoreobj(bpContext *ctx, restore_object_pkt *rop DMSG2(ctx, DDEBUG, "handle_plugin_restoreobj: %s %d\n", rop->object_name, rop->object_type); - // if (strcmp(rop->object_name, INI_RESTORE_OBJECT_NAME) == 0) { - if (strcmp(rop->object_name, INI_RESTORE_OBJECT_NAME) == 0 && (rop->object_type == FT_PLUGIN_CONFIG || rop->object_type == FT_PLUGIN_CONFIG_FILLED)) { - + // do not handle FT_PLUGIN_CONFIG when no one was saved by default + if (!DONOTSAVE_FT_PLUGIN_CONFIG && strcmp(rop->object_name, INI_RESTORE_OBJECT_NAME) == 0 && + (rop->object_type == FT_PLUGIN_CONFIG || rop->object_type == FT_PLUGIN_CONFIG_FILLED)) + { DMSG(ctx, DINFO, "INIcmd: %s\n", rop->plugin_name); ini.clear_items(); @@ -2252,16 +2253,19 @@ bRC METAPLUGIN::startBackupFile(bpContext *ctx, struct save_pkt *sp) return bRC_Error; } - /* The first file in Full backup, is the RestoreObject */ - if (!estimate && mode == BACKUP_FULL && pluginconfigsent == false) { - ConfigFile ini; - ini.register_items(plugin_items_dump, sizeof(struct ini_items)); - sp->restore_obj.object_name = (char *)INI_RESTORE_OBJECT_NAME; - sp->restore_obj.object_len = ini.serialize(robjbuf.handle()); - sp->restore_obj.object = robjbuf.c_str(); - sp->type = FT_PLUGIN_CONFIG; - DMSG2(ctx, DINFO, "Prepared RestoreObject/%s (%d) sent.\n", INI_RESTORE_OBJECT_NAME, FT_PLUGIN_CONFIG); - return bRC_OK; + if (!DONOTSAVE_FT_PLUGIN_CONFIG) + { + /* The first file in Full backup, is the RestoreObject */ + if (!estimate && mode == BACKUP_FULL && pluginconfigsent == false) { + ConfigFile ini; + ini.register_items(plugin_items_dump, sizeof(struct ini_items)); + sp->restore_obj.object_name = (char *)INI_RESTORE_OBJECT_NAME; + sp->restore_obj.object_len = ini.serialize(robjbuf.handle()); + sp->restore_obj.object = robjbuf.c_str(); + sp->type = FT_PLUGIN_CONFIG; + DMSG2(ctx, DINFO, "Prepared RestoreObject/%s (%d) sent.\n", INI_RESTORE_OBJECT_NAME, FT_PLUGIN_CONFIG); + return bRC_OK; + } } // check if this is the first file from backend to backup @@ -2455,9 +2459,11 @@ bRC METAPLUGIN::endBackupFile(bpContext *ctx) } } - if (!estimate){ + if (!estimate && !DONOTSAVE_FT_PLUGIN_CONFIG) + { /* The current file was the restore object, so just ask for the next file */ - if (mode == BACKUP_FULL && pluginconfigsent == false) { + if (mode == BACKUP_FULL && pluginconfigsent == false) + { pluginconfigsent = true; return bRC_More; } diff --git a/bacula/src/plugins/fd/pluginlib/metaplugin.h b/bacula/src/plugins/fd/pluginlib/metaplugin.h index ce1978347..e9889d187 100644 --- a/bacula/src/plugins/fd/pluginlib/metaplugin.h +++ b/bacula/src/plugins/fd/pluginlib/metaplugin.h @@ -60,16 +60,17 @@ extern const char *PLUGIN_VERSION; extern const char *PLUGIN_DESCRIPTION; // Plugin linking time variables -extern const char *PLUGINPREFIX; /// is used for prefixing every Job and Debug messages generted by a plugin -extern const char *PLUGINNAME; /// should match the backend $pluginname$ used for Handshake procedure -extern const bool CUSTOMNAMESPACE; /// defines if metaplugin should send `Namespace=...` backend plugin parameter using PLUGINNAMESPACE variable -extern const bool CUSTOMPREVJOBNAME; /// defines if metaplugin should send `PrevJobName=...` backend plugin parameter from bacula variable -extern const char *PLUGINNAMESPACE; /// custom backend plugin namespace used as file name prefix -extern const char *PLUGINAPI; /// the plugin api string which should match backend expectations -extern const char *BACKEND_CMD; /// a backend execution command path -extern const int32_t CUSTOMCANCELSLEEP; /// custom wait time for backend between USR1 and terminate procedures -extern const bool ACCURATEPLUGINPARAMETER; /// accurate parameter for plugin parameter -extern const int ADDINCLUDESTRIPOPTION; /// setup precompiled include path strip option +extern const char *PLUGINPREFIX; /// is used for prefixing every Job and Debug messages generted by a plugin +extern const char *PLUGINNAME; /// should match the backend $pluginname$ used for Handshake procedure +extern const bool CUSTOMNAMESPACE; /// defines if metaplugin should send `Namespace=...` backend plugin parameter using PLUGINNAMESPACE variable +extern const bool CUSTOMPREVJOBNAME; /// defines if metaplugin should send `PrevJobName=...` backend plugin parameter from bacula variable +extern const char *PLUGINNAMESPACE; /// custom backend plugin namespace used as file name prefix +extern const char *PLUGINAPI; /// the plugin api string which should match backend expectations +extern const char *BACKEND_CMD; /// a backend execution command path +extern const int32_t CUSTOMCANCELSLEEP; /// custom wait time for backend between USR1 and terminate procedures +extern const bool ACCURATEPLUGINPARAMETER; /// accurate parameter for plugin parameter +extern const int ADDINCLUDESTRIPOPTION; /// setup precompiled include path strip option +extern const bool DONOTSAVE_FT_PLUGIN_CONFIG; /// when set to `true` then Metaplugin won't save FT_PLUGIN_CONFIG as a first file during Full backup /// defines if metaplugin should handle local filesystem restore with Bacula Core functions /// `false` means metaplugin will redirect local restore to backend diff --git a/bacula/src/plugins/fd/pluginlib/ptcomm.cpp b/bacula/src/plugins/fd/pluginlib/ptcomm.cpp index b5246c479..3979d139c 100644 --- a/bacula/src/plugins/fd/pluginlib/ptcomm.cpp +++ b/bacula/src/plugins/fd/pluginlib/ptcomm.cpp @@ -79,6 +79,7 @@ void PTCOMM::terminate(bpContext *ctx) return; } + struct timeval _timeout; _timeout.tv_sec = 0; _timeout.tv_usec = 1000; @@ -151,6 +152,7 @@ bool PTCOMM::recvbackend_data(bpContext *ctx, char *buf, int32_t nbytes) { int status; int rbytes = 0; + struct timeval _timeout; _timeout.tv_sec = PTCOMM_DEFAULT_TIMEOUT; _timeout.tv_usec = 0; @@ -244,8 +246,9 @@ bool PTCOMM::sendbackend_data(bpContext *ctx, const char *buf, int32_t nbytes) { int status; int wbytes = 0; + struct timeval _timeout; - _timeout.tv_sec = PTCOMM_DEFAULT_TIMEOUT; + _timeout.tv_sec = m_timeout > 0 ? m_timeout : PTCOMM_DEFAULT_TIMEOUT; _timeout.tv_usec = 0; while (nbytes > 0) diff --git a/bacula/src/plugins/fd/pluginlib/ptcomm.h b/bacula/src/plugins/fd/pluginlib/ptcomm.h index 113954190..2f5f17a31 100644 --- a/bacula/src/plugins/fd/pluginlib/ptcomm.h +++ b/bacula/src/plugins/fd/pluginlib/ptcomm.h @@ -85,7 +85,7 @@ private: bool f_cont; // when we are reading next part of data packet */ bool abort_on_error; // abort on error flag */ int32_t remaininglen; // the number of bytes to read when `f_cont` is true - struct timeval _timeout; // a timeout when waiting for data to read from backend + uint32_t m_timeout; // a timeout when waiting for data to read from backend, in seconds protected: bool recvbackend_data(bpContext *ctx, char *buf, int32_t nbytes); @@ -115,7 +115,8 @@ public: f_fatal(false), f_cont(false), abort_on_error(false), - remaininglen(0) + remaininglen(0), + m_timeout(PTCOMM_DEFAULT_TIMEOUT) {} #if __cplusplus > 201103L PTCOMM(PTCOMM &) = delete; @@ -294,7 +295,9 @@ public: * @return true if flag is set * @return false if flag is not set */ - bool is_abort_on_error() { return abort_on_error; } + inline bool is_abort_on_error() { return abort_on_error; } + + inline void set_timeout(uint32_t timeout) { m_timeout = timeout; } }; #endif /* _PTCOMM_H_ */