From: Kern Sibbald Date: Sun, 11 Apr 2010 18:59:02 +0000 (+0200) Subject: Pass restore object to plugin X-Git-Tag: Release-7.0.0~1951 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=0034cad2dd3e77a3da9ceb7a09a6e6d3eca14a6a;p=bacula%2Fbacula Pass restore object to plugin --- diff --git a/bacula/src/filed/fd_plugins.c b/bacula/src/filed/fd_plugins.c index ec18c2ca60..4f4f93a90d 100644 --- a/bacula/src/filed/fd_plugins.c +++ b/bacula/src/filed/fd_plugins.c @@ -292,16 +292,17 @@ int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level) ff_pkt->fname = fname.c_str(); ff_pkt->link = link.c_str(); ff_pkt->type = sp.type; - ff_pkt->object = sp.object; - ff_pkt->object_len = sp.object_len; if (sp.type == FT_RESTORE_FIRST) { ff_pkt->LinkFI = sp.index; /* restore object index */ + ff_pkt->object = sp.object; + ff_pkt->object_len = sp.object_len; } memcpy(&ff_pkt->statp, &sp.statp, sizeof(ff_pkt->statp)); Dmsg2(dbglvl, "startBackup returned type=%d, fname=%s\n", sp.type, sp.fname); if (sp.object) { Dmsg2(dbglvl, "index=%d object=%s\n", sp.index, sp.object); } + /* Call Bacula core code to backup the plugin's file */ save_file(jcr, ff_pkt, true); bRC rc = plug_func(plugin)->endBackupFile(jcr->plugin_ctx); if (rc == bRC_More || rc == bRC_OK) { diff --git a/bacula/src/filed/fd_plugins.h b/bacula/src/filed/fd_plugins.h index e88d77e549..7c37eaffcf 100644 --- a/bacula/src/filed/fd_plugins.h +++ b/bacula/src/filed/fd_plugins.h @@ -70,6 +70,22 @@ #include "../win32/filed/vss.h" #endif +/* + * This packet is used for the restore objects + * It is passed to the plugin when restoring + * the object. + */ +struct restore_object_pkt { + int32_t pkt_size; /* size of this packet */ + char *fname; /* Full path and filename */ + int32_t object_type; /* FT_xx for this file */ + char *object; /* restore object data to save */ + int32_t object_len; /* restore object length */ + int32_t object_index; /* restore object index */ + uint32_t JobId; /* JobId object came from */ + int32_t pkt_end; /* end packet sentinel */ +}; + /* * This packet is used for file save info transfer. */ @@ -175,6 +191,7 @@ typedef enum { bEventVssBackupAddComponents = 14, bEventVssRestoreLoadComponentMetadata = 15, bEventVssRestoreSetComponentsSelected = 16, + bEventRestoreObject = 17, } bEventType; typedef struct s_bEvent { diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index 803a080285..66bf6c9735 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -624,17 +624,21 @@ static int restore_object_cmd(JCR *jcr) { BSOCK *dir = jcr->dir_bsock; POOLMEM *msg = get_memory(dir->msglen+1); - uint32_t JobId; - int32_t object_len, object_index, object_type, FileIndex; + int32_t FileIndex; + restore_object_pkt rop; + memset(&rop, 0, sizeof(rop)); + rop.pkt_size = sizeof(rop); + rop.pkt_end = sizeof(rop); Dmsg1(100, "Enter restoreobject_cmd: %s", dir->msg); if (strcmp(dir->msg, endrestoreobjectcmd) == 0) { + generate_plugin_event(jcr, bEventRestoreObject, NULL); free_memory(msg); return dir->fsend(OKRestoreObject); } - if (sscanf(dir->msg, restoreobjcmd, &JobId, &object_len, &object_index, - &object_type, &FileIndex) != 5) { + if (sscanf(dir->msg, restoreobjcmd, &rop.JobId, &rop.object_len, + &rop.object_index, &rop.object_type, &FileIndex) != 5) { Dmsg0(5, "Bad restore object command\n"); pm_strcpy(jcr->errmsg, dir->msg); Jmsg1(jcr, M_FATAL, 0, _("Bad RestoreObject command: %s\n"), jcr->errmsg); @@ -648,6 +652,7 @@ static int restore_object_cmd(JCR *jcr) goto bail_out; } // Dmsg2(000, "Recv Fname object: len=%d Fname=%s\n", dir->msglen, dir->msg); + rop.fname = bstrdup(dir->msg); /* Read Path */ if (dir->recv() < 0) { @@ -659,8 +664,19 @@ static int restore_object_cmd(JCR *jcr) if (dir->recv() < 0) { goto bail_out; } + rop.object = dir->msg; // Dmsg2(000, "Recv Object: len=%d Object=%s\n", dir->msglen, dir->msg); + /* pass to plugin */ + generate_plugin_event(jcr, bEventRestoreObject, (void *)&rop); + + if (rop.fname) { + free(rop.fname); + } + if (!rop.object) { + dir->msg = get_pool_memory(PM_MESSAGE); + } + free_memory(msg); Dmsg1(100, "Send: %s", OKRestoreObject); return 1; diff --git a/bacula/src/plugins/fd/test-plugin-fd.c b/bacula/src/plugins/fd/test-plugin-fd.c index a09ae9e50f..8165499f1e 100644 --- a/bacula/src/plugins/fd/test-plugin-fd.c +++ b/bacula/src/plugins/fd/test-plugin-fd.c @@ -46,7 +46,7 @@ extern "C" { #endif -static const int dbglvl = 150; +static const int dbglvl = 000; #define PLUGIN_LICENSE "Bacula GPLv2" #define PLUGIN_AUTHOR "Kern Sibbald" @@ -205,6 +205,7 @@ static bRC setPluginValue(bpContext *ctx, pVariable var, void *value) static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value) { struct plugin_ctx *p_ctx = (struct plugin_ctx *)ctx->pContext; + restore_object_pkt *rop; if (!p_ctx) { return bRC_Error; } @@ -230,6 +231,16 @@ static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value) case bEventStartBackupJob: bfuncs->AddExclude(ctx, "/home/kern/bacula/regress/README"); break; + case bEventRestoreObject: + printf("Plugin RestoreObject\n"); + if (!value) { + bfuncs->DebugMessage(ctx, fi, li, dbglvl, "test-plugin-fd: End restore objects\n"); + break; + } + rop = (restore_object_pkt *)value; + bfuncs->DebugMessage(ctx, fi, li, dbglvl, "test-plugin-fd: len=%d JobId=%d fname=%s\n", + rop->object_len, rop->JobId, rop->fname); + break; /* Plugin command e.g. plugin = ::read command:write command */ case bEventRestoreCommand: /* Fall-through wanted */