Skip to content

Commit

Permalink
list volumes: cleanup
Browse files Browse the repository at this point in the history
Changed output of "list volumes jobid=XXX" from

  Jobid %d used %d Volume(s): VOL1|VOL2|...

to the typical list based output used by the other list functions.
  • Loading branch information
joergsteffens committed Mar 22, 2018
1 parent ec91505 commit 0e62f6f
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 80 deletions.
4 changes: 3 additions & 1 deletion src/cats/bdb_query_enum_class.h
Expand Up @@ -78,6 +78,8 @@ class B_DB_QUERY_ENUM_CLASS {
SQL_QUERY_get_bad_paths_0 = 72,
SQL_QUERY_bvfs_ls_special_dirs_3 = 73,
SQL_QUERY_bvfs_ls_sub_dirs_5 = 74,
SQL_QUERY_NUMBER = 75
SQL_QUERY_list_volumes_select_0 = 75,
SQL_QUERY_list_volumes_select_long_0 = 76,
SQL_QUERY_NUMBER = 77
} SQL_QUERY_ENUM;
};
2 changes: 2 additions & 0 deletions src/cats/bdb_query_names.inc
Expand Up @@ -76,5 +76,7 @@ const char *B_DB::query_names[] = {
"get_bad_paths_0",
"bvfs_ls_special_dirs_3",
"bvfs_ls_sub_dirs_5",
"list_volumes_select_0",
"list_volumes_select_long_0",
NULL
};
3 changes: 2 additions & 1 deletion src/cats/cats.h
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2000-2012 Free Software Foundation Europe e.V.
Copyright (C) 2011-2016 Planets Communications B.V.
Copyright (C) 2013-2017 Bareos GmbH & Co. KG
Copyright (C) 2013-2018 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -740,6 +740,7 @@ class CATS_IMP_EXP B_DB: public SMARTALLOC, public B_DB_QUERY_ENUM_CLASS {
void list_storage_records(JCR *jcr, OUTPUT_FORMATTER *sendit, e_list_type type);
void list_media_records(JCR *jcr, MEDIA_DBR *mdbr, const char *range, bool count, OUTPUT_FORMATTER *sendit, e_list_type type);
void list_jobmedia_records(JCR *jcr, JobId_t JobId, OUTPUT_FORMATTER *sendit, e_list_type type);
void list_volumes_of_jobid(JCR *jcr, JobId_t JobId, OUTPUT_FORMATTER *sendit, e_list_type type);
void list_joblog_records(JCR *jcr, JobId_t JobId, const char *range, bool count, OUTPUT_FORMATTER *sendit, e_list_type type);
void list_log_records(JCR *jcr, const char *clientname, const char *range,
bool reverse, OUTPUT_FORMATTER *sendit, e_list_type type);
Expand Down
6 changes: 6 additions & 0 deletions src/cats/dml/0076_list_volumes_select_0
@@ -0,0 +1,6 @@
SELECT MediaId,VolumeName,VolStatus,Enabled,
VolBytes,VolFiles,VolRetention,Recycle,Slot,InChanger,
MediaType,LastWritten,Name AS Storage
FROM Media
LEFT JOIN Storage USING(StorageId)

11 changes: 11 additions & 0 deletions src/cats/dml/0077_list_volumes_select_long_0
@@ -0,0 +1,11 @@
SELECT MediaId,VolumeName,Slot,PoolId,
MediaType,FirstWritten,LastWritten,LabelDate,VolJobs,
VolFiles,VolBlocks,VolMounts,VolBytes,VolErrors,VolWrites,
VolCapacityBytes,VolStatus,Enabled,Recycle,VolRetention,
VolUseDuration,MaxVolJobs,MaxVolFiles,MaxVolBytes,InChanger,
EndFile,EndBlock,LabelType,StorageId,DeviceId,
LocationId,RecycleCount,InitialWrite,ScratchPoolId,RecyclePoolId,
Comment,Name AS Storage
FROM Media
LEFT JOIN Storage USING(StorageId)

21 changes: 21 additions & 0 deletions src/cats/mysql_queries.inc
Expand Up @@ -952,5 +952,26 @@ const char *B_DB_MYSQL::query_definitions[] = {
") AS A "
,

/* 0076_list_volumes_select_0 */
"SELECT MediaId,VolumeName,VolStatus,Enabled, "
"VolBytes,VolFiles,VolRetention,Recycle,Slot,InChanger, "
"MediaType,LastWritten,Name AS Storage "
"FROM Media "
"LEFT JOIN Storage USING(StorageId) "
,

/* 0077_list_volumes_select_long_0 */
"SELECT MediaId,VolumeName,Slot,PoolId, "
"MediaType,FirstWritten,LastWritten,LabelDate,VolJobs, "
"VolFiles,VolBlocks,VolMounts,VolBytes,VolErrors,VolWrites, "
"VolCapacityBytes,VolStatus,Enabled,Recycle,VolRetention, "
"VolUseDuration,MaxVolJobs,MaxVolFiles,MaxVolBytes,InChanger, "
"EndFile,EndBlock,LabelType,StorageId,DeviceId, "
"LocationId,RecycleCount,InitialWrite,ScratchPoolId,RecyclePoolId, "
"Comment,Name AS Storage "
"FROM Media "
"LEFT JOIN Storage USING(StorageId) "
,

NULL
};
21 changes: 21 additions & 0 deletions src/cats/postgresql_queries.inc
Expand Up @@ -928,5 +928,26 @@ const char *B_DB_POSTGRESQL::query_definitions[] = {
") AS A "
,

/* 0076_list_volumes_select_0 */
"SELECT MediaId,VolumeName,VolStatus,Enabled, "
"VolBytes,VolFiles,VolRetention,Recycle,Slot,InChanger, "
"MediaType,LastWritten,Name AS Storage "
"FROM Media "
"LEFT JOIN Storage USING(StorageId) "
,

/* 0077_list_volumes_select_long_0 */
"SELECT MediaId,VolumeName,Slot,PoolId, "
"MediaType,FirstWritten,LastWritten,LabelDate,VolJobs, "
"VolFiles,VolBlocks,VolMounts,VolBytes,VolErrors,VolWrites, "
"VolCapacityBytes,VolStatus,Enabled,Recycle,VolRetention, "
"VolUseDuration,MaxVolJobs,MaxVolFiles,MaxVolBytes,InChanger, "
"EndFile,EndBlock,LabelType,StorageId,DeviceId, "
"LocationId,RecycleCount,InitialWrite,ScratchPoolId,RecyclePoolId, "
"Comment,Name AS Storage "
"FROM Media "
"LEFT JOIN Storage USING(StorageId) "
,

NULL
};
124 changes: 54 additions & 70 deletions src/cats/sql_list.cc
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2000-2009 Free Software Foundation Europe e.V.
Copyright (C) 2011-2016 Planets Communications B.V.
Copyright (C) 2013-2017 Bareos GmbH & Co. KG
Copyright (C) 2013-2018 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -191,8 +191,9 @@ void B_DB::list_media_records(JCR *jcr, MEDIA_DBR *mdbr, const char *range, bool
{
char ed1[50];
char esc[MAX_ESCAPE_NAME_LENGTH];
POOL_MEM select(PM_MESSAGE);
POOL_MEM query(PM_MESSAGE);

db_lock(this);
escape_string(jcr, esc, mdbr->VolumeName, strlen(mdbr->VolumeName));

/*
Expand All @@ -205,88 +206,34 @@ void B_DB::list_media_records(JCR *jcr, MEDIA_DBR *mdbr, const char *range, bool
range = "";
}

if (type == VERT_LIST) {
if (count) {
/* NOTE: ACLs are ignored. */
if (mdbr->VolumeName[0] != 0) {
Mmsg(cmd, "SELECT MediaId,VolumeName,Slot,PoolId,"
"MediaType,FirstWritten,LastWritten,LabelDate,VolJobs,"
"VolFiles,VolBlocks,VolMounts,VolBytes,VolErrors,VolWrites,"
"VolCapacityBytes,VolStatus,Enabled,Recycle,VolRetention,"
"VolUseDuration,MaxVolJobs,MaxVolFiles,MaxVolBytes,InChanger,"
"EndFile,EndBlock,LabelType,StorageId,DeviceId,"
"LocationId,RecycleCount,InitialWrite,ScratchPoolId,RecyclePoolId, "
"Comment,Name AS Storage "
"FROM Media "
"LEFT JOIN Storage USING(StorageId) "
"WHERE Media.VolumeName='%s'", esc);
fill_query(query, SQL_QUERY_list_volumes_by_name_count_1, esc);
} else if (mdbr->PoolId > 0) {
Mmsg(cmd, "SELECT MediaId,VolumeName,Slot,PoolId,"
"MediaType,FirstWritten,LastWritten,LabelDate,VolJobs,"
"VolFiles,VolBlocks,VolMounts,VolBytes,VolErrors,VolWrites,"
"VolCapacityBytes,VolStatus,Enabled,Recycle,VolRetention,"
"VolUseDuration,MaxVolJobs,MaxVolFiles,MaxVolBytes,InChanger,"
"EndFile,EndBlock,LabelType,StorageId,DeviceId,"
"LocationId,RecycleCount,InitialWrite,ScratchPoolId,RecyclePoolId, "
"Comment,Name AS Storage "
"FROM Media "
"LEFT JOIN Storage USING(StorageId) "
"WHERE Media.PoolId=%s ORDER BY MediaId "
"%s",
edit_int64(mdbr->PoolId, ed1), range);
fill_query(query, SQL_QUERY_list_volumes_by_poolid_count_1, edit_int64(mdbr->PoolId, ed1));
} else {
Mmsg(cmd, "SELECT MediaId,VolumeName,Slot,PoolId,"
"MediaType,FirstWritten,LastWritten,LabelDate,VolJobs,"
"VolFiles,VolBlocks,VolMounts,VolBytes,VolErrors,VolWrites,"
"VolCapacityBytes,VolStatus,Enabled,Recycle,VolRetention,"
"VolUseDuration,MaxVolJobs,MaxVolFiles,MaxVolBytes,InChanger,"
"EndFile,EndBlock,LabelType,StorageId,DeviceId,"
"LocationId,RecycleCount,InitialWrite,ScratchPoolId,RecyclePoolId, "
"Comment,Name AS Storage "
"FROM Media "
"LEFT JOIN Storage USING(StorageId) "
"ORDER BY MediaId "
"%s", range);
fill_query(query, SQL_QUERY_list_volumes_count_0);
}
} else {
if (mdbr->VolumeName[0] != 0) {
Mmsg(cmd, "SELECT MediaId,VolumeName,VolStatus,Enabled,"
"VolBytes,VolFiles,VolRetention,Recycle,Slot,InChanger,"
"MediaType,LastWritten,Name AS Storage "
"FROM Media "
"LEFT JOIN Storage USING(StorageId) "
"WHERE VolumeName='%s'", esc);
} else if (mdbr->PoolId > 0) {
Mmsg(cmd, "SELECT MediaId,VolumeName,VolStatus,Enabled,"
"VolBytes,VolFiles,VolRetention,Recycle,Slot,InChanger,"
"MediaType,LastWritten,Name AS Storage "
"FROM Media "
"LEFT JOIN Storage USING(StorageId) "
"WHERE PoolId=%s ORDER BY MediaId "
"%s",
edit_int64(mdbr->PoolId, ed1), range);
if (type == VERT_LIST) {
fill_query(select, SQL_QUERY_list_volumes_select_long_0);
} else {
Mmsg(cmd, "SELECT MediaId,VolumeName,VolStatus,Enabled,"
"VolBytes,VolFiles,VolRetention,Recycle,Slot,InChanger,"
"MediaType,LastWritten,Name AS Storage "
"FROM Media "
"LEFT JOIN Storage USING(StorageId) "
"ORDER BY MediaId "
"%s",
range);
fill_query(select, SQL_QUERY_list_volumes_select_0);
}
}

if (count) {
/* NOTE: ACLs are ignored. */
if (mdbr->VolumeName[0] != 0) {
fill_query(SQL_QUERY_list_volumes_by_name_count_1, esc);
query.bsprintf("%s WHERE VolumeName='%s'", select.c_str(), esc);
} else if (mdbr->PoolId > 0) {
fill_query(SQL_QUERY_list_volumes_by_poolid_count_1, edit_int64(mdbr->PoolId, ed1));
query.bsprintf("%s WHERE PoolId=%s ORDER BY MediaId %s", select.c_str(), edit_int64(mdbr->PoolId, ed1), range);
} else {
fill_query(SQL_QUERY_list_volumes_count_0);
query.bsprintf("%s ORDER BY MediaId %s", select.c_str(), range);
}
}

if (!QUERY_DB(jcr, cmd)) {
db_lock(this);

if (!QUERY_DB(jcr, query.c_str())) {
goto bail_out;
}

Expand All @@ -298,6 +245,8 @@ void B_DB::list_media_records(JCR *jcr, MEDIA_DBR *mdbr, const char *range, bool
db_unlock(this);
}



void B_DB::list_jobmedia_records(JCR *jcr, uint32_t JobId, OUTPUT_FORMATTER *sendit, e_list_type type)
{
char ed1[50];
Expand Down Expand Up @@ -341,6 +290,41 @@ void B_DB::list_jobmedia_records(JCR *jcr, uint32_t JobId, OUTPUT_FORMATTER *sen
db_unlock(this);
}


void B_DB::list_volumes_of_jobid(JCR *jcr, uint32_t JobId, OUTPUT_FORMATTER *sendit, e_list_type type)
{
char ed1[50];

if (JobId <= 0) {
return;
}

db_lock(this);
if (type == VERT_LIST) {
Mmsg(cmd, "SELECT JobMediaId,JobId,Media.MediaId,Media.VolumeName "
"FROM JobMedia,Media WHERE Media.MediaId=JobMedia.MediaId "
"AND JobMedia.JobId=%s", edit_int64(JobId, ed1));
} else {
Mmsg(cmd, "SELECT Media.VolumeName "
"FROM JobMedia,Media WHERE Media.MediaId=JobMedia.MediaId "
"AND JobMedia.JobId=%s", edit_int64(JobId, ed1));
}
if (!QUERY_DB(jcr, cmd)) {
goto bail_out;
}

sendit->array_start("volumes");
list_result(jcr, sendit, type);
sendit->array_end("volumes");

sql_free_result();

bail_out:
db_unlock(this);
}



void B_DB::list_copies_records(JCR *jcr, const char *range, const char *JobIds,
OUTPUT_FORMATTER *send, e_list_type type)
{
Expand Down
21 changes: 21 additions & 0 deletions src/cats/sqlite_queries.inc
Expand Up @@ -937,5 +937,26 @@ const char *B_DB_SQLITE::query_definitions[] = {
") AS A "
,

/* 0076_list_volumes_select_0 */
"SELECT MediaId,VolumeName,VolStatus,Enabled, "
"VolBytes,VolFiles,VolRetention,Recycle,Slot,InChanger, "
"MediaType,LastWritten,Name AS Storage "
"FROM Media "
"LEFT JOIN Storage USING(StorageId) "
,

/* 0077_list_volumes_select_long_0 */
"SELECT MediaId,VolumeName,Slot,PoolId, "
"MediaType,FirstWritten,LastWritten,LabelDate,VolJobs, "
"VolFiles,VolBlocks,VolMounts,VolBytes,VolErrors,VolWrites, "
"VolCapacityBytes,VolStatus,Enabled,Recycle,VolRetention, "
"VolUseDuration,MaxVolJobs,MaxVolFiles,MaxVolBytes,InChanger, "
"EndFile,EndBlock,LabelType,StorageId,DeviceId, "
"LocationId,RecycleCount,InitialWrite,ScratchPoolId,RecyclePoolId, "
"Comment,Name AS Storage "
"FROM Media "
"LEFT JOIN Storage USING(StorageId) "
,

NULL
};
10 changes: 2 additions & 8 deletions src/dird/ua_output.cc
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2000-2012 Free Software Foundation Europe e.V.
Copyright (C) 2011-2016 Planets Communications B.V.
Copyright (C) 2013-2017 Bareos GmbH & Co. KG
Copyright (C) 2013-2018 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -905,13 +905,7 @@ static bool do_list_cmd(UAContext *ua, const char *cmd, e_list_type llist)
*/
jobid = get_jobid_from_cmdline(ua);
if (jobid > 0) {
int num_vols = 0;
POOLMEM *VolumeName;

VolumeName = get_pool_memory(PM_FNAME);
num_vols = ua->db->get_job_volume_names(ua->jcr, jobid, VolumeName);
ua->send_msg(_("Jobid %d used %d Volume(s): %s\n"), jobid, num_vols, VolumeName);
free_pool_memory(VolumeName);
ua->db->list_volumes_of_jobid(ua->jcr, jobid, ua->send, llist);
} else if (jobid == 0) {
/*
* List a specific volume?
Expand Down

0 comments on commit 0e62f6f

Please sign in to comment.