diff --git a/tools/import_sanef_assets.py b/tools/import_sanef_assets.py index dae18f3..151e9cf 100644 --- a/tools/import_sanef_assets.py +++ b/tools/import_sanef_assets.py @@ -121,6 +121,7 @@ def main(): continue try: + sp = conn.begin_nested() conn.execute(text(""" INSERT INTO servers (hostname, fqdn, domain_ltd, os_family, os_version, machine_type, @@ -139,11 +140,14 @@ def main(): responsable_nom = EXCLUDED.responsable_nom, patch_owner_details = EXCLUDED.patch_owner_details """), params) + sp.commit() inserted += 1 if ip: ip_map.append((hostname, ip)) except Exception as e: - print(f" [ERR] {hostname}: {e}") + try: sp.rollback() + except Exception: pass + print(f" [ERR] {hostname}: {str(e)[:200]}") skipped += 1 if not args.dry_run: