Skip to content

Commit

Permalink
bcommand: [l]list jobs last, [l]list jobs count
Browse files Browse the repository at this point in the history
list jobs last:
list only the last run of each job name.

list jobs count
instead of listing the jobs, only show how many jobs match the criteria.
  • Loading branch information
joergsteffens authored and Marco van Wieringen committed Oct 13, 2015
1 parent c946e41 commit 25d13df
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 19 deletions.
5 changes: 3 additions & 2 deletions src/cats/protos.h
Expand Up @@ -122,8 +122,9 @@ bool db_get_ndmp_environment_string(JCR *jcr, B_DB *mdb, JOB_DBR *jr,
void db_list_pool_records(JCR *jcr, B_DB *db, POOL_DBR *pr,
OUTPUT_FORMATTER *sendit, e_list_type type);
void db_list_job_records(JCR *jcr, B_DB *db, JOB_DBR *jr, const char *range,
const char *clientname, int jobstatus, const char *volumename,
utime_t since_time, OUTPUT_FORMATTER *sendit, e_list_type type);
const char* clientname, int jobstatus, const char* volumename,
utime_t since_time, int last, int count,
OUTPUT_FORMATTER *sendit, e_list_type type);
void db_list_job_totals(JCR *jcr, B_DB *db, JOB_DBR *jr,
OUTPUT_FORMATTER *sendit);
void db_list_files_for_job(JCR *jcr, B_DB *db, uint32_t jobid,
Expand Down
12 changes: 12 additions & 0 deletions src/cats/sql_cmds.c
Expand Up @@ -96,6 +96,18 @@ const char *list_jobs =
"%s "
"ORDER BY StartTime%s";

const char *list_jobs_count =
"SELECT "
"COUNT(*) as count "
"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 "
"WHERE Job.JobId > 0 "
"%s "
"ORDER BY StartTime%s";

const char *list_jobs_long =
"SELECT "
"Job.JobId, Job.Job, Job.Name, "
Expand Down
1 change: 1 addition & 0 deletions src/cats/sql_cmds.h
Expand Up @@ -24,6 +24,7 @@
extern const char CATS_IMP_EXP *get_restore_objects;
extern const char CATS_IMP_EXP *fill_jobhisto;
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_pool;
extern const char CATS_IMP_EXP *drop_deltabs[];
Expand Down
33 changes: 22 additions & 11 deletions src/cats/sql_list.c
Expand Up @@ -356,8 +356,9 @@ void db_list_joblog_records(JCR *jcr, B_DB *mdb, uint32_t JobId,
* List Job record(s) that match JOB_DBR
*/
void db_list_job_records(JCR *jcr, B_DB *mdb, JOB_DBR *jr, const char *range,
const char *clientname, int jobstatus, const char *volumename,
utime_t since_time, OUTPUT_FORMATTER *sendit, e_list_type type)
const char* clientname, int jobstatus, const char* volumename,
utime_t since_time, int last, int count,
OUTPUT_FORMATTER *sendit, e_list_type type)
{
char ed1[50];
char esc[MAX_ESCAPE_NAME_LENGTH];
Expand All @@ -370,36 +371,46 @@ void db_list_job_records(JCR *jcr, B_DB *mdb, JOB_DBR *jr, const char *range,
bstrutime(dt, sizeof(dt), since_time);

if (jr->JobId > 0) {
temp.bsprintf(" AND Job.JobId=%s", edit_int64(jr->JobId, ed1));
temp.bsprintf("AND Job.JobId=%s", edit_int64(jr->JobId, ed1));
pm_strcat(selection, temp.c_str());
}
if (jr->Name[0] != 0) {
mdb->db_escape_string(jcr, esc, jr->Name, strlen(jr->Name));
temp.bsprintf( " AND Job.Name = '%s' ", esc);
temp.bsprintf( "AND Job.Name = '%s' ", esc);
pm_strcat(selection, temp.c_str());
}
if (clientname) {
temp.bsprintf(" AND Client.Name = '%s' ", clientname);
temp.bsprintf("AND Client.Name = '%s' ", clientname);
pm_strcat(selection, temp.c_str());
}
if (jobstatus) {
temp.bsprintf(" AND Job.JobStatus = '%c' ", jobstatus);
temp.bsprintf("AND Job.JobStatus = '%c' ", jobstatus);
pm_strcat(selection, temp.c_str());
}
if (volumename) {
temp.bsprintf(" AND Media.Volumename = '%s' ", volumename);
temp.bsprintf("AND Media.Volumename = '%s' ", volumename);
pm_strcat(selection, temp.c_str());
}
if (since_time) {
temp.bsprintf(" AND Job.SchedTime > '%s' ", dt);
temp.bsprintf("AND Job.SchedTime > '%s' ", dt);
pm_strcat(selection, temp.c_str());
}
if (last > 0) {
/*
* show only the last run of a jobs
*/
pm_strcat(selection, "AND Job.JobId=(SELECT MAX(JobId) FROM Job JobTemp WHERE Job.Name = JobTemp.Name) ");
}

db_lock(mdb);
if (type == VERT_LIST) {
Mmsg(mdb->cmd, list_jobs_long, selection.c_str(), range);
if (count > 0) {
Mmsg(mdb->cmd, list_jobs_count, selection.c_str(), range);
} else {
Mmsg(mdb->cmd, list_jobs, selection.c_str(), range);
if (type == VERT_LIST) {
Mmsg(mdb->cmd, list_jobs_long, selection.c_str(), range);
} else {
Mmsg(mdb->cmd, list_jobs, selection.c_str(), range);
}
}

if (!QUERY_DB(jcr, mdb, mdb->cmd)) {
Expand Down
4 changes: 2 additions & 2 deletions src/dird/ua_cmds.c
Expand Up @@ -146,7 +146,7 @@ static struct cmdstruct commands[] = {
"filesets |\n"
"fileset [ jobid=<jobid> ] | fileset [ ujobid=<complete_name> ] |\n"
"fileset [ filesetid=<filesetid> ] | fileset [ jobid=<jobid> ] |\n"
"jobs [job=<job-name>] [client=<client-name>] [jobstatus=<status>] [volume=<volumename>] [days=<number>] [hours=<number>] |\n"
"jobs [job=<job-name>] [client=<client-name>] [jobstatus=<status>] [volume=<volumename>] [days=<number>] [hours=<number>] [last] [count] |\n"
"job=<job-name> [client=<client-name>] [jobstatus=<status>] [volume=<volumename>] [days=<number>] [hours=<number>] |\n"
"jobid=<jobid> | ujobid=<complete_name> |\n"
"joblog jobid=<jobid> | joblog ujobid=<complete_name> |\n"
Expand All @@ -169,7 +169,7 @@ static struct cmdstruct commands[] = {
"filesets |\n"
"fileset jobid=<jobid> | fileset ujobid=<complete_name> |\n"
"fileset [ filesetid=<filesetid> ] | fileset [ jobid=<jobid> ] |\n"
"jobs [job=<job-name>] [client=<client-name>] [jobstatus=<status>] [volume=<volumename>] [days=<number>] [hours=<number>] |\n"
"jobs [job=<job-name>] [client=<client-name>] [jobstatus=<status>] [volume=<volumename>] [days=<number>] [hours=<number>] [last] [count] |\n"
"job=<job-name> [client=<client-name>] [jobstatus=<status>] [volume=<volumename>] [days=<number>] [hours=<number>] |\n"
"jobid=<jobid> | ujobid=<complete_name> |\n"
"joblog jobid=<jobid> | joblog ujobid=<complete_name> |\n"
Expand Down
13 changes: 10 additions & 3 deletions src/dird/ua_output.c
Expand Up @@ -404,6 +404,8 @@ static bool do_list_cmd(UAContext *ua, const char *cmd, e_list_type llist)
int days = 0,
hours = 0,
jobstatus = 0;
int count = -1;
int last_run = -1;
time_t schedtime = 0;
const int secs_in_day = 86400;
const int secs_in_hour = 3600;
Expand Down Expand Up @@ -493,8 +495,11 @@ static bool do_list_cmd(UAContext *ua, const char *cmd, e_list_type llist)
if (i >= 0) {
volumename = ua->argv[i];
}
last_run = find_arg(ua, NT_("last"));
count = find_arg(ua, NT_("count"));
db_list_job_records(ua->jcr, ua->db, &jr, query_range.c_str(), clientname,
jobstatus, volumename, schedtime, ua->send, llist);
jobstatus, volumename, schedtime, last_run, count,
ua->send, llist);
} else if (bstrcasecmp(ua->argk[1], NT_("jobtotals"))) {
/*
* List JOBTOTALS
Expand All @@ -509,7 +514,8 @@ static bool do_list_cmd(UAContext *ua, const char *cmd, e_list_type llist)
if (jobid > 0) {
jr.JobId = jobid;
db_list_job_records(ua->jcr, ua->db, &jr, query_range.c_str(), clientname,
jobstatus, volumename, schedtime, ua->send, llist);
jobstatus, volumename, schedtime, last_run, count,
ua->send, llist);
}
}
} else if (bstrcasecmp(ua->argk[1], NT_("ujobid")) && ua->argv[1]) {
Expand All @@ -519,7 +525,8 @@ static bool do_list_cmd(UAContext *ua, const char *cmd, e_list_type llist)
bstrncpy(jr.Job, ua->argv[1], MAX_NAME_LENGTH);
jr.JobId = 0;
db_list_job_records(ua->jcr, ua->db, &jr, query_range.c_str(), clientname,
jobstatus, volumename, schedtime, ua->send, llist);
jobstatus, volumename, schedtime, last_run, count,
ua->send, llist);
} else if (bstrcasecmp(ua->argk[1], NT_("basefiles"))) {
/*
* List BASEFILES
Expand Down
2 changes: 1 addition & 1 deletion src/dird/ua_select.c
Expand Up @@ -820,7 +820,7 @@ POOLRES *get_pool_resource(UAContext *ua)
*/
int select_job_dbr(UAContext *ua, JOB_DBR *jr)
{
db_list_job_records(ua->jcr, ua->db, jr, "", NULL, 0, NULL, 0, ua->send, HORZ_LIST);
db_list_job_records(ua->jcr, ua->db, jr, "", NULL, 0, NULL, 0, 0, 0, ua->send, HORZ_LIST);
if (!get_pint(ua, _("Enter the JobId to select: "))) {
return 0;
}
Expand Down

0 comments on commit 25d13df

Please sign in to comment.