/*
Bacula(R) - The Network Backup Solution
- Copyright (C) 2000-2019 Kern Sibbald
+ Copyright © 2000-2020 Bacula Systems SA
+ All rights reserved.
The original author of Bacula is Kern Sibbald, with contributions
from many others, a complete list can be found in the file AUTHORS.
param_container_run(false),
param_container_imageid(false),
param_container_defaultnames(false),
- param_docker_host(NULL),
+ param_docker_host(PM_FNAME),
param_timeout(0),
abort_on_error(false),
f_error(false),
f_fatal(false),
ini(NULL),
- workingvolume(NULL),
- workingdir(NULL)
+ workingvolume(PM_FNAME),
+ workingdir(PM_FNAME)
{
/* setup initial plugin command here */
command = bstrdup(cmd);
release_all_pm_list(¶m_container);
release_all_pm_list(¶m_image);
release_all_pm_list(¶m_volume);
- free_and_null_pool_memory(param_docker_host);
- free_and_null_pool_memory(workingvolume);
- free_and_null_pool_memory(workingdir);
};
/*
*/
void DKCOMMCTX::setworkingdir(char* workdir)
{
- if (workingdir == NULL){
- /* not allocated yet */
- workingdir = get_pool_memory(PM_FNAME);
- }
- pm_strcpy(&workingdir, workdir);
- DMSG1(NULL, DVDEBUG, "workingdir: %s\n", workingdir);
+ pm_strcpy(workingdir, workdir);
+ DMSG1(NULL, DVDEBUG, "workingdir: %s\n", workingdir.c_str());
};
/*
pid_t pid = getpid();
DMSG0(ctx, DINFO, "prepare_working_volume called\n");
- if (workingvolume == NULL){
- workingvolume = get_pool_memory(PM_FNAME);
- /* create dir template for mkdtemp function */
- Mmsg(workingvolume, "%s/docker-%d-%d-XXXXXX",
- workingdir != NULL ? workingdir : WORKDIR, jobid, pid);
- dir = mkdtemp(workingvolume);
- if (dir == NULL){
- /* failback to standard method */
- Mmsg(workingvolume, "%s/docker-%d-%d",
- workingdir != NULL ? workingdir : WORKDIR, jobid, pid);
- if (stat(workingvolume, &statp) != 0){
- berrno be;
- /* if the path does not exist then create one */
- if (be.code() != ENOENT || mkdir(workingvolume, 0700) != 0){
- /* creation or other error, set new errno and proceed to inform user */
- be.set_errno(errno);
- DMSG2(ctx, DERROR, "working volume path (%s) creation Err=%s\n", workingvolume, be.bstrerror());
- JMSG2(ctx, abort_on_error ? M_FATAL : M_ERROR,
- "Working volume path (%s) creation Err=%s!\n", workingvolume, be.bstrerror());
- return bRC_Error;
- }
- } else
- if (!S_ISDIR(statp.st_mode)){
- /* the expected working dir/volume is already available and it is not a directory, strange */
- DMSG2(ctx, DERROR, "working volume path (%s) is not directory Mode=%o\n", workingvolume, statp.st_mode);
- JMSG2(ctx, abort_on_error ? M_FATAL : M_ERROR,
- "Working volume path (%s) is not directory Mode=%o\n", workingvolume, statp.st_mode);
- return bRC_Error;
- }
- }
+ /* create dir template for mkdtemp function */
+ const char *wd = strlen(workingdir.c_str()) > 0 ? workingdir.c_str() : WORKDIR;
+ Mmsg(workingvolume, "%s/docker-%d-%d-XXXXXX", wd, jobid, pid);
+ dir = mkdtemp(workingvolume.c_str());
+ if (dir == NULL){
+ /* failback to standard method */
+ Mmsg(workingvolume, "%s/docker-%d-%d", wd, jobid, pid);
+ if (stat(workingvolume.c_str(), &statp) != 0){
+ berrno be;
+ /* if the path does not exist then create one */
+ if (be.code() != ENOENT || mkdir(workingvolume.c_str(), 0700) != 0){
+ /* creation or other error, set new errno and proceed to inform user */
+ be.set_errno(errno);
+ DMSG2(ctx, DERROR, "working volume path (%s) creation Err=%s\n", workingvolume.c_str(), be.bstrerror());
+ JMSG2(ctx, abort_on_error ? M_FATAL : M_ERROR, "Working volume path (%s) creation Err=%s!\n", workingvolume.c_str(), be.bstrerror());
+ return bRC_Error;
+ }
+ } else
+ if (!S_ISDIR(statp.st_mode)){
+ /* the expected working dir/volume is already available and it is not a directory, strange */
+ DMSG2(ctx, DERROR, "working volume path (%s) is not directory mode=%o\n", workingvolume.c_str(), statp.st_mode);
+ JMSG2(ctx, abort_on_error ? M_FATAL : M_ERROR,
+ "Working volume path (%s) is not directory mode=%o\n", workingvolume.c_str(), statp.st_mode);
+ return bRC_Error;
+ }
}
- DMSG1(ctx, DINFO, "prepare_working_volume finish: %s\n", workingvolume);
+
+ DMSG1(ctx, DINFO, "prepare_working_volume finish: %s\n", workingvolume.c_str());
return bRC_OK;
};
DMSG1(ctx, DDEBUG, "removing: %s\n", fname.c_str())
}
if (!ferr){
- status = rmdir(workingvolume);
+ status = rmdir(workingvolume.c_str());
if (status < 0){
/* unlink error - report to user */
berrno be;
- DMSG2(ctx, DERROR, "rmdir error: %s Err=%s\n", workingvolume, be.bstrerror());
- JMSG2(ctx, M_ERROR, "Cannot remove directory: %s Err=%s\n", workingvolume, be.bstrerror());
+ DMSG2(ctx, DERROR, "rmdir error: %s Err=%s\n", workingvolume.c_str(), be.bstrerror());
+ JMSG2(ctx, M_ERROR, "Cannot remove directory: %s Err=%s\n", workingvolume.c_str(), be.bstrerror());
}
}
- free_and_null_pool_memory(workingvolume);
+ pm_strcpy(workingvolume, NULL);
DMSG0(ctx, DDEBUG, "clean_working_volume finish.\n");
};
DMSG(ctx, DINFO, "Executing: %s\n", exe_cmd.c_str());
/* preparing envinroment variables */
envp[a++] = bstrdup("LANG=C");
- if (param_docker_host != NULL){
- Mmsg(DH, "DOCKER_HOST=%s", param_docker_host);
+ if (strlen(param_docker_host.c_str()) > 0)
+ {
+ Mmsg(DH, "DOCKER_HOST=%s", param_docker_host.c_str());
envp[a++] = bstrdup(DH.c_str());
}
envp[a] = NULL;
return wbytes;
}
-/*
- * Render a command tool parameter for string value.
- *
- * in:
- * bpContext - for Bacula debug and jobinfo messages
- * param - a pointer to the param variable where we will render a parameter
- * pname - a name of the parameter to compare
- * fmt - a low-level parameter name
- * name - a name of the parameter from parameter list
- * value - a value to render
- * out:
- * True if parameter was rendered
- * False if it was not the parameter required
- */
-bool DKCOMMCTX::render_param(bpContext *ctx, POOLMEM **param, const char *pname, const char *fmt, const char *name, char *value)
-{
- if (bstrcasecmp(name, pname)){
- if (!*param){
- *param = get_pool_memory(PM_NAME);
- Mmsg(*param, " -%s '%s' ", fmt, value);
- DMSG(ctx, DDEBUG, "render param:%s\n", *param);
- }
- return true;
- }
- return false;
-}
-
-/*
- * Render a command tool parameter for integer value.
- *
- * in:
- * bpContext - for Bacula debug and jobinfo messages
- * param - a pointer to the param variable where we will render a parameter
- * pname - a name of the parameter to compare
- * fmt - a low-level parameter name
- * name - a name of the parameter from parameter list
- * value - a value to render
- * out:
- * True if parameter was rendered
- * False if it was not the parameter required
- */
-bool DKCOMMCTX::render_param(bpContext *ctx, POOLMEM **param, const char *pname, const char *fmt, const char *name, int value)
-{
- if (bstrcasecmp(name, pname)){
- if (!*param){
- *param = get_pool_memory(PM_NAME);
- Mmsg(*param, " -%s %d ", value);
- DMSG(ctx, DDEBUG, "render param:%s\n", *param);
- }
- return true;
- }
- return false;
-}
-
-/*
- * Render a command tool parameter for string value.
- *
- * in:
- * bpContext - for Bacula debug and jobinfo messages
- * param - a pointer to the param variable where we will render a parameter
- * pname - a name of the parameter to compare
- * name - a name of the parameter from parameter list
- * value - a value to render
- * out:
- * True if parameter was rendered
- * False if it was not the parameter required
- */
-bool DKCOMMCTX::render_param(bpContext *ctx, POOLMEM **param, const char *pname, const char *name, char *value)
-{
- if (bstrcasecmp(name, pname)){
- if (!*param){
- *param = get_pool_memory(PM_NAME);
- Mmsg(*param, "%s", value);
- DMSG(ctx, DDEBUG, "render param:%s\n", *param);
- }
- return true;
- }
- return false;
-}
-
-/*
- * Setup DKCOMMCTX parameter for boolean value.
- *
- * in:
- * bpContext - for Bacula debug and jobinfo messages
- * param - a pointer to the param variable where we will render a parameter
- * pname - a name of the parameter to compare
- * name - a name of the parameter from parameter list
- * value - a value to render
- * out:
- * True if parameter was rendered
- * False if it was not the parameter required
- */
-bool DKCOMMCTX::render_param(bpContext *ctx, bool *param, const char *pname, const char *name, bool value)
-{
- if (bstrcasecmp(name, pname)){
- if (param){
- *param = value;
- DMSG2(ctx, DDEBUG, "render param: %s=%s\n", pname, *param ? "True" : "False");
- }
- return true;
- }
- return false;
-}
-
-/*
- * Setup DKCOMMCTX parameter for int32_t value.
- *
- * in:
- * bpContext - for Bacula debug and jobinfo messages
- * param - a pointer to the param variable where we will render a parameter
- * pname - a name of the parameter to compare
- * name - a name of the parameter from parameter list
- * value - a value to render
- * out:
- * True if parameter was rendered
- * False if it was not the parameter required
- */
-bool DKCOMMCTX::render_param(bpContext *ctx, int32_t *param, const char *pname, const char *name, int32_t value)
-{
- if (bstrcasecmp(name, pname)){
- if (param){
- *param = value;
- DMSG2(ctx, DDEBUG, "render param: %s=%d\n", pname, *param);
- }
- return true;
- }
- return false;
-}
-
-/*
- * Setup DKCOMMCTX parameter for boolean from string value.
- * The parameter value will be false if value start with '0' character and
- * will be true in any other case. So, when a plugin will have a following:
- * param
- * param=...
- * param=1
- * then a param will be set to true.
- *
- * in:
- * bpContext - for Bacula debug and jobinfo messages
- * param - a pointer to the param variable where we will render a parameter
- * pname - a name of the parameter to compare
- * name - a name of the parameter from parameter list
- * value - a value to render
- * out:
- * True if parameter was rendered
- * False if it was not the parameter required
- */
-bool DKCOMMCTX::parse_param(bpContext *ctx, bool *param, const char *pname, const char *name, char *value)
-{
- if (bstrcasecmp(name, pname)){
- if (value && *value == '0'){
- *param = false;
- } else {
- *param = true;
- }
- DMSG2(ctx, DINFO, "%s parameter: %s\n", name, *param ? "True" : "False");
- return true;
- }
- return false;
-}
-
-/*
- * Setup DKCOMMCTX parameter for integer from string value.
- *
- * in:
- * bpContext - for Bacula debug and jobinfo messages
- * param - a pointer to the param variable where we will render a parameter
- * pname - a name of the parameter to compare
- * name - a name of the parameter from parameter list
- * value - a value to render
- * out:
- * True if parameter was rendered
- * False if it was not the parameter required
- */
-bool DKCOMMCTX::parse_param(bpContext *ctx, int32_t *param, const char *pname, const char *name, char *value)
-{
- if (value && bstrcasecmp(name, pname)){
- /* convert str to integer */
- *param = atoi(value);
- if (*param == 0){
- /* error in conversion */
- f_error = true;
- DMSG2(ctx, DERROR, "Invalid %s parameter: %s\n", name, value);
- JMSG2(ctx, M_ERROR, "Invalid %s parameter: %s\n", name, value);
- return false;
- }
- DMSG2(ctx, DINFO, "%s parameter: %d\n", name, *param);
- return true;
- }
- return false;
-}
+// /*
+// * Render a command tool parameter for string value.
+// *
+// * in:
+// * bpContext - for Bacula debug and jobinfo messages
+// * param - a pointer to the param variable where we will render a parameter
+// * pname - a name of the parameter to compare
+// * fmt - a low-level parameter name
+// * name - a name of the parameter from parameter list
+// * value - a value to render
+// * out:
+// * True if parameter was rendered
+// * False if it was not the parameter required
+// */
+// bool DKCOMMCTX::render_param(bpContext *ctx, POOLMEM **param, const char *pname, const char *fmt, const char *name, char *value)
+// {
+// if (bstrcasecmp(name, pname)){
+// if (!*param){
+// *param = get_pool_memory(PM_NAME);
+// Mmsg(*param, " -%s '%s' ", fmt, value);
+// DMSG(ctx, DDEBUG, "render param:%s\n", *param);
+// }
+// return true;
+// }
+// return false;
+// }
+
+// /*
+// * Render a command tool parameter for integer value.
+// *
+// * in:
+// * bpContext - for Bacula debug and jobinfo messages
+// * param - a pointer to the param variable where we will render a parameter
+// * pname - a name of the parameter to compare
+// * fmt - a low-level parameter name
+// * name - a name of the parameter from parameter list
+// * value - a value to render
+// * out:
+// * True if parameter was rendered
+// * False if it was not the parameter required
+// */
+// bool DKCOMMCTX::render_param(bpContext *ctx, POOLMEM **param, const char *pname, const char *fmt, const char *name, int value)
+// {
+// if (bstrcasecmp(name, pname)){
+// if (!*param){
+// *param = get_pool_memory(PM_NAME);
+// Mmsg(*param, " -%s %d ", value);
+// DMSG(ctx, DDEBUG, "render param:%s\n", *param);
+// }
+// return true;
+// }
+// return false;
+// }
+
+// /*
+// * Render a command tool parameter for string value.
+// *
+// * in:
+// * bpContext - for Bacula debug and jobinfo messages
+// * param - a pointer to the param variable where we will render a parameter
+// * pname - a name of the parameter to compare
+// * name - a name of the parameter from parameter list
+// * value - a value to render
+// * out:
+// * True if parameter was rendered
+// * False if it was not the parameter required
+// */
+// bool DKCOMMCTX::render_param(bpContext *ctx, POOLMEM **param, const char *pname, const char *name, char *value)
+// {
+// if (bstrcasecmp(name, pname)){
+// if (!*param){
+// *param = get_pool_memory(PM_NAME);
+// Mmsg(*param, "%s", value);
+// DMSG(ctx, DDEBUG, "render param:%s\n", *param);
+// }
+// return true;
+// }
+// return false;
+// }
+
+// /*
+// * Setup DKCOMMCTX parameter for boolean value.
+// *
+// * in:
+// * bpContext - for Bacula debug and jobinfo messages
+// * param - a pointer to the param variable where we will render a parameter
+// * pname - a name of the parameter to compare
+// * name - a name of the parameter from parameter list
+// * value - a value to render
+// * out:
+// * True if parameter was rendered
+// * False if it was not the parameter required
+// */
+// bool DKCOMMCTX::render_param(bpContext *ctx, bool *param, const char *pname, const char *name, bool value)
+// {
+// if (bstrcasecmp(name, pname)){
+// if (param){
+// *param = value;
+// DMSG2(ctx, DDEBUG, "render param: %s=%s\n", pname, *param ? "True" : "False");
+// }
+// return true;
+// }
+// return false;
+// }
+
+// /*
+// * Setup DKCOMMCTX parameter for int32_t value.
+// *
+// * in:
+// * bpContext - for Bacula debug and jobinfo messages
+// * param - a pointer to the param variable where we will render a parameter
+// * pname - a name of the parameter to compare
+// * name - a name of the parameter from parameter list
+// * value - a value to render
+// * out:
+// * True if parameter was rendered
+// * False if it was not the parameter required
+// */
+// bool DKCOMMCTX::render_param(bpContext *ctx, int32_t *param, const char *pname, const char *name, int32_t value)
+// {
+// if (bstrcasecmp(name, pname)){
+// if (param){
+// *param = value;
+// DMSG2(ctx, DDEBUG, "render param: %s=%d\n", pname, *param);
+// }
+// return true;
+// }
+// return false;
+// }
+
+// /*
+// * Setup DKCOMMCTX parameter for boolean from string value.
+// * The parameter value will be false if value start with '0' character and
+// * will be true in any other case. So, when a plugin will have a following:
+// * param
+// * param=...
+// * param=1
+// * then a param will be set to true.
+// *
+// * in:
+// * bpContext - for Bacula debug and jobinfo messages
+// * param - a pointer to the param variable where we will render a parameter
+// * pname - a name of the parameter to compare
+// * name - a name of the parameter from parameter list
+// * value - a value to render
+// * out:
+// * True if parameter was rendered
+// * False if it was not the parameter required
+// */
+// bool DKCOMMCTX::parse_param(bpContext *ctx, bool *param, const char *pname, const char *name, char *value)
+// {
+// if (bstrcasecmp(name, pname)){
+// if (value && *value == '0'){
+// *param = false;
+// } else {
+// *param = true;
+// }
+// DMSG2(ctx, DINFO, "%s parameter: %s\n", name, *param ? "True" : "False");
+// return true;
+// }
+// return false;
+// }
+
+// /*
+// * Setup DKCOMMCTX parameter for integer from string value.
+// *
+// * in:
+// * bpContext - for Bacula debug and jobinfo messages
+// * param - a pointer to the param variable where we will render a parameter
+// * pname - a name of the parameter to compare
+// * name - a name of the parameter from parameter list
+// * value - a value to render
+// * out:
+// * True if parameter was rendered
+// * False if it was not the parameter required
+// */
+// bool DKCOMMCTX::parse_param(bpContext *ctx, int32_t *param, const char *pname, const char *name, char *value)
+// {
+// if (value && bstrcasecmp(name, pname)){
+// /* convert str to integer */
+// *param = atoi(value);
+// if (*param == 0){
+// /* error in conversion */
+// f_error = true;
+// DMSG2(ctx, DERROR, "Invalid %s parameter: %s\n", name, value);
+// JMSG2(ctx, M_ERROR, "Invalid %s parameter: %s\n", name, value);
+// return false;
+// }
+// DMSG2(ctx, DINFO, "%s parameter: %d\n", name, *param);
+// return true;
+// }
+// return false;
+// }
/*
* Setup DKCOMMCTX parameter for DOCKER_BACKUP_MODE_T from string value.
* True if parameter was rendered
* False if it was not the parameter required
*/
-bool DKCOMMCTX::parse_param(bpContext *ctx, DOCKER_BACKUP_MODE_T *param, const char *pname, const char *name, char *value)
+bool DKCOMMCTX::parse_param_mode(bpContext *ctx, DOCKER_BACKUP_MODE_T *param, const char *pname, const char *name, char *value)
{
if (bstrcasecmp(name, pname)){
if (value){
return false;
}
-/*
- * Render and add a parameter for string value to alist.
- * When alist is NULL (uninitialized) then it creates a new list to use.
- *
- * in:
- * bpContext - for Bacula debug and jobinfo messages
- * list - pointer to alist class to use
- * pname - a name of the parameter to compare
- * name - a name of the parameter from parameter list
- * value - a value to render
- * out:
- * True if parameter was rendered
- * False if it was not the parameter required
- */
-bool DKCOMMCTX::add_param_str(bpContext *ctx, alist **list, const char *pname, const char *name, char *value)
-{
- POOLMEM *param;
-
- if (bstrcasecmp(name, pname)){
- if (!*list){
- *list = New(alist(8, not_owned_by_alist));
- }
- param = get_pool_memory(PM_NAME);
- Mmsg(param, "%s", value);
- (*list)->append(param);
- DMSG2(ctx, DDEBUG, "add param: %s=%s\n", name, value);
- return true;
- }
- return false;
-}
-
-/*
- * Render and set a parameter for string value.
- * When param is NULL (uninitialized) then it allocates a new string.
- *
- * in:
- * bpContext - for Bacula debug and jobinfo messages
- * list - pointer to alist class to use
- * pname - a name of the parameter to compare
- * name - a name of the parameter from parameter list
- * value - a value to render
- * out:
- * True if parameter was rendered
- * False if it was not the parameter required
- */
-bool DKCOMMCTX::parse_param(bpContext *ctx, POOLMEM **param, const char *pname, const char *name, char *value)
-{
- if (bstrcasecmp(name, pname)){
- if (!*param){
- *param = get_pool_memory(PM_NAME);
- }
- pm_strcpy(param, value);
- DMSG2(ctx, DDEBUG, "add param: %s=%s\n", name, value);
- return true;
- }
- return false;
-}
+// /*
+// * Render and add a parameter for string value to alist.
+// * When alist is NULL (uninitialized) then it creates a new list to use.
+// *
+// * in:
+// * bpContext - for Bacula debug and jobinfo messages
+// * list - pointer to alist class to use
+// * pname - a name of the parameter to compare
+// * name - a name of the parameter from parameter list
+// * value - a value to render
+// * out:
+// * True if parameter was rendered
+// * False if it was not the parameter required
+// */
+// bool DKCOMMCTX::add_param_str(bpContext *ctx, alist **list, const char *pname, const char *name, char *value)
+// {
+// POOLMEM *param;
+
+// if (bstrcasecmp(name, pname)){
+// if (!*list){
+// *list = New(alist(8, not_owned_by_alist));
+// }
+// param = get_pool_memory(PM_NAME);
+// Mmsg(param, "%s", value);
+// (*list)->append(param);
+// DMSG2(ctx, DDEBUG, "add param: %s=%s\n", name, value);
+// return true;
+// }
+// return false;
+// }
+
+// /*
+// * Render and set a parameter for string value.
+// * When param is NULL (uninitialized) then it allocates a new string.
+// *
+// * in:
+// * bpContext - for Bacula debug and jobinfo messages
+// * list - pointer to alist class to use
+// * pname - a name of the parameter to compare
+// * name - a name of the parameter from parameter list
+// * value - a value to render
+// * out:
+// * True if parameter was rendered
+// * False if it was not the parameter required
+// */
+// bool DKCOMMCTX::parse_param(bpContext *ctx, POOLMEM **param, const char *pname, const char *name, char *value)
+// {
+// if (bstrcasecmp(name, pname)){
+// if (!*param){
+// *param = get_pool_memory(PM_NAME);
+// }
+// pm_strcpy(param, value);
+// DMSG2(ctx, DDEBUG, "add param: %s=%s\n", name, value);
+// return true;
+// }
+// return false;
+// }
/*
* Parse a restore plugin parameters for DKCOMMCTX class (single at a time).
void DKCOMMCTX::parse_parameters(bpContext *ctx, ini_items &item)
{
/* container_create variable */
- if (render_param(ctx, ¶m_container_create, "container_create", item.name, item.val.boolval)){
+ if (setup_param(param_container_create, "container_create", item.name, item.val.boolval)){
return;
}
/* container_create variable */
- if (render_param(ctx, ¶m_container_run, "container_run", item.name, item.val.boolval)){
+ if (setup_param(param_container_run, "container_run", item.name, item.val.boolval)){
return;
}
/* container_create variable */
- if (render_param(ctx, ¶m_container_imageid, "container_imageid", item.name, item.val.boolval)){
+ if (setup_param(param_container_imageid, "container_imageid", item.name, item.val.boolval)){
return;
}
/* container_create variable */
- if (render_param(ctx, ¶m_container_defaultnames, "container_defaultnames", item.name, item.val.boolval)){
+ if (setup_param(param_container_defaultnames, "container_defaultnames", item.name, item.val.boolval)){
return;
}
/* docker_host variable */
- if (render_param(ctx, ¶m_docker_host, "docker_host", item.name, item.val.strval)){
+ if (setup_param(param_docker_host, "docker_host", item.name, item.val.strval)){
return;
}
/* timeout variable */
- if (render_param(ctx, ¶m_timeout, "timeout", item.name, item.val.int32val)){
+ if (setup_param(param_timeout, "timeout", item.name, item.val.int32val)){
return;
}
f_error = true;
bRC DKCOMMCTX::parse_parameters(bpContext *ctx, char *argk, char *argv)
{
/* check abort_on_error parameter */
- if (parse_param(ctx, &abort_on_error, "abort_on_error", argk, argv)){
+ if (parse_param(abort_on_error, "abort_on_error", argk, argv)){
return bRC_OK;
}
/* check allvolumes parameter */
- if (parse_param(ctx, &all_vols_to_backup, "allvolumes", argk, argv)){
+ if (parse_param(all_vols_to_backup, "allvolumes", argk, argv)){
return bRC_OK;
}
/* check and handle container list */
- if (add_param_str(ctx, ¶m_container, "container", argk, argv)){
+ if (parse_param_add_str(¶m_container, "container", argk, argv)){
return bRC_OK;
}
/* check and handle include_container list */
- if (add_param_str(ctx, ¶m_include_container, "include_container", argk, argv)){
+ if (parse_param_add_str(¶m_include_container, "include_container", argk, argv)){
return bRC_OK;
}
/* check and handle exclude_container list */
- if (add_param_str(ctx, ¶m_exclude_container, "exclude_container", argk, argv)){
+ if (parse_param_add_str(¶m_exclude_container, "exclude_container", argk, argv)){
return bRC_OK;
}
/* check and handle image list */
- if (add_param_str(ctx, ¶m_image, "image", argk, argv)){
+ if (parse_param_add_str(¶m_image, "image", argk, argv)){
return bRC_OK;
}
/* check and handle include_image list */
- if (add_param_str(ctx, ¶m_include_image, "include_image", argk, argv)){
+ if (parse_param_add_str(¶m_include_image, "include_image", argk, argv)){
return bRC_OK;
}
/* check and handle exclude_image list */
- if (add_param_str(ctx, ¶m_exclude_image, "exclude_image", argk, argv)){
+ if (parse_param_add_str(¶m_exclude_image, "exclude_image", argk, argv)){
return bRC_OK;
}
/* check and handle volume list */
- if (add_param_str(ctx, ¶m_volume, "volume", argk, argv)){
+ if (parse_param_add_str(¶m_volume, "volume", argk, argv)){
return bRC_OK;
}
/* check and handle timeout parameter */
- if (parse_param(ctx, ¶m_timeout, "timeout", argk, argv)){
+ if (parse_param(param_timeout, "timeout", argk, argv)){
return bRC_OK;
}
/* check mode parameter */
- if (parse_param(ctx, ¶m_mode, "mode", argk, argv)){
+ if (parse_param_mode(ctx, ¶m_mode, "mode", argk, argv)){
return bRC_OK;
}
/* check docker_host parameter */
- if (parse_param(ctx, ¶m_docker_host, "docker_host", argk, argv)){
+ if (parse_param(param_docker_host, "docker_host", argk, argv)){
return bRC_OK;
}
found = false;
foreach_alist(dkinfo, dklist){
DMSG3(ctx, DDEBUG, "compare: %s/%s vs %s\n",
- (char*)dkinfo->id(), dkinfo->name(), pobj);
+ (char*)*dkinfo->id(), dkinfo->name(), pobj);
/* we have to check container id or container names */
dkid = pobj;
if (bstrcmp(pobj, dkinfo->name()) || dkid == *(dkinfo->id())
found = true;
DMSG3(ctx, DINFO, "adding %s to backup (1): %s (%s)\n",
dkinfo->type_str(),
- dkinfo->name(), (char*)dkinfo->id());
+ dkinfo->name(), (char*)*dkinfo->id());
break;
};
};
objs_to_backup->append(dkinfo);
DMSG3(ctx, DINFO, "adding %s to backup (2): %s (%s)\n",
dkinfo->type_str(),
- dkinfo->name(), (char*)dkinfo->id());
+ dkinfo->name(), (char*)*dkinfo->id());
};
}
};
return bRC_Error;
}
/* when docker_host defined then skip all volumes */
- if (param_docker_host == NULL && !get_all_volumes(ctx)){
+ if (strlen(param_docker_host.c_str()) == 0 && !get_all_volumes(ctx)){
return bRC_Error;
}
/* find all objects on param_* lists */
filter_param_to_backup(ctx, param_container, all_containers, estimate);
filter_param_to_backup(ctx, param_image, all_images, estimate);
- if (param_volume && param_docker_host == NULL){
+ if (param_volume && strlen(param_docker_host.c_str()) == 0){
filter_param_to_backup(ctx, param_volume, all_volumes, estimate);
}
filter_incex_to_backup(ctx, param_include_image, param_exclude_image, all_images);
/* handle allvolumes for containers backup */
- if (all_vols_to_backup && param_docker_host == NULL){
+ if (all_vols_to_backup && strlen(param_docker_host.c_str()) == 0){
add_container_volumes_to_backup(ctx);
}
/* generate a warning message if required */
- if ((param_volume || all_vols_to_backup) && param_docker_host){
+ if ((param_volume || all_vols_to_backup) && strlen(param_docker_host.c_str()) > 0){
DMSG0(ctx, DINFO, "Docker Volume backup with docker_host is unsupported!\n");
JMSG0(ctx, M_WARNING, "Docker Volume backup with docker_host is unsupported!\n");
}
dkinfo->scan_container_size(paramtab[2]);
dkinfo->set_container_mounts(paramtab[3]);
DMSG3(ctx, DINFO, "setup_container_dkinfo: %s %s %d\n",
- (char*)dkinfo->get_container_id(), dkinfo->get_container_names(), dkinfo->get_container_size());
+ (char*)*dkinfo->get_container_id(), dkinfo->get_container_names(), dkinfo->get_container_size());
DMSG1(ctx, DINFO, "setup_container_dkinfo: %s\n", dkinfo->get_container_mounts());
};
dkinfo->scan_image_size(paramtab[3]);
dkinfo->set_image_created(str_to_utime(paramtab[4]));
DMSG3(ctx, DINFO, "setup_image_dkinfo: %s %s : %s\n",
- (char*)dkinfo->get_image_id(), dkinfo->get_image_repository(), dkinfo->get_image_tag());
+ (char*)*dkinfo->get_image_id(), dkinfo->get_image_repository(), dkinfo->get_image_tag());
DMSG2(ctx, DINFO, "setup_image_dkinfo: %d %ld\n", dkinfo->get_image_size(), dkinfo->get_image_created());
};
setup_dkinfo(ctx, type, paramtab, dkinfo);
(*dklist)->append(dkinfo);
if (dkinfo->type() != DOCKER_VOLUME){
- DMSG3(ctx, DDEBUG, "found %s: %s -> %s\n", dkinfo->type_str(), (char*)dkinfo->id(), dkinfo->name());
+ DMSG3(ctx, DDEBUG, "found %s: %s -> %s\n", dkinfo->type_str(), (char*)*dkinfo->id(), dkinfo->name());
} else {
DMSG2(ctx, DDEBUG, "found %s: %s\n", dkinfo->type_str(), dkinfo->name());
}
}
// commit -p 66f45d8601bae26a6b2ffeb46922318534d3b3905377b3a224693bd78601cb3b mcache1/66f45d8601ba:backup
render_imagesave_name(imagename, dkinfo, jobid);
- Mmsg(cmd, "commit %s %s %s", mode, (char*)dkinfo->get_container_id(), imagename.c_str());
+ Mmsg(cmd, "commit %s %s %s", mode, (char*)*dkinfo->get_container_id(), imagename.c_str());
if (!execute_command(ctx, cmd)){
/* some error executing command */
DMSG0(ctx, DERROR, "container_commit execution error\n");
Deleted: sha256:e7cd2a7f1c52a1fa8d88ab812abdcd814064e4884a12bd1f9acde16133023a69
*/
- Mmsg(cmd, "rmi %s", (char*)dkinfo->get_container_imagesave());
+ Mmsg(cmd, "rmi %s", (char*)*dkinfo->get_container_imagesave());
if (!execute_command(ctx, cmd)){
/* some error executing command */
DMSG0(ctx, DERROR, "delete_container_commit execution error\n");
POOL_MEM cmd(PM_FNAME);
DMSG0(ctx, DINFO, "image_save called.\n");
- Mmsg(cmd, "save %s", (char*)dkid);
+ Mmsg(cmd, "save %s", (char*)*dkid);
if (!execute_command(ctx, cmd)){
/* some error executing command */
DMSG0(ctx, DERROR, "image_save execution error\n");
char *p;
DMSG1(ctx, DINFO, "run_container_volume_cmd called: %s.\n", cmd);
- if (workingvolume == NULL && prepare_working_volume(ctx, jobid) != bRC_OK){
+ if (strlen(workingvolume.c_str()) == 0 && prepare_working_volume(ctx, jobid) != bRC_OK){
return bRC_Error;
}
+
/* Here we will run archive container for volume backup */
- Mmsg(bactarcmd, "run -d --rm -v %s:/%s -v %s:/logs %s %s", volname, cmd, workingvolume, BACULATARIMAGE, cmd);
+ Mmsg(bactarcmd, "run -d --rm -v %s:/%s -v %s:/logs %s %s", volname, cmd, workingvolume.c_str(), BACULATARIMAGE, cmd);
if (!execute_command(ctx, bactarcmd)){
/* some error executing command */
DMSG0(ctx, DERROR, "run_container_volume_cmd execution error\n");
}
DMSG0(ctx, DINFO, "docker_create_container called.\n");
if (dkinfo){
- imagelabel = param_container_imageid ? (char*)dkinfo->get_container_imagesave() : dkinfo->get_container_imagesave_tag();
+ imagelabel = param_container_imageid ? (char*)*dkinfo->get_container_imagesave() : dkinfo->get_container_imagesave_tag();
namepar = param_container_defaultnames ? "" : "--name ";
nameval = param_container_defaultnames ? "" : dkinfo->get_container_names();
if (param_container_run){
/*
Bacula(R) - The Network Backup Solution
- Copyright (C) 2000-2019 Kern Sibbald
+ Copyright © 2000-2020 Bacula Systems SA
+ All rights reserved.
The original author of Bacula is Kern Sibbald, with contributions
from many others, a complete list can be found in the file AUTHORS.
/*
* This is a low-level communication class which handles command tools execution.
*/
-class DKCOMMCTX: public SMARTALLOC {
+class DKCOMMCTX: public SMARTALLOC
+{
public:
char *command;
void set_all_images_to_backup(bpContext *ctx);
void set_all_volumes_to_backup(bpContext *ctx);
- inline DKINFO *get_first_to_backup(bpContext *ctx) { return (DKINFO*)objs_to_backup->first(); };
- inline DKINFO *get_next_to_backup(bpContext *ctx) { return (DKINFO*)objs_to_backup->next(); };
- inline void finish_backup_list(bpContext *ctx) { objs_to_backup->last(); };
+ inline DKINFO *get_first_to_backup(bpContext *ctx) { return (DKINFO*)objs_to_backup->first(); }
+ inline DKINFO *get_next_to_backup(bpContext *ctx) { return (DKINFO*)objs_to_backup->next(); }
+ inline void finish_backup_list(bpContext *ctx) { objs_to_backup->last(); }
bRC container_commit(bpContext *ctx, DKINFO *dkinfo, int jobid);
bRC delete_container_commit(bpContext *ctx, DKINFO *dkinfo, int jobid);
int32_t read_output(bpContext *ctx, POOL_MEM &out);
int32_t write_data(bpContext *ctx, POOLMEM *buf, int32_t len);
void terminate(bpContext *ctx);
- inline int get_backend_pid() { if (bpipe){ return bpipe->worker_pid; } return -1;};
+ inline int get_backend_pid()
+ {
+ if (bpipe){
+ return bpipe->worker_pid;
+ }
+ return -1;
+ }
bRC parse_parameters(bpContext *ctx, char *argk, char *argv);
bRC parse_restoreobj(bpContext *ctx, restore_object_pkt *rop);
bRC prepare_restore(bpContext *ctx);
bRC prepare_working_volume(bpContext* ctx, int jobid);
void clean_working_volume(bpContext* ctx);
- inline void render_working_volume_filename(POOL_MEM &buf, const char *fname)
- { Mmsg(buf, "%s/%s", workingvolume, fname); };
+ inline void render_working_volume_filename(POOL_MEM &buf, const char *fname) { Mmsg(buf, "%s/%s", workingvolume.c_str(), fname); }
void setworkingdir(char *workdir);
- inline bool is_open() { return bpipe != NULL; };
- inline bool is_closed() { return bpipe == NULL; };
- inline bool is_error() { return f_error || f_fatal; };
- inline void set_error() { f_error = true; };
- inline bool is_fatal() { return f_fatal || (f_error && abort_on_error); };
- inline bool is_eod() { return f_eod; };
- inline void clear_eod() { f_eod = false; };
- inline void set_eod() { f_eod = true; };
- inline void set_abort_on_error() { abort_on_error = true; };
- inline void clear_abort_on_error() { abort_on_error = false; };
- inline bool is_abort_on_error() { return abort_on_error; };
- inline bool is_all_vols_to_backup() { return all_vols_to_backup; };
- inline bool is_remote_docker() { return param_docker_host != NULL; };
+ inline bool is_open() { return bpipe != NULL; }
+ inline bool is_closed() { return bpipe == NULL; }
+ inline bool is_error() { return f_error || f_fatal; }
+ inline void set_error() { f_error = true; }
+ inline bool is_fatal() { return f_fatal || (f_error && abort_on_error); }
+ inline bool is_eod() { return f_eod; }
+ inline void clear_eod() { f_eod = false; }
+ inline void set_eod() { f_eod = true; }
+ inline void set_abort_on_error() { abort_on_error = true; }
+ inline void clear_abort_on_error() { abort_on_error = false; }
+ inline bool is_abort_on_error() { return abort_on_error; }
+ inline bool is_all_vols_to_backup() { return all_vols_to_backup; }
+ inline bool is_remote_docker() { return strlen(param_docker_host.c_str()) > 0; }
inline int32_t timeout() { return param_timeout; };
DKCOMMCTX(const char *cmd);
bool param_container_run; /* the restore parameter for container creation and execution */
bool param_container_imageid; /* the restore parameter for setting imageid during container creation/run */
bool param_container_defaultnames; /* the restore parameter for setting default docker names on container creation */
- POOLMEM *param_docker_host; /* use defined docker host to docker operations */
+ POOL_MEM param_docker_host; /* use defined docker host to docker operations */
int32_t param_timeout; /* a timeout opening container communication pipe, the default is 30 */
regex_t preg; /* this is a regex context for include/exclude */
bool abort_on_error; /* abort on error flag */
bool f_error; /* the plugin signaled an error */
bool f_fatal; /* the plugin signaled a fatal error */
ConfigFile *ini; /* restore object config parser */
- POOLMEM *workingvolume; /* */
- POOLMEM *workingdir; /* runtime working directory from file daemon */
+ POOL_MEM workingvolume; /* */
+ POOL_MEM workingdir; /* runtime working directory from file daemon */
bool execute_command(bpContext *ctx, POOLMEM *args);
bool execute_command(bpContext *ctx, const char *args);
bool execute_command(bpContext *ctx, POOL_MEM &args);
void parse_parameters(bpContext *ctx, ini_items &item);
- bool render_param(bpContext *ctx, POOLMEM **param, const char *pname, const char *fmt, const char *name, char *value);
- bool render_param(bpContext *ctx, POOLMEM **param, const char *pname, const char *fmt, const char *name, int value);
- bool render_param(bpContext *ctx, POOLMEM **param, const char *pname, const char *name, char *value);
- bool render_param(bpContext *ctx, bool *param, const char *pname, const char *name, bool value);
- bool render_param(bpContext *ctx, int32_t *param, const char *pname, const char *name, int32_t value);
- bool add_param_str(bpContext *ctx, alist **list, const char *pname, const char *name, char *value);
- bool parse_param(bpContext *ctx, POOLMEM **param, const char *pname, const char *name, char *value);
- bool parse_param(bpContext *ctx, bool *param, const char *pname, const char *name, char *value);
- bool parse_param(bpContext *ctx, int32_t *param, const char *pname, const char *name, char *value);
- bool parse_param(bpContext *ctx, DOCKER_BACKUP_MODE_T *param, const char *pname, const char *name, char *value);
+ // bool render_param(bpContext *ctx, POOLMEM **param, const char *pname, const char *fmt, const char *name, char *value);
+ // bool render_param(bpContext *ctx, POOLMEM **param, const char *pname, const char *fmt, const char *name, int value);
+ // bool render_param(bpContext *ctx, POOLMEM **param, const char *pname, const char *name, char *value);
+ // bool render_param(bpContext *ctx, bool *param, const char *pname, const char *name, bool value);
+ // bool render_param(bpContext *ctx, int32_t *param, const char *pname, const char *name, int32_t value);
+ // bool add_param_str(bpContext *ctx, alist **list, const char *pname, const char *name, char *value);
+ // bool parse_param(bpContext *ctx, POOLMEM **param, const char *pname, const char *name, char *value);
+ // bool parse_param(bpContext *ctx, bool *param, const char *pname, const char *name, char *value);
+ // bool parse_param(bpContext *ctx, int32_t *param, const char *pname, const char *name, char *value);
+ bool parse_param_mode(bpContext *ctx, DOCKER_BACKUP_MODE_T *param, const char *pname, const char *name, char *value);
void filter_param_to_backup(bpContext *ctx, alist *params, alist *dklist, bool estimate);
void filter_incex_to_backup(bpContext *ctx, alist *params_include, alist *params_exclude, alist *dklist);
bRC run_container_volume_load(bpContext* ctx, POOLMEM *volname, int jobid);
bool check_for_docker_errors(bpContext* ctx, char *buf);
inline void render_imagesave_name(POOL_MEM &out, DKINFO *dkinfo, int jobid)
- { Mmsg(out, "%s/%s/%d:backup", dkinfo->get_container_names(),
- dkinfo->get_container_id()->digest_short(), jobid); };
+ {
+ Mmsg(out, "%s/%s/%d:backup", dkinfo->get_container_names(), dkinfo->get_container_id()->digest_short(), jobid);
+ }
void dump_robjdebug(bpContext *ctx, restore_object_pkt *rop);
};
-#endif /* _DKCOMMCTX_H_ */
\ No newline at end of file
+#endif /* _DKCOMMCTX_H_ */