Author: mattm
Date: 2016-10-12 14:07:36 +0200 (Wed, 12 Oct 2016)
New Revision: 26384

Modified:
   trunk/openvas-manager/ChangeLog
   trunk/openvas-manager/tools/openvas-migrate-to-postgres.in
Log:
        * tools/openvas-migrate-to-postgres.in (copy_data): Check that the
        tables being copied include all the tables in the SQLite db.
        (TABLES_133, TABLES_135): Add agents and agents_trash.
        (TABSES_134): Remove quotes to match others.

Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog     2016-10-12 11:54:02 UTC (rev 26383)
+++ trunk/openvas-manager/ChangeLog     2016-10-12 12:07:36 UTC (rev 26384)
@@ -1,3 +1,10 @@
+2016-10-12  Matthew Mundell <matthew.mund...@greenbone.net>
+
+       * tools/openvas-migrate-to-postgres.in (copy_data): Check that the
+       tables being copied include all the tables in the SQLite db.
+       (TABLES_133, TABLES_135): Add agents and agents_trash.
+       (TABSES_134): Remove quotes to match others.
+
 2016-10-12  Timo Pollmeier <timo.pollme...@greenbone.net>
 
        * src/manage_sql.c (init_aggregate_iterator): Also fall back to the

Modified: trunk/openvas-manager/tools/openvas-migrate-to-postgres.in
===================================================================
--- trunk/openvas-manager/tools/openvas-migrate-to-postgres.in  2016-10-12 
11:54:02 UTC (rev 26383)
+++ trunk/openvas-manager/tools/openvas-migrate-to-postgres.in  2016-10-12 
12:07:36 UTC (rev 26384)
@@ -1032,19 +1032,33 @@
        exit 1
   fi
 
-  log_info "Dumping SQLite3 data:"
+  log_info "Copying SQLite3 data:"
   TEMP_DIR=`mktemp -d`
   log_debug "TEMP_DIR: $TEMP_DIR"
 
-  # These must be ordered to respect foreign keys.
+  # Tables must be ordered to respect foreign keys.
   #
-  # To get all tables use ".tables" or
-  #     SELECT tbl_name FROM sqlite_master WHERE type='table' and tbl_name not 
like 'sqlite_%'
-  #
   # These tables are left out: report_counts nvts nvt_cves
 
+  log_info "Copying SQLite3 data: checking that tables match"
+
   TABLES=$1
   log_debug "TABLES: $TABLES"
+
+  SQLITE_TABLES=`sqlite "SELECT tbl_name FROM sqlite_master WHERE type='table' 
and tbl_name not like 'sqlite_%';"`
+  test_sql_exit "Failed get table list"
+  log_debug "SQLITE_TABLES: $SQLITE_TABLES"
+
+  echo $SQLITE_TABLES | tr -s ' ' '\n' | sort - | grep --invert-match 
"^\(nvt_cves\|nvts\|report_counts\)" > $TEMP_DIR/sqlite_tables_sorted
+  echo $TABLES | tr -s ' ' '\n' | sort - | diff - 
$TEMP_DIR/sqlite_tables_sorted
+  if [ $? -ne 0 ]
+  then
+    log_notice "Internal Error: tables being copied do not match tables in 
SQLite db"
+       exit 1
+  fi
+
+  log_info "Copying SQLite3 data: copying"
+
   for TABLE in $TABLES; do
     # Get the Postgres columns because the import CSV must be in that order.
     #
@@ -1061,7 +1075,7 @@
   # Force a --rebuild.
   pg "DELETE FROM meta WHERE name = 'nvts_feed_version';"
 
-  log_info "Resetting Postgres sequences"
+  log_info "Copying SQLite3 data: resetting Postgres sequences"
   # Reset ID sequences, because the COPY specified the ID values explicitly.
   pg "SELECT 'SELECT 1'
              || ' WHERE'
@@ -1098,7 +1112,7 @@
 ## NB These only need to migrate the schema.
 ##
 
-TABLES_133="users configs config_preferences meta nvt_preferences 
nvt_selectors lsc_credentials lsc_credentials_trash port_lists port_ranges 
targets schedules slaves tasks reports report_hosts report_formats 
report_format_params report_format_param_options results report_results 
task_files configs_trash config_preferences_trash report_formats_trash 
report_format_params_trash report_format_param_options_trash schedules_trash 
slaves_trash targets_trash report_host_details task_preferences 
port_lists_trash port_ranges_trash alerts_trash alert_event_data_trash 
alert_method_data_trash alerts alert_condition_data alert_event_data 
alert_method_data task_alerts alert_condition_data_trash groups group_users 
filters filters_trash port_names settings roles role_users overrides 
overrides_trash notes notes_trash groups_trash roles_trash tags_trash 
group_users_trash role_users_trash scanners scanners_trash permissions_trash 
permissions tags"
+TABLES_133="users agents agents_trash configs config_preferences meta 
nvt_preferences nvt_selectors lsc_credentials lsc_credentials_trash port_lists 
port_ranges targets schedules slaves tasks reports report_hosts report_formats 
report_format_params report_format_param_options results report_results 
task_files configs_trash config_preferences_trash report_formats_trash 
report_format_params_trash report_format_param_options_trash schedules_trash 
slaves_trash targets_trash report_host_details task_preferences 
port_lists_trash port_ranges_trash alerts_trash alert_event_data_trash 
alert_method_data_trash alerts alert_condition_data alert_event_data 
alert_method_data task_alerts alert_condition_data_trash groups group_users 
filters filters_trash port_names settings roles role_users overrides 
overrides_trash notes notes_trash groups_trash roles_trash tags_trash 
group_users_trash role_users_trash scanners scanners_trash permissions_trash 
permissions tags"
 
 migrate_133_to_134 () {
   pg "ALTER TABLE targets ADD COLUMN esxi_lsc_credential integer;"
@@ -1106,13 +1120,13 @@
   pg "ALTER TABLE targets_trash ADD COLUMN esxi_location integer;"
 }
 
-TABLES_134="$TABLES_133"
+TABLES_134=$TABLES_133
 
 migrate_134_to_135 () {
   pg "DROP TABLE report_results;"
 }
 
-TABLES_135="users configs config_preferences meta nvt_preferences 
nvt_selectors lsc_credentials lsc_credentials_trash port_lists port_ranges 
targets schedules slaves tasks reports report_hosts report_formats 
report_format_params report_format_param_options results task_files 
configs_trash config_preferences_trash report_formats_trash 
report_format_params_trash report_format_param_options_trash schedules_trash 
slaves_trash targets_trash report_host_details task_preferences 
port_lists_trash port_ranges_trash alerts_trash alert_event_data_trash 
alert_method_data_trash alerts alert_condition_data alert_event_data 
alert_method_data task_alerts alert_condition_data_trash groups group_users 
filters filters_trash port_names settings roles role_users overrides 
overrides_trash notes notes_trash groups_trash roles_trash tags_trash 
group_users_trash role_users_trash scanners scanners_trash permissions_trash 
permissions tags"
+TABLES_135="users agents agents_trash configs config_preferences meta 
nvt_preferences nvt_selectors lsc_credentials lsc_credentials_trash port_lists 
port_ranges targets schedules slaves tasks reports report_hosts report_formats 
report_format_params report_format_param_options results task_files 
configs_trash config_preferences_trash report_formats_trash 
report_format_params_trash report_format_param_options_trash schedules_trash 
slaves_trash targets_trash report_host_details task_preferences 
port_lists_trash port_ranges_trash alerts_trash alert_event_data_trash 
alert_method_data_trash alerts alert_condition_data alert_event_data 
alert_method_data task_alerts alert_condition_data_trash groups group_users 
filters filters_trash port_names settings roles role_users overrides 
overrides_trash notes notes_trash groups_trash roles_trash tags_trash 
group_users_trash role_users_trash scanners scanners_trash permissions_trash 
permissions tags"
 
 migrate_135_to_136 () {
   : # Schema stayed the same.
@@ -1182,13 +1196,14 @@
   pg "DROP VIEW IF EXISTS result_overrides;"
 }
 
-# FIX tables were added since 133?
 TABLES_146=$TABLES_145
 
 migrate_146_to_147 () {
   pg "ALTER TABLE report_counts ADD COLUMN min_qod INTEGER;"
 }
 
+# FIX tables were added to rest?
+
 TABLES_147=$TABLES_146
 
 migrate_147_to_148 () {

_______________________________________________
Openvas-commits mailing list
Openvas-commits@wald.intevation.org
https://lists.wald.intevation.org/cgi-bin/mailman/listinfo/openvas-commits

Reply via email to