2017-04-18 20:43:20 +02:00
|
|
|
/******************************************************
|
|
|
|
Copyright (c) 2011-2013 Percona LLC and/or its affiliates.
|
|
|
|
|
|
|
|
Data sink interface.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; version 2 of the License.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2019-05-11 21:19:05 +02:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
|
2017-04-18 20:43:20 +02:00
|
|
|
|
|
|
|
*******************************************************/
|
|
|
|
|
2017-08-21 16:57:08 +02:00
|
|
|
#include <my_global.h>
|
2017-04-18 20:43:20 +02:00
|
|
|
#include <my_base.h>
|
|
|
|
#include "common.h"
|
|
|
|
#include "datasink.h"
|
|
|
|
#include "ds_compress.h"
|
|
|
|
#include "ds_archive.h"
|
|
|
|
#include "ds_xbstream.h"
|
|
|
|
#include "ds_local.h"
|
|
|
|
#include "ds_stdout.h"
|
|
|
|
#include "ds_tmpfile.h"
|
|
|
|
#include "ds_buffer.h"
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
Create a datasink of the specified type */
|
|
|
|
ds_ctxt_t *
|
|
|
|
ds_create(const char *root, ds_type_t type)
|
|
|
|
{
|
|
|
|
datasink_t *ds;
|
|
|
|
ds_ctxt_t *ctxt;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case DS_TYPE_STDOUT:
|
|
|
|
ds = &datasink_stdout;
|
|
|
|
break;
|
|
|
|
case DS_TYPE_LOCAL:
|
|
|
|
ds = &datasink_local;
|
|
|
|
break;
|
|
|
|
case DS_TYPE_ARCHIVE:
|
2017-04-18 21:05:57 +02:00
|
|
|
#ifdef HAVE_LIBARCHIVE
|
2017-04-18 20:43:20 +02:00
|
|
|
ds = &datasink_archive;
|
2017-04-18 21:05:57 +02:00
|
|
|
#else
|
2019-01-15 22:47:54 +01:00
|
|
|
die("mariabackup was built without libarchive support");
|
2017-04-18 21:05:57 +02:00
|
|
|
#endif
|
2017-04-18 20:43:20 +02:00
|
|
|
break;
|
|
|
|
case DS_TYPE_XBSTREAM:
|
|
|
|
ds = &datasink_xbstream;
|
|
|
|
break;
|
|
|
|
case DS_TYPE_COMPRESS:
|
|
|
|
ds = &datasink_compress;
|
|
|
|
break;
|
|
|
|
case DS_TYPE_ENCRYPT:
|
2017-04-19 15:09:03 +02:00
|
|
|
case DS_TYPE_DECRYPT:
|
2019-01-15 22:47:54 +01:00
|
|
|
die("mariabackup does not support encrypted backups.");
|
2017-04-18 20:43:20 +02:00
|
|
|
break;
|
2017-04-18 21:05:57 +02:00
|
|
|
|
2017-04-18 20:43:20 +02:00
|
|
|
case DS_TYPE_TMPFILE:
|
|
|
|
ds = &datasink_tmpfile;
|
|
|
|
break;
|
|
|
|
case DS_TYPE_BUFFER:
|
|
|
|
ds = &datasink_buffer;
|
|
|
|
break;
|
|
|
|
default:
|
2019-01-14 22:28:23 +01:00
|
|
|
msg("Unknown datasink type: %d", type);
|
2017-04-18 20:43:20 +02:00
|
|
|
xb_ad(0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctxt = ds->init(root);
|
|
|
|
if (ctxt != NULL) {
|
|
|
|
ctxt->datasink = ds;
|
|
|
|
} else {
|
2019-01-15 22:47:54 +01:00
|
|
|
die("failed to initialize datasink.");
|
2017-04-18 20:43:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ctxt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
Open a datasink file */
|
|
|
|
ds_file_t *
|
|
|
|
ds_open(ds_ctxt_t *ctxt, const char *path, MY_STAT *stat)
|
|
|
|
{
|
|
|
|
ds_file_t *file;
|
|
|
|
|
|
|
|
file = ctxt->datasink->open(ctxt, path, stat);
|
|
|
|
if (file != NULL) {
|
|
|
|
file->datasink = ctxt->datasink;
|
|
|
|
}
|
|
|
|
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
Write to a datasink file.
|
|
|
|
@return 0 on success, 1 on error. */
|
|
|
|
int
|
|
|
|
ds_write(ds_file_t *file, const void *buf, size_t len)
|
|
|
|
{
|
2018-08-09 16:06:52 +02:00
|
|
|
if (len == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
2018-03-21 23:29:00 +01:00
|
|
|
return file->datasink->write(file, (const uchar *)buf, len);
|
2017-04-18 20:43:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
Close a datasink file.
|
|
|
|
@return 0 on success, 1, on error. */
|
|
|
|
int
|
|
|
|
ds_close(ds_file_t *file)
|
|
|
|
{
|
|
|
|
return file->datasink->close(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
Destroy a datasink handle */
|
|
|
|
void
|
|
|
|
ds_destroy(ds_ctxt_t *ctxt)
|
|
|
|
{
|
|
|
|
ctxt->datasink->deinit(ctxt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
Set the destination pipe for a datasink (only makes sense for compress and
|
|
|
|
tmpfile). */
|
|
|
|
void ds_set_pipe(ds_ctxt_t *ctxt, ds_ctxt_t *pipe_ctxt)
|
|
|
|
{
|
|
|
|
ctxt->pipe_ctxt = pipe_ctxt;
|
|
|
|
}
|