2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2008 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from
7 many others, a complete list can be found in the file AUTHORS.
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version two of the GNU General Public
10 License as published by the Free Software Foundation, which is
11 listed in the file LICENSE.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 Bacula® is a registered trademark of John Walker.
24 The licensor of Bacula is the Free Software Foundation Europe
25 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 Switzerland, email:ftf@fsfeurope.org.
29 * Sample Plugin program
31 * Kern Sibbald, October 2007
35 #include "fd-plugins.h"
41 #define PLUGIN_LICENSE "GPL"
42 #define PLUGIN_AUTHOR "Kern Sibbald"
43 #define PLUGIN_DATE "January 2008"
44 #define PLUGIN_VERSION "1"
45 #define PLUGIN_DESCRIPTION "Test File Daemon Plugin"
47 /* Forward referenced functions */
48 static bRC newPlugin(bpContext *ctx);
49 static bRC freePlugin(bpContext *ctx);
50 static bRC getPluginValue(bpContext *ctx, pVariable var, void *value);
51 static bRC setPluginValue(bpContext *ctx, pVariable var, void *value);
52 static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value);
53 static bRC startBackupFile(bpContext *ctx, struct save_pkt *sp);
54 static bRC endBackupFile(bpContext *ctx);
55 static bRC pluginIO(bpContext *ctx, struct io_pkt *io);
56 static bRC startRestoreFile(bpContext *ctx, const char *cmd);
57 static bRC endRestoreFile(bpContext *ctx);
58 static bRC createFile(bpContext *ctx, struct restore_pkt *rp);
59 static bRC setFileAttributes(bpContext *ctx, struct restore_pkt *rp);
62 /* Pointers to Bacula functions */
63 static bFuncs *bfuncs = NULL;
64 static bInfo *binfo = NULL;
66 static pInfo pluginInfo = {
68 FD_PLUGIN_INTERFACE_VERSION,
77 static pFuncs pluginFuncs = {
79 FD_PLUGIN_INTERFACE_VERSION,
81 /* Entry points into plugin */
82 newPlugin, /* new plugin instance */
83 freePlugin, /* free plugin instance */
96 bRC loadPlugin(bInfo *lbinfo, bFuncs *lbfuncs, pInfo **pinfo, pFuncs **pfuncs)
98 bfuncs = lbfuncs; /* set Bacula funct pointers */
100 printf("plugin: Loaded: size=%d version=%d\n", bfuncs->size, bfuncs->version);
102 *pinfo = &pluginInfo; /* return pointer to our info */
103 *pfuncs = &pluginFuncs; /* return pointer to our functions */
110 printf("plugin: Unloaded\n");
114 static bRC newPlugin(bpContext *ctx)
117 bfuncs->getBaculaValue(ctx, bVarJobId, (void *)&JobId);
118 // printf("plugin: newPlugin JobId=%d\n", JobId);
119 bfuncs->registerBaculaEvents(ctx, 1, 2, 0);
123 static bRC freePlugin(bpContext *ctx)
126 bfuncs->getBaculaValue(ctx, bVarJobId, (void *)&JobId);
127 // printf("plugin: freePlugin JobId=%d\n", JobId);
131 static bRC getPluginValue(bpContext *ctx, pVariable var, void *value)
133 // printf("plugin: getPluginValue var=%d\n", var);
137 static bRC setPluginValue(bpContext *ctx, pVariable var, void *value)
139 // printf("plugin: setPluginValue var=%d\n", var);
143 static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value)
147 switch (event->eventType) {
149 printf("plugin: JobStart=%s\n", (char *)value);
152 printf("plugin: JobEnd\n");
154 case bEventStartBackupJob:
155 printf("plugin: BackupStart\n");
157 case bEventEndBackupJob:
158 printf("plugin: BackupEnd\n");
161 printf("plugin: JobLevel=%c %d\n", (int)value, (int)value);
164 printf("plugin: since=%d\n", (int)value);
166 case bEventStartRestoreJob:
167 printf("plugin: StartRestoreJob\n");
169 case bEventEndRestoreJob:
170 printf("plugin: EndRestoreJob\n");
173 /* Plugin command e.g. plugin = <plugin-name>:<name-space>:command */
174 case bEventRestoreCommand:
175 printf("plugin: backup command=%s\n", (char *)value);
178 case bEventBackupCommand:
179 printf("plugin: backup command=%s\n", (char *)value);
183 printf("plugin: unknown event=%d\n", event->eventType);
185 bfuncs->getBaculaValue(ctx, bVarFDName, (void *)&name);
186 // printf("FD Name=%s\n", name);
187 // bfuncs->JobMessage(ctx, __FILE__, __LINE__, 1, 0, "JobMesssage message");
188 // bfuncs->DebugMessage(ctx, __FILE__, __LINE__, 1, "DebugMesssage message");
192 static bRC startBackupFile(bpContext *ctx, struct save_pkt *sp)
197 static bRC endBackupFile(bpContext *ctx)
205 static bRC pluginIO(bpContext *ctx, struct io_pkt *io)
211 printf("plugin: IO_OPEN\n");
214 printf("plugin: IO_READ buf=%p len=%d\n", io->buf, io->count);
217 printf("plugin: IO_WRITE buf=%p len=%d\n", io->buf, io->count);
220 printf("plugin: IO_CLOSE\n");
226 static bRC startRestoreFile(bpContext *ctx, const char *cmd)
231 static bRC endRestoreFile(bpContext *ctx)
236 static bRC createFile(bpContext *ctx, struct restore_pkt *rp)
241 static bRC setFileAttributes(bpContext *ctx, struct restore_pkt *rp)