Skip to content

Commit

Permalink
dbcopy: add more verbose output
Browse files Browse the repository at this point in the history
  • Loading branch information
franku authored and pstorz committed Jan 31, 2020
1 parent 90f67e6 commit 12cb394
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
28 changes: 16 additions & 12 deletions core/src/dird/dbcopy/database_export_postgresql.cc
Expand Up @@ -164,30 +164,34 @@ static bool TableIsEmtpy(BareosDb* db, const std::string& table_name)
throw std::runtime_error(err);
}

if (db->SqlNumRows() > 0) {
std::cout << "DatabaseExportPostgresql: Table is not empty, skipping: ";
std::cout << table_name << std::endl;
return false;
}
if (db->SqlNumRows() > 0) { return false; }
return true;
}

bool DatabaseExportPostgresql::TableExists(const std::string& table_name)
{
auto found = table_descriptions_->GetTableDescription(table_name);
if (found == nullptr) {
std::cout << "DatabaseExportPostgresql: Table not found, skipping: ";
std::cout << table_name << std::endl;
return false;
}
if (found == nullptr) { return false; }
return true;
}

bool DatabaseExportPostgresql::StartTable(const std::string& table_name)
{
if (!TableIsEmtpy(db_, table_name)) { return false; }
std::cout << "Check if table exists: ";
std::cout << table_name << " ..." << std::flush;
if (!TableExists(table_name)) {
std::cout << " does not exist." << std::endl;
return false;
}
std::cout << " exists." << std::endl;

if (!TableExists(table_name)) { return false; }
std::cout << "Check if table is empty: ";
std::cout << table_name << " ..." << std::flush;
if (!TableIsEmtpy(db_, table_name)) {
std::cout << " not empty." << std::endl;
return false;
}
std::cout << table_name << " is empty." << std::endl;

if (db_->SqlQuery("BEGIN")) {
transaction_ = true;
Expand Down
8 changes: 7 additions & 1 deletion core/src/dird/dbcopy/database_import_mysql.cc
Expand Up @@ -85,7 +85,12 @@ void DatabaseImportMysql::RunQuerySelectAllRows(
DatabaseExport& exporter)
{
for (const auto& t : table_descriptions_->tables) {
if (!exporter.StartTable(t.table_name)) { continue; }
if (!exporter.StartTable(t.table_name)) {
std::cout << "Skipping table " << t.table_name << std::endl;
continue;
}

std::cout << "Copy data from: " << t.table_name << std::endl;

std::string query{"SELECT `"};
for (const auto& col : t.column_descriptions) {
Expand All @@ -112,6 +117,7 @@ void DatabaseImportMysql::RunQuerySelectAllRows(
}

exporter.EndTable();
std::cout << "Finished copy data from: " << t.table_name << std::endl;
// std::cout << query << std::endl << std::endl;
}
}
Expand Down
6 changes: 4 additions & 2 deletions core/src/dird/dbcopy/dbcopy.cc
Expand Up @@ -73,7 +73,7 @@ class DbConvert {

imp->ExportTo(*exp);

if (cl.compare_all_rows) { imp->CompareWith(*exp); }
// if (cl.compare_all_rows) { imp->CompareWith(*exp); }
}

private:
Expand Down Expand Up @@ -132,7 +132,7 @@ class DbConvert {
bool options_error{false};
int argument_count{};

while ((c = getopt(argc, argv, "c:del:?")) != -1 && !options_error) {
while ((c = getopt(argc, argv, "c:dl:?")) != -1 && !options_error) {
switch (c) {
case 'c':
configpath_ = optarg;
Expand All @@ -142,10 +142,12 @@ class DbConvert {
empty_destination_tables = true;
++argument_count;
break;
#if 0
case 'e':
compare_all_rows = true;
++argument_count;
break;
#endif
case 'l':
try {
maximum_number_of_rows = std::atoi(optarg);
Expand Down

0 comments on commit 12cb394

Please sign in to comment.