Skip to content

Commit

Permalink
Merge branch 'bareos-15.2' into bareos-16.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco van Wieringen committed Jul 28, 2016
2 parents 4583bfd + ca56bea commit ded698f
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 129 deletions.
77 changes: 51 additions & 26 deletions src/cats/sql_cmds.c
Expand Up @@ -83,9 +83,7 @@ const char *list_pool = "SELECT * FROM Pool WHERE PoolId=%s";
* JOIN with Media is required for filter to Media.Volumename.
*/
const char *list_jobs =
"SELECT DISTINCT "
"Job.JobId,Job.Name, "
"Client.Name as Client, "
"SELECT DISTINCT Job.JobId,Job.Name, Client.Name as Client, "
"Job.StartTime,Job.Type,Job.Level,Job.JobFiles,Job.JobBytes,Job.JobStatus "
"FROM Job "
"LEFT JOIN Client ON Client.ClientId=Job.ClientId "
Expand All @@ -96,9 +94,31 @@ const char *list_jobs =
"%s "
"ORDER BY StartTime%s";

const char *list_jobs_last =
"SELECT DISTINCT Job.JobId,Job.Name, Client.Name as Client, "
"Job.StartTime,Job.Type,Job.Level,Job.JobFiles,Job.JobBytes,Job.JobStatus "
"FROM Job "
"LEFT JOIN Client ON Client.ClientId=Job.ClientId "
"LEFT JOIN JobMedia ON JobMedia.JobId=Job.JobId "
"LEFT JOIN Media ON JobMedia.MediaId=Media.MediaId "
"LEFT JOIN FileSet ON FileSet.FileSetId=Job.FileSetId "
"INNER JOIN ( "
"SELECT MAX(Job.JobId) as MaxJobId "
"FROM Job "
"LEFT JOIN Client ON Client.ClientId=Job.ClientId "
"LEFT JOIN Pool ON Pool.PoolId=Job.PoolId "
"LEFT JOIN JobMedia ON JobMedia.JobId=Job.JobId "
"LEFT JOIN Media ON JobMedia.MediaId=Media.MediaId "
"LEFT JOIN FileSet ON FileSet.FileSetId=Job.FileSetId "
"WHERE Job.JobId > 0 "
"%s "
"GROUP BY Job.Name "
") LastJob "
"ON Job.JobId = LastJob.MaxJobId "
"ORDER BY StartTime%s";

const char *list_jobs_count =
"SELECT DISTINCT "
"COUNT(DISTINCT Job.JobId) as count "
"SELECT DISTINCT COUNT(DISTINCT Job.JobId) as count "
"FROM Job "
"LEFT JOIN Client ON Client.ClientId=Job.ClientId "
"LEFT JOIN JobMedia ON JobMedia.JobId=Job.JobId "
Expand All @@ -109,17 +129,11 @@ const char *list_jobs_count =
"%s";

const char *list_jobs_long =
"SELECT DISTINCT "
"Job.JobId, Job.Job, Job.Name, "
"Job.PurgedFiles, Job.Type, Job.Level, "
"Job.ClientId, Client.Name as Client, "
"Job.JobStatus,"
"Job.SchedTime, Job.StartTime, Job.EndTime, Job.RealEndTime, Job.JobTDate, "
"Job.VolSessionId, Job.VolSessionTime, "
"Job.JobFiles, Job.JobBytes, Job.JobErrors, Job.JobMissingFiles, "
"Job.PoolId, Pool.Name as PoolName,"
"Job.PriorJobId, "
"Job.FileSetId, FileSet.FileSet "
"SELECT DISTINCT Job.JobId, Job.Job, Job.Name, Job.PurgedFiles, Job.Type, Job.Level, "
"Job.ClientId, Client.Name as Client, Job.JobStatus, Job.SchedTime, Job.StartTime, "
"Job.EndTime, Job.RealEndTime, Job.JobTDate, Job.VolSessionId, Job.VolSessionTime, "
"Job.JobFiles, Job.JobBytes, Job.JobErrors, Job.JobMissingFiles, Job.PoolId, "
"Pool.Name as PoolName, Job.PriorJobId, Job.FileSetId, FileSet.FileSet "
"FROM Job "
"LEFT JOIN Client ON Client.ClientId=Job.ClientId "
"LEFT JOIN Pool ON Pool.PoolId=Job.PoolId "
Expand All @@ -130,21 +144,32 @@ const char *list_jobs_long =
"%s "
"ORDER BY StartTime%s";

/*
* Get the last JobId of each Job.Name matching the given criteria.
*/
const char *list_jobs_last =
"SELECT DISTINCT "
"MAX(DISTINCT Job.JobId) as MaxJobId "
const char *list_jobs_long_last =
"SELECT DISTINCT Job.JobId, Job.Job, Job.Name, Job.PurgedFiles, Job.Type, Job.Level, "
"Job.ClientId, Client.Name as Client, Job.JobStatus, Job.SchedTime, Job.StartTime, "
"Job.EndTime, Job.RealEndTime, Job.JobTDate, Job.VolSessionId, Job.VolSessionTime, "
"Job.JobFiles, Job.JobBytes, Job.JobErrors, Job.JobMissingFiles, Job.PoolId, "
"Pool.Name as PoolName, Job.PriorJobId, Job.FileSetId, FileSet.FileSet "
"FROM Job "
"LEFT JOIN Client ON Client.ClientId=Job.ClientId "
"LEFT JOIN Pool ON Pool.PoolId=Job.PoolId "
"LEFT JOIN JobMedia ON JobMedia.JobId=Job.JobId "
"LEFT JOIN Media ON JobMedia.MediaId=Media.MediaId "
"LEFT JOIN FileSet ON FileSet.FileSetId=Job.FileSetId "
"WHERE Job.JobId > 0 "
"%s "
"GROUP BY Job.Name "
"%s";
"INNER JOIN ( "
"SELECT MAX(Job.JobId) as MaxJobId "
"FROM Job "
"LEFT JOIN Client ON Client.ClientId=Job.ClientId "
"LEFT JOIN Pool ON Pool.PoolId=Job.PoolId "
"LEFT JOIN JobMedia ON JobMedia.JobId=Job.JobId "
"LEFT JOIN Media ON JobMedia.MediaId=Media.MediaId "
"LEFT JOIN FileSet ON FileSet.FileSetId=Job.FileSetId "
"WHERE Job.JobId > 0 "
"%s "
"GROUP BY Job.Name "
") LastJob "
"ON Job.JobId = LastJob.MaxJobId "
"ORDER BY StartTime%s";

const char *get_jobstatus_details =
"SELECT DISTINCT "
Expand Down
1 change: 1 addition & 0 deletions src/cats/sql_cmds.h
Expand Up @@ -27,6 +27,7 @@ extern const char CATS_IMP_EXP *list_jobs;
extern const char CATS_IMP_EXP *list_jobs_count;
extern const char CATS_IMP_EXP *list_jobs_long;
extern const char CATS_IMP_EXP *list_jobs_last;
extern const char CATS_IMP_EXP *list_jobs_long_last;
extern const char CATS_IMP_EXP *get_jobstatus_details;
extern const char CATS_IMP_EXP *list_pool;
extern const char CATS_IMP_EXP *drop_deltabs[];
Expand Down
29 changes: 6 additions & 23 deletions src/cats/sql_list.c
Expand Up @@ -415,7 +415,6 @@ void db_list_job_records(JCR *jcr, B_DB *mdb, JOB_DBR *jr, const char *range,
POOL_MEM temp(PM_MESSAGE),
selection(PM_MESSAGE),
criteria(PM_MESSAGE);
POOL_MEM selection_last(PM_MESSAGE);
char dt[MAX_TIME_LENGTH];

if (jr->JobId > 0) {
Expand Down Expand Up @@ -450,31 +449,15 @@ void db_list_job_records(JCR *jcr, B_DB *mdb, JOB_DBR *jr, const char *range,
pm_strcat(selection, temp.c_str());
}

if (last > 0) {
/*
* Show only the last run of a job (Job.Name).
* Do a subquery to get a list of matching JobIds
* to be used in the main query later.
*
* range: while it might be more efficient,
* to apply the range to the subquery,
* at least mariadb 10 does not support this.
* Therefore range is handled in the main query.
*/
temp.bsprintf("AND Job.JobId IN (%s) ", list_jobs_last);
selection_last.bsprintf(temp.c_str(), selection.c_str(), "");

/*
* As the existing selection is handled in the subquery,
* overwrite the main query selection
* by the newly created selection_last.
*/
pm_strcpy(selection, selection_last.c_str());
}

db_lock(mdb);
if (count > 0) {
Mmsg(mdb->cmd, list_jobs_count, selection.c_str(), range);
} else if (last > 0) {
if (type == VERT_LIST) {
Mmsg(mdb->cmd, list_jobs_long_last, selection.c_str(), range);
} else {
Mmsg(mdb->cmd, list_jobs_last, selection.c_str(), range);
}
} else {
if (type == VERT_LIST) {
Mmsg(mdb->cmd, list_jobs_long, selection.c_str(), range);
Expand Down
51 changes: 32 additions & 19 deletions src/dird/dird_conf.c
Expand Up @@ -1303,13 +1303,9 @@ static inline void print_config_runscript(RES_ITEM *item, POOL_MEM &cfg_str)
if (bstrcasecmp(item->name, "runscript")) {
if (list != NULL) {
foreach_alist(runscript, list) {
int len;
POOLMEM *cmdbuf;
POOL_MEM esc;

len = strlen(runscript->command);
cmdbuf = get_pool_memory(PM_NAME);
cmdbuf = check_pool_memory_size(cmdbuf, len * 2);
escape_string(cmdbuf, runscript->command, len);
escape_string(esc, runscript->command, strlen(runscript->command));

/*
* Don't print runscript when its inherited from a JobDef.
Expand All @@ -1324,28 +1320,28 @@ static inline void print_config_runscript(RES_ITEM *item, POOL_MEM &cfg_str)
if (runscript->short_form) {
if (runscript->when == SCRIPT_Before && /* runbeforejob */
(bstrcmp(runscript->target, ""))) {
Mmsg(temp, "run before job = \"%s\"\n", cmdbuf);
Mmsg(temp, "run before job = \"%s\"\n", esc.c_str());
} else if (runscript->when == SCRIPT_After && /* runafterjob */
runscript->on_success &&
!runscript->on_failure &&
!runscript->fail_on_error &&
bstrcmp(runscript->target, "")) {
Mmsg(temp, "run after job = \"%s\"\n", cmdbuf);
Mmsg(temp, "run after job = \"%s\"\n", esc.c_str());
} else if (runscript->when == SCRIPT_After && /* client run after job */
runscript->on_success &&
!runscript->on_failure &&
!runscript->fail_on_error &&
!bstrcmp(runscript->target, "")) {
Mmsg(temp, "client run after job = \"%s\"\n", cmdbuf);
Mmsg(temp, "client run after job = \"%s\"\n", esc.c_str());
} else if (runscript->when == SCRIPT_Before && /* client run before job */
!bstrcmp(runscript->target, "")) {
Mmsg(temp, "client run before job = \"%s\"\n", cmdbuf);
Mmsg(temp, "client run before job = \"%s\"\n", esc.c_str());
} else if (runscript->when == SCRIPT_After && /* run after failed job */
runscript->on_failure &&
!runscript->on_success &&
!runscript->fail_on_error &&
bstrcmp(runscript->target, "")) {
Mmsg(temp, "run after failed job = \"%s\"\n", cmdbuf);
Mmsg(temp, "run after failed job = \"%s\"\n", esc.c_str());
}
indent_config_item(cfg_str, 1, temp.c_str());
} else {
Expand All @@ -1357,7 +1353,7 @@ static inline void print_config_runscript(RES_ITEM *item, POOL_MEM &cfg_str)
cmdstring = (char *)"console";
}

Mmsg(temp, "%s = \"%s\"\n", cmdstring, cmdbuf);
Mmsg(temp, "%s = \"%s\"\n", cmdstring, esc.c_str());
indent_config_item(cfg_str, 2, temp.c_str());

/*
Expand Down Expand Up @@ -1430,8 +1426,6 @@ static inline void print_config_runscript(RES_ITEM *item, POOL_MEM &cfg_str)

indent_config_item(cfg_str, 1, "}\n");
}

free_pool_memory(cmdbuf);
}
} /* foreach runscript */
}
Expand Down Expand Up @@ -2123,8 +2117,13 @@ bool FILESETRES::print_config(POOL_MEM &buff, bool hide_sensitive_data)
indent_config_item(cfg_str, 3, temp.c_str());
}

/*
* Wildbase is WildFile not containing a / or \\
* see void store_wild() in inc_conf.c
* so we need to translate it back to a Wild File entry
*/
for (int k = 0; k < fo->wildbase.size(); k++) {
Mmsg(temp, "Wild Base = \"%c %s\"\n", enhanced_wild ? 'B' : 'F', fo->wildbase.get(k));
Mmsg(temp, "Wild File = \"%s\"\n", fo->wildbase.get(k));
indent_config_item(cfg_str, 3, temp.c_str());
}

Expand Down Expand Up @@ -2171,8 +2170,13 @@ bool FILESETRES::print_config(POOL_MEM &buff, bool hide_sensitive_data)
* File = entries.
*/
if (incexe->name_list.size()) {
char *entry;
POOL_MEM esc;

for (int l = 0; l < incexe->name_list.size(); l++) {
Mmsg(temp, "File = \"%s\"\n", incexe->name_list.get(l));
entry = (char *)incexe->name_list.get(l);
escape_string(esc, entry, strlen(entry));
Mmsg(temp, "File = \"%s\"\n", esc.c_str());
indent_config_item(cfg_str, 2, temp.c_str());
}
}
Expand All @@ -2181,8 +2185,13 @@ bool FILESETRES::print_config(POOL_MEM &buff, bool hide_sensitive_data)
* Plugin = entries.
*/
if (incexe->plugin_list.size()) {
char *entry;
POOL_MEM esc;

for (int l = 0; l < incexe->plugin_list.size(); l++) {
Mmsg(temp, "Plugin = %s\n", incexe->plugin_list.get(l));
entry = (char *)incexe->plugin_list.get(l);
escape_string(esc, entry, strlen(entry));
Mmsg(temp, "Plugin = \"%s\"\n", esc.c_str());
indent_config_item(cfg_str, 2, temp.c_str());
}
}
Expand Down Expand Up @@ -2213,10 +2222,14 @@ bool FILESETRES::print_config(POOL_MEM &buff, bool hide_sensitive_data)
INCEXE *incexe = exclude_items[j];

if (incexe->name_list.size()) {
indent_config_item(cfg_str, 1, "Exclude {\n");
char *entry;
POOL_MEM esc;

indent_config_item(cfg_str, 1, "Exclude {\n");
for (int k = 0; k < incexe->name_list.size(); k++) {
Mmsg(temp, "File = \"%s\"\n", incexe->name_list.get(k));
entry = (char *)incexe->name_list.get(k);
escape_string(esc, entry, strlen(entry));
Mmsg(temp, "File = \"%s\"\n", esc.c_str());
indent_config_item(cfg_str, 2, temp.c_str());
}

Expand Down
2 changes: 2 additions & 0 deletions src/dird/ua_purge.c
Expand Up @@ -653,6 +653,8 @@ static void do_truncate_on_purge(UAContext *ua, MEDIA_DBR *mr,
* Do it only if action on purge = truncate is set
*/
if (!(mr->ActionOnPurge & ON_PURGE_TRUNCATE)) {
ua->error_msg(_("\nThe option \"Action On Purge = Truncate\" was not defined in the Pool resource.\n"
"Unable to truncate volume \"%s\"\n"), mr->VolumeName);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/protos.h
Expand Up @@ -402,7 +402,7 @@ void set_tls_enable(TLS_CONTEXT *ctx, bool value);
bool get_tls_verify_peer(TLS_CONTEXT *ctx);

/* util.c */
void escape_string(char *snew, char *old, int len);
void escape_string(POOL_MEM &snew, char *old, int len);
bool is_buf_zero(char *buf, int len);
void lcase(char *str);
void bash_spaces(char *str);
Expand Down
28 changes: 12 additions & 16 deletions src/lib/res.c
Expand Up @@ -1416,8 +1416,6 @@ static inline void print_config_time(RES_ITEM *item, POOL_MEM &cfg_str)

bool MSGSRES::print_config(POOL_MEM &buff, bool hide_sensitive_data)
{
int len;
POOLMEM *cmdbuf;
POOL_MEM cfg_str; /* configuration as string */
POOL_MEM temp;
MSGSRES *msgres;
Expand All @@ -1429,31 +1427,29 @@ bool MSGSRES::print_config(POOL_MEM &buff, bool hide_sensitive_data)
Mmsg(temp, " %s = \"%s\"\n", "Name", msgres->name());
pm_strcat(cfg_str, temp.c_str());

cmdbuf = get_pool_memory(PM_NAME);
if (msgres->mail_cmd) {
len = strlen(msgres->mail_cmd);
cmdbuf = check_pool_memory_size(cmdbuf, len * 2);
escape_string(cmdbuf, msgres->mail_cmd, len);
Mmsg(temp, " MailCommand = \"%s\"\n", cmdbuf);
POOL_MEM esc;

escape_string(esc, msgres->mail_cmd, strlen(msgres->mail_cmd));
Mmsg(temp, " MailCommand = \"%s\"\n", esc.c_str());
pm_strcat(cfg_str, temp.c_str());
}

if (msgres->operator_cmd) {
len = strlen(msgres->operator_cmd);
cmdbuf = check_pool_memory_size(cmdbuf, len * 2);
escape_string(cmdbuf, msgres->operator_cmd, len);
Mmsg(temp, " OperatorCommand = \"%s\"\n", cmdbuf);
POOL_MEM esc;

escape_string(esc, msgres->operator_cmd, strlen(msgres->operator_cmd));
Mmsg(temp, " OperatorCommand = \"%s\"\n", esc.c_str());
pm_strcat(cfg_str, temp.c_str());
}

if (msgres->timestamp_format) {
len = strlen(msgres->timestamp_format);
cmdbuf = check_pool_memory_size(cmdbuf, len * 2);
escape_string(cmdbuf, msgres->timestamp_format, len);
Mmsg(temp, " TimestampFormat = \"%s\"\n", cmdbuf);
POOL_MEM esc;

escape_string(esc, msgres->timestamp_format, strlen(msgres->timestamp_format));
Mmsg(temp, " TimestampFormat = \"%s\"\n", esc.c_str());
pm_strcat(cfg_str, temp.c_str());
}
free_pool_memory(cmdbuf);

for (d = msgres->dest_chain; d; d = d->next) {
int nr_set = 0;
Expand Down

0 comments on commit ded698f

Please sign in to comment.