]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
pluginlib: Metaplugin avoid saving FT_PLUGIN_CONFIG Restore Options.
authorRadosław Korzeniewski <radoslaw@korzeniewski.net>
Fri, 5 Nov 2021 11:23:22 +0000 (12:23 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:56:56 +0000 (13:56 +0200)
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.

bacula/src/plugins/fd/pluginlib/metaplugin.cpp
bacula/src/plugins/fd/pluginlib/metaplugin.h
bacula/src/plugins/fd/pluginlib/ptcomm.cpp
bacula/src/plugins/fd/pluginlib/ptcomm.h

index 46ebad105963495b1c742c1c436603bd3286f868..713da99ce7d5f391446feb700324008e12847a11 100644 (file)
@@ -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;
       }
index ce19783470cc0e61d5cebc68d1756034e7f8b682..e9889d1875a157c10bba95652952b9e11ff01105 100644 (file)
@@ -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
index b5246c4797d5eeefa0727ed66c37b36ee725fa7e..3979d139c3a2935d53233148f071342289689a45 100644 (file)
@@ -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)
index 113954190774448424759a34c30d1382581a9b84..2f5f17a315a8d63dedf954c3aab54028525bf38f 100644 (file)
@@ -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_ */