Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'bareos-16.2'
  • Loading branch information
Marco van Wieringen committed Jul 28, 2016
2 parents 966ad8e + 51f2e38 commit 3529acc
Show file tree
Hide file tree
Showing 13 changed files with 197 additions and 140 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
6 changes: 4 additions & 2 deletions src/dird/backup.c
Expand Up @@ -1042,9 +1042,11 @@ void generate_backup_summary(JCR *jcr, CLIENT_DBR *cr, int msg_type, const char
if (jcr->is_JobLevel(L_VIRTUAL_FULL)) {
Mmsg(daemon_status, _(
" SD Errors: %d\n"
" SD termination status: %s\n"),
" SD termination status: %s\n"
" Accurate: %s\n"),
jcr->SDErrors,
sd_term_msg);
sd_term_msg,
jcr->accurate ? _("yes") : _("no"));
} else {
if (jcr->HasBase) {
Mmsg(client_options, _(
Expand Down
3 changes: 1 addition & 2 deletions src/dird/consolidate.c
Expand Up @@ -50,8 +50,7 @@ static inline void start_new_consolidation_job(JCR *jcr, char *jobname)

ua = new_ua_context(jcr);
ua->batch = true;

Mmsg(ua->cmd, "run job=\"%s\" jobid=%s level=VirtualFull", jobname, jcr->vf_jobids);
Mmsg(ua->cmd, "run job=\"%s\" jobid=%s level=VirtualFull %s", jobname, jcr->vf_jobids, jcr->accurate ? "accurate=yes" : "accurate=no");

Dmsg1(dbglvl, "=============== consolidate cmd=%s\n", ua->cmd);
parse_ua_args(ua); /* parse command */
Expand Down
57 changes: 35 additions & 22 deletions src/dird/dird_conf.c
Expand Up @@ -422,11 +422,11 @@ RES_ITEM job_items[] = {
{ "MaxConcurrentCopies", CFG_TYPE_PINT32, ITEM(res_job.MaxConcurrentCopies), 0, CFG_ITEM_DEFAULT, "100", NULL, NULL },
/* Settings for always incremental */
{ "AlwaysIncremental", CFG_TYPE_BOOL, ITEM(res_job.AlwaysIncremental), 0, CFG_ITEM_DEFAULT, "false", "16.2.4-",
"Enable/disable always incremental backup scheme." },
"Enable/disable always incremental backup scheme." },
{ "AlwaysIncrementalJobRetention", CFG_TYPE_TIME, ITEM(res_job.AlwaysIncrementalJobRetention), 0, CFG_ITEM_DEFAULT, "0", "16.2.4-",
"Backup Jobs older than the specified time duration will be merged into a new Virtual Full." },
"Backup Jobs older than the specified time duration will be merged into a new Virtual backup." },
{ "AlwaysIncrementalKeepNumber", CFG_TYPE_PINT32, ITEM(res_job.AlwaysIncrementalKeepNumber), 0, CFG_ITEM_DEFAULT, "0", "16.2.4-",
"Guarantee that at least the specified number of Backup Jobs will persist, even if they are older than \"Always Incremental Job Retention\"."},
"Guarantee that at least the specified number of Backup Jobs will persist, even if they are older than \"Always Incremental Job Retention\"."},
{ NULL, 0, { 0 }, 0, 0, NULL, NULL, NULL }
};

Expand Down 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
3 changes: 3 additions & 0 deletions src/dird/ua_cmds.c
Expand Up @@ -65,6 +65,7 @@ extern bool dot_jobs_cmd(UAContext *ua, const char *cmd);
extern bool dot_jobstatus_cmd(UAContext *ua, const char *cmd);
extern bool dot_filesets_cmd(UAContext *ua, const char *cmd);
extern bool dot_clients_cmd(UAContext *ua, const char *cmd);
extern bool dot_consoles_cmd(UAContext *ua, const char *cmd);
extern bool dot_msgs_cmd(UAContext *ua, const char *cmd);
extern bool dot_pools_cmd(UAContext *ua, const char *cmd);
extern bool dot_schedule_cmd(UAContext *ua, const char *cmd);
Expand Down Expand Up @@ -158,6 +159,8 @@ static struct cmdstruct commands[] = {
NULL, false, false },
{ NT_(".clients"), dot_clients_cmd, _("List all client resources"),
NULL, true, false },
{ NT_(".consoles"), dot_consoles_cmd, _("List all console resources"),
NULL, true, false },
{ NT_(".defaults"), dot_defaults_cmd, _("Get default settings"),
NT_("job=<job-name> | client=<client-name> | storage=<storage-name | pool=<pool-name>"), false, false },
#ifdef DEVELOPER
Expand Down
17 changes: 17 additions & 0 deletions src/dird/ua_dotcmds.c
Expand Up @@ -923,6 +923,23 @@ bool dot_clients_cmd(UAContext *ua, const char *cmd)
return true;
}

bool dot_consoles_cmd(UAContext *ua, const char *cmd)
{
CONRES *console;

LockRes();
ua->send->array_start("consoles");
foreach_res(console, R_CONSOLE) {
ua->send->object_start();
ua->send->object_key_value("name", console->name(), "%s\n");
ua->send->object_end();
}
ua->send->array_end("consoles");
UnlockRes();

return true;
}

bool dot_msgs_cmd(UAContext *ua, const char *cmd)
{
MSGSRES *msgs = NULL;
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

0 comments on commit 3529acc

Please sign in to comment.