2 Bacula® - The Network Backup Solution
4 Copyright (C) 2010-2014 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from many
7 others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 Bacula® is a registered trademark of Kern Sibbald.
18 #define BUILDING_DLL /* required for Windows plugin */
21 #include "fd_plugins.h"
27 #define PLUGIN_LICENSE "AGPLv3"
28 #define PLUGIN_AUTHOR "Your name"
29 #define PLUGIN_DATE "January 2010"
30 #define PLUGIN_VERSION "1"
31 #define PLUGIN_DESCRIPTION "Test File Daemon Plugin"
33 /* Forward referenced functions */
34 static bRC newPlugin(bpContext *ctx);
35 static bRC freePlugin(bpContext *ctx);
36 static bRC getPluginValue(bpContext *ctx, pVariable var, void *value);
37 static bRC setPluginValue(bpContext *ctx, pVariable var, void *value);
38 static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value);
39 static bRC startBackupFile(bpContext *ctx, struct save_pkt *sp);
40 static bRC endBackupFile(bpContext *ctx);
41 static bRC pluginIO(bpContext *ctx, struct io_pkt *io);
42 static bRC startRestoreFile(bpContext *ctx, const char *cmd);
43 static bRC endRestoreFile(bpContext *ctx);
44 static bRC createFile(bpContext *ctx, struct restore_pkt *rp);
45 static bRC setFileAttributes(bpContext *ctx, struct restore_pkt *rp);
46 static bRC checkFile(bpContext *ctx, char *fname);
49 /* Pointers to Bacula functions */
50 static bFuncs *bfuncs = NULL;
51 static bInfo *binfo = NULL;
53 static pInfo pluginInfo = {
55 FD_PLUGIN_INTERFACE_VERSION,
64 static pFuncs pluginFuncs = {
66 FD_PLUGIN_INTERFACE_VERSION,
68 /* Entry points into plugin */
69 newPlugin, /* new plugin instance */
70 freePlugin, /* free plugin instance */
85 * Plugin called here when it is first loaded
88 loadPlugin(bInfo *lbinfo, bFuncs *lbfuncs, pInfo **pinfo, pFuncs **pfuncs)
90 bfuncs = lbfuncs; /* set Bacula funct pointers */
92 printf("plugin: Loaded: size=%d version=%d\n", bfuncs->size, bfuncs->version);
94 *pinfo = &pluginInfo; /* return pointer to our info */
95 *pfuncs = &pluginFuncs; /* return pointer to our functions */
101 * Plugin called here when it is unloaded, normally when
102 * Bacula is going to exit.
107 printf("plugin: Unloaded\n");
112 * Called here to make a new instance of the plugin -- i.e. when
113 * a new Job is started. There can be multiple instances of
114 * each plugin that are running at the same time. Your
115 * plugin instance must be thread safe and keep its own
118 static bRC newPlugin(bpContext *ctx)
121 bfuncs->getBaculaValue(ctx, bVarJobId, (void *)&JobId);
122 // printf("plugin: newPlugin JobId=%d\n", JobId);
123 bfuncs->registerBaculaEvents(ctx, 1, 2, 0);
128 * Release everything concerning a particular instance of a
129 * plugin. Normally called when the Job terminates.
131 static bRC freePlugin(bpContext *ctx)
134 bfuncs->getBaculaValue(ctx, bVarJobId, (void *)&JobId);
135 // printf("plugin: freePlugin JobId=%d\n", JobId);
140 * Called by core code to get a variable from the plugin.
141 * Not currently used.
143 static bRC getPluginValue(bpContext *ctx, pVariable var, void *value)
145 // printf("plugin: getPluginValue var=%d\n", var);
150 * Called by core code to set a plugin variable.
151 * Not currently used.
153 static bRC setPluginValue(bpContext *ctx, pVariable var, void *value)
155 // printf("plugin: setPluginValue var=%d\n", var);
160 * Called by Bacula when there are certain events that the
161 * plugin might want to know. The value depends on the
164 static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value)
168 switch (event->eventType) {
170 printf("plugin: JobStart=%s\n", NPRT((char *)value));
173 printf("plugin: JobEnd\n");
175 case bEventStartBackupJob:
176 printf("plugin: BackupStart\n");
178 case bEventEndBackupJob:
179 printf("plugin: BackupEnd\n");
182 printf("plugin: JobLevel=%c %d\n", (int64_t)value, (int64_t)value);
185 printf("plugin: since=%d\n", (int64_t)value);
187 case bEventStartRestoreJob:
188 printf("plugin: StartRestoreJob\n");
190 case bEventEndRestoreJob:
191 printf("plugin: EndRestoreJob\n");
193 /* Plugin command e.g. plugin = <plugin-name>:<name-space>:command */
194 case bEventRestoreCommand:
195 printf("plugin: backup command=%s\n", NPRT((char *)value));
197 case bEventBackupCommand:
198 printf("plugin: backup command=%s\n", NPRT((char *)value));
201 case bEventComponentInfo:
202 printf("plugin: Component=%s\n", NPRT((char *)value));
206 printf("plugin: unknown event=%d\n", event->eventType);
208 bfuncs->getBaculaValue(ctx, bVarFDName, (void *)&name);
209 // printf("FD Name=%s\n", name);
210 // bfuncs->JobMessage(ctx, __FILE__, __LINE__, 1, 0, "JobMesssage message");
211 // bfuncs->DebugMessage(ctx, __FILE__, __LINE__, 1, "DebugMesssage message");
216 * Called when starting to backup a file. Here the plugin must
217 * return the "stat" packet for the directory/file and provide
218 * certain information so that Bacula knows what the file is.
219 * The plugin can create "Virtual" files by giving them a
220 * name that is not normally found on the file system.
222 static bRC startBackupFile(bpContext *ctx, struct save_pkt *sp)
228 * Done backing up a file.
230 static bRC endBackupFile(bpContext *ctx)
236 * Do actual I/O. Bacula calls this after startBackupFile
237 * or after startRestoreFile to do the actual file
240 static bRC pluginIO(bpContext *ctx, struct io_pkt *io)
246 printf("plugin: IO_OPEN\n");
249 printf("plugin: IO_READ buf=%p len=%d\n", io->buf, io->count);
252 printf("plugin: IO_WRITE buf=%p len=%d\n", io->buf, io->count);
255 printf("plugin: IO_CLOSE\n");
261 static bRC startRestoreFile(bpContext *ctx, const char *cmd)
266 static bRC endRestoreFile(bpContext *ctx)
272 * Called here to give the plugin the information needed to
273 * re-create the file on a restore. It basically gets the
274 * stat packet that was created during the backup phase.
275 * This data is what is needed to create the file, but does
276 * not contain actual file data.
278 static bRC createFile(bpContext *ctx, struct restore_pkt *rp)
284 * Called after the file has been restored. This can be used to
285 * set directory permissions, ...
287 static bRC setFileAttributes(bpContext *ctx, struct restore_pkt *rp)
292 /* When using Incremental dump, all previous dumps are necessary */
293 static bRC checkFile(bpContext *ctx, char *fname)