/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
+ Copyright (C) 2000-2008 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
* STREAM_SHA256_DIGEST
* STREAM_SHA512_DIGEST
*/
-#define STREAM_NONE 0 /* Reserved Non-Stream */
-#define STREAM_UNIX_ATTRIBUTES 1 /* Generic Unix attributes */
-#define STREAM_FILE_DATA 2 /* Standard uncompressed data */
-#define STREAM_MD5_SIGNATURE 3 /* deprecated */
-#define STREAM_MD5_DIGEST 3 /* MD5 digest for the file */
-#define STREAM_GZIP_DATA 4 /* GZip compressed file data */
+#define STREAM_NONE 0 /* Reserved Non-Stream */
+#define STREAM_UNIX_ATTRIBUTES 1 /* Generic Unix attributes */
+#define STREAM_FILE_DATA 2 /* Standard uncompressed data */
+#define STREAM_MD5_SIGNATURE 3 /* deprecated */
+#define STREAM_MD5_DIGEST 3 /* MD5 digest for the file */
+#define STREAM_GZIP_DATA 4 /* GZip compressed file data */
/* Extended Unix attributes with Win32 Extended data. Deprecated. */
-#define STREAM_UNIX_ATTRIBUTES_EX 5 /* Extended Unix attr for Win32 EX */
-#define STREAM_SPARSE_DATA 6 /* Sparse data stream */
-#define STREAM_SPARSE_GZIP_DATA 7
-#define STREAM_PROGRAM_NAMES 8 /* program names for program data */
-#define STREAM_PROGRAM_DATA 9 /* Data needing program */
-#define STREAM_SHA1_SIGNATURE 10 /* deprecated */
-#define STREAM_SHA1_DIGEST 10 /* SHA1 digest for the file */
-#define STREAM_WIN32_DATA 11 /* Win32 BackupRead data */
-#define STREAM_WIN32_GZIP_DATA 12 /* Gzipped Win32 BackupRead data */
-#define STREAM_MACOS_FORK_DATA 13 /* Mac resource fork */
-#define STREAM_HFSPLUS_ATTRIBUTES 14 /* Mac OS extra attributes */
+#define STREAM_UNIX_ATTRIBUTES_EX 5 /* Extended Unix attr for Win32 EX */
+#define STREAM_SPARSE_DATA 6 /* Sparse data stream */
+#define STREAM_SPARSE_GZIP_DATA 7
+#define STREAM_PROGRAM_NAMES 8 /* program names for program data */
+#define STREAM_PROGRAM_DATA 9 /* Data needing program */
+#define STREAM_SHA1_SIGNATURE 10 /* deprecated */
+#define STREAM_SHA1_DIGEST 10 /* SHA1 digest for the file */
+#define STREAM_WIN32_DATA 11 /* Win32 BackupRead data */
+#define STREAM_WIN32_GZIP_DATA 12 /* Gzipped Win32 BackupRead data */
+#define STREAM_MACOS_FORK_DATA 13 /* Mac resource fork */
+#define STREAM_HFSPLUS_ATTRIBUTES 14 /* Mac OS extra attributes */
/*** FIXME ***/
-#define STREAM_UNIX_ATTRIBUTES_ACCESS_ACL 15 /* Standard ACL attributes on UNIX */
-#define STREAM_UNIX_ATTRIBUTES_DEFAULT_ACL 16 /* Default ACL attributes on UNIX */
+#define STREAM_UNIX_ACCESS_ACL 15 /* Standard ACL attributes on UNIX */
+#define STREAM_UNIX_DEFAULT_ACL 16 /* Default ACL attributes on UNIX */
/*** FIXME ***/
#define STREAM_SHA256_DIGEST 17 /* SHA-256 digest for the file */
#define STREAM_SHA512_DIGEST 18 /* SHA-512 digest for the file */
# This creates an ASCII copy of the catalog
# WARNING!!! Passing the password via the command line is insecure.
# see comments in make_catalog_backup for details.
- RunBeforeJob = "@scriptdir@/make_catalog_backup bacula bacula"
+ # Arguments to make_catalog_backup are:
+ # make_catalog_backup <database-name> <user-name> <password> <host>
+ RunBeforeJob = "@scriptdir@/make_catalog_backup @db_name@ @db_user@"
# This deletes the copy of the catalog
RunAfterJob = "@scriptdir@/delete_catalog_backup"
Write Bootstrap = "@working_dir@/BackupCatalog.bsr"
if (!set_cmd_plugin(&ff_pkt->bfd, jcr)) {
goto bail_out;
}
+ send_plugin_name(jcr, sd);
}
/* Send attributes -- must be done after binit() */
if (ff_pkt->flags & FO_ACL) {
/* Read access ACLs for files, dirs and links */
- if (!read_and_send_acl(jcr, BACL_TYPE_ACCESS, STREAM_UNIX_ATTRIBUTES_ACCESS_ACL)) {
+ if (!read_and_send_acl(jcr, BACL_TYPE_ACCESS, STREAM_UNIX_ACCESS_ACL)) {
goto bail_out;
}
/* Directories can have default ACLs too */
if (ff_pkt->type == FT_DIREND && (BACL_CAP & BACL_CAP_DEFAULTS_DIR)) {
- if (!read_and_send_acl(jcr, BACL_TYPE_DEFAULT, STREAM_UNIX_ATTRIBUTES_DEFAULT_ACL)) {
+ if (!read_and_send_acl(jcr, BACL_TYPE_DEFAULT, STREAM_UNIX_DEFAULT_ACL)) {
goto bail_out;
}
}
extern int (*plugin_bclose)(JCR *jcr);
extern ssize_t (*plugin_bread)(JCR *jcr, void *buf, size_t count);
extern ssize_t (*plugin_bwrite)(JCR *jcr, void *buf, size_t count);
+extern boffset_t (*plugin_blseek)(JCR *jcr, boffset_t offset, int whence);
/* Forward referenced functions */
static int my_plugin_bclose(JCR *jcr);
static ssize_t my_plugin_bread(JCR *jcr, void *buf, size_t count);
static ssize_t my_plugin_bwrite(JCR *jcr, void *buf, size_t count);
+static boffset_t my_plugin_blseek(JCR *jcr, boffset_t offset, int whence);
/* Bacula info */
memset(&sp, 0, sizeof(sp));
sp.type = FT_REG;
sp.portable = true;
+ sp.cmd = cmd;
Dmsg0(000, "Plugin startBackup\n");
if (plug_func(plugin)->startPluginBackup(&plugin_ctx_list[i], &sp) != bRC_OK) {
goto bail_out;
}
jcr->plugin_ctx = &plugin_ctx_list[i];
jcr->plugin = plugin;
+ jcr->plugin_sp = &sp;
ff_pkt = jcr->ff;
ff_pkt->fname = sp.fname;
ff_pkt->type = sp.type;
- ff_pkt->statp = sp.statp; /* structure copy */
+ memcpy(&ff_pkt->statp, &sp.statp, sizeof(ff_pkt->statp));
Dmsg1(000, "Save_file: file=%s\n", ff_pkt->fname);
save_file(ff_pkt, (void *)jcr, true);
goto bail_out;
return;
}
+/*
+ * Send plugin name record to SD
+ */
+bool send_plugin_name(JCR *jcr, BSOCK *sd)
+{
+ int stat;
+ struct save_pkt *sp = (struct save_pkt *)jcr->plugin_sp;
+ Plugin *plugin = (Plugin *)jcr->plugin;
+ if (!sd->fsend("%ld %d 0", jcr->JobFiles, STREAM_PLUGIN_NAME)) {
+ Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
+ sd->bstrerror());
+ return false;
+ }
+ stat = sd->fsend("%ld %d %s%c%s%c", jcr->JobFiles, sp->portable, 0, plugin->file,
+ sp->cmd, 0);
+ if (!stat) {
+ Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
+ sd->bstrerror());
+ return false;
+ }
+ sd->signal(BNET_EOD); /* indicate end of plugin name data */
+ return true;
+}
+
+
void load_fd_plugins(const char *plugin_dir)
{
if (!plugin_dir) {
plugin_bclose = my_plugin_bclose;
plugin_bread = my_plugin_bread;
plugin_bwrite = my_plugin_bwrite;
+ plugin_blseek = my_plugin_blseek;
}
return (ssize_t)io.status;
}
+static boffset_t my_plugin_blseek(JCR *jcr, boffset_t offset, int whence)
+{
+ Plugin *plugin = (Plugin *)jcr->plugin;
+ bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx;
+ struct io_pkt io;
+ Dmsg0(000, "plugin_bseek\n");
+ io.func = IO_SEEK;
+ io.offset = offset;
+ io.whence = whence;
+ plug_func(plugin)->pluginIO(plugin_ctx, &io);
+ return (boffset_t)io.offset;
+}
+
/* ==============================================================
*
* Callbacks from the plugin
int (*plugin_bclose)(JCR *jcr) = NULL;
ssize_t (*plugin_bread)(JCR *jcr, void *buf, size_t count) = NULL;
ssize_t (*plugin_bwrite)(JCR *jcr, void *buf, size_t count) = NULL;
+boffset_t (*plugin_blseek)(JCR *jcr, boffset_t offset, int whence) = NULL;
int save_file(FF_PKT *ff_pkt, void *vjcr, bool top_level)
{
char *fname; /* Full path and filename */
char *link; /* Link name if any */
struct stat statp; /* System stat() packet for file */
- int type; /* FT_xx for this file */
+ int32_t type; /* FT_xx for this file */
uint32_t flags; /* Bacula internal flags */
bool portable; /* set if data format is portable */
+ char *cmd; /* command */
};
#define IO_OPEN 1
#define IO_READ 2
#define IO_WRITE 3
#define IO_CLOSE 4
+#define IO_SEEK 5
struct io_pkt {
- int func; /* Function code */
- int count; /* read/write count */
+ int32_t func; /* Function code */
+ int32_t count; /* read/write count */
char *buf; /* read/write buffer */
- int status; /* return status */
- int io_errno; /* errno code */
+ int32_t status; /* return status */
+ int32_t io_errno; /* errno code */
+ int32_t whence;
+ boffset_t offset;
};
/****************************************************************************
void new_plugins(JCR *jcr);
void free_plugins(JCR *jcr);
void generate_plugin_event(JCR *jcr, bEventType event, void *value=NULL);
+bool send_plugin_name(JCR *jcr, BSOCK *sd);
#ifdef __cplusplus
extern "C" {
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
+ Copyright (C) 2000-2008 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
* Close a bfd check that we are at the expected file offset.
* Makes some code in set_attributes().
*/
-int bclose_chksize(JCR *jcr, BFILE *bfd, boffset_t osize)
+static int bclose_chksize(JCR *jcr, BFILE *bfd, boffset_t osize)
{
char ec1[50], ec2[50];
boffset_t fsize;
#endif
break;
- case STREAM_UNIX_ATTRIBUTES_ACCESS_ACL:
+ case STREAM_UNIX_ACCESS_ACL:
if (have_acl) {
pm_strcpy(jcr->acl_text, sd->msg);
Dmsg2(400, "Restoring ACL type 0x%2x <%s>\n", BACL_TYPE_ACCESS, jcr->acl_text);
}
break;
- case STREAM_UNIX_ATTRIBUTES_DEFAULT_ACL:
+ case STREAM_UNIX_DEFAULT_ACL:
if (have_acl) {
pm_strcpy(jcr->acl_text, sd->msg);
Dmsg2(400, "Restoring ACL type 0x%2x <%s>\n", BACL_TYPE_DEFAULT, jcr->acl_text);
int (*plugin_bclose)(JCR *jcr) = NULL;
ssize_t (*plugin_bread)(JCR *jcr, void *buf, size_t count) = NULL;
ssize_t (*plugin_bwrite)(JCR *jcr, void *buf, size_t count) = NULL;
+boffset_t (*plugin_blseek)(JCR *jcr, boffset_t offset, int whence) = NULL;
#ifdef HAVE_DARWIN_OS
return _("MacOS Fork data");
case STREAM_HFSPLUS_ATTRIBUTES:
return _("HFS+ attribs");
- case STREAM_UNIX_ATTRIBUTES_ACCESS_ACL:
+ case STREAM_UNIX_ACCESS_ACL:
return _("Standard Unix ACL attribs");
- case STREAM_UNIX_ATTRIBUTES_DEFAULT_ACL:
+ case STREAM_UNIX_DEFAULT_ACL:
return _("Default Unix ACL attribs");
case STREAM_SHA256_DIGEST:
return _("SHA256 digest");
boffset_t blseek(BFILE *bfd, boffset_t offset, int whence)
{
boffset_t pos;
+
+ if (bfd->cmd_plugin && plugin_bwrite) {
+ return plugin_blseek(bfd->jcr, offset, whence);
+ }
pos = (boffset_t)lseek(bfd->fid, (off_t)offset, whence);
bfd->berrno = errno;
return pos;
void *plugin_ctx_list; /* list of contexts for plugins */
void *plugin_ctx; /* current plugin context */
void *plugin; /* plugin instance */
+ void *plugin_sp; /* plugin save packet */
/* Daemon specific part of JCR */
/* This should be empty in the library */
struct plugin_ctx {
int record;
+ boffset_t offset;
};
bRC loadPlugin(bInfo *lbinfo, bFuncs *lbfuncs, pInfo **pinfo, pFuncs **pfuncs)
printf("bpipe-fd: since=%d\n", (int)value);
break;
+ case bEventRestoreStart:
+ printf("bpipe-fd: RestoreStart\n");
+ break;
+ case bEventRestoreEnd:
+ printf("bpipe-fd: RestoreEnd\n");
+ break;
+
/* Plugin command e.g. plugin = <plugin-name>:<name-space>:command */
case bEventPluginCommand:
printf("bpipe-fd: command=%s\n", (char *)value);
static bRC startPluginBackup(bpContext *ctx, struct save_pkt *sp)
{
- static char *fname = (char *)"/BPIPE/test.txt";
+ static char *fname = (char *)"/@BPIPE/test.txt";
time_t now = time(NULL);
sp->fname = fname;
sp->statp.st_mode = 0700;
if (p_ctx->record == 0) {
strcpy(io->buf, "This is a test string.\n");
io->status = strlen(io->buf);
+ p_ctx->offset = io->status;
p_ctx->record = 1;
return bRC_OK;
}
case IO_CLOSE:
printf("bpipe-fd: IO_CLOSE\n");
break;
+ case IO_SEEK:
+ io->offset = p_ctx->offset;
+ break;
}
return bRC_OK;
}
case bEventSince:
printf("plugin: since=%d\n", (int)value);
break;
+ case bEventRestoreStart:
+ printf("bpipe-fd: RestoreStart\n");
+ break;
+ case bEventRestoreEnd:
+ printf("bpipe-fd: RestoreEnd\n");
+ break;
/* Plugin command e.g. plugin = <plugin-name>:<name-space>:command */
case bEventPluginCommand:
}
break;
- case STREAM_UNIX_ATTRIBUTES_ACCESS_ACL: /* Standard ACL attributes on UNIX */
- case STREAM_UNIX_ATTRIBUTES_DEFAULT_ACL: /* Default ACL attributes on UNIX */
+ case STREAM_UNIX_ACCESS_ACL: /* Standard ACL attributes on UNIX */
+ case STREAM_UNIX_DEFAULT_ACL: /* Default ACL attributes on UNIX */
/* Ignore Unix attributes */
break;