@@ -17,6 +17,7 @@ true "${CFE_FR_COMPRESSOR_EXT?undefined}"
1717true " ${CFE_FR_EXTRACTOR?undefined} "
1818true " ${CFE_FR_TABLES?undefined} "
1919true " ${CFE_FR_INVENTORY_REFRESH_CMD?undefined} "
20+ true " ${CFE_FR_HANDLE_DUPLICATES?undefined} "
2021
2122if ! type " $CFE_FR_EXTRACTOR " > /dev/null; then
2223 log " Extractor $CFE_FR_EXTRACTOR not available!"
@@ -57,8 +58,10 @@ table_whitelist=$(printf "'%s'," $CFE_FR_TABLES | sed -e 's/,$//')
5758
5859failed=0
5960log " Setting up schemas for import"
61+ declare -a hostkeys
6062for file in $dump_files ; do
6163 hostkey=$( basename " $file " | cut -d. -f1)
64+ hostkeys+=($hostkey )
6265 " $CFE_BIN_DIR " /psql -U $CFE_FR_DB_USER -d cfdb --set " ON_ERROR_STOP=1" \
6366 -c " SELECT ensure_feeder_schema('$hostkey ', ARRAY[$table_whitelist ]);" \
6467 > schema_setup.log 2>&1 || failed=1
@@ -100,6 +103,22 @@ else
100103 done
101104fi
102105
106+ if [ " $CFE_FR_HANDLE_DUPLICATES " = " yes" ]; then
107+ log " Handle Duplicate Hostkeys"
108+ hostkey_list=$( printf " '%s'," ${hostkeys[*]} | sed -e ' s/,$//' )
109+ " $CFE_BIN_DIR " /psql -U $CFE_FR_DB_USER -d cfdb --set " ON_ERROR_STOP=1" \
110+ -c " SELECT handle_duplicate_hostkeys_in_import(ARRAY[$hostkey_list ]);" \
111+ > duplicates.log 2>&1 || failed=1
112+ if [ " $failed " = " 0" ]; then
113+ log " Handle Duplicate Hostkeys: DONE"
114+ else
115+ log " Handle Duplicate Hostkeys: FAILED"
116+ log " last 10 lines of duplicates.log"
117+ tail -n 10 duplicates.log
118+ exit 1
119+ fi
120+ fi
121+
103122failed=0
104123log " Attaching schemas"
105124for file in $dump_files ; do
0 commit comments