forked from ScoDoc/ScoDoc
Fix bug export db
This commit is contained in:
parent
e159ca23ad
commit
d7fce217ec
@ -129,7 +129,7 @@ def _duplicate_db(db_uri: str, db_name: str, ano_db_uri: str, ano_db_name: str):
|
|||||||
f"erreur lors de la creation de la base {ano_db_name}"
|
f"erreur lors de la creation de la base {ano_db_name}"
|
||||||
) from e
|
) from e
|
||||||
|
|
||||||
cmd = ["pg_dump", db_uri, "|", "psql", ano_db_uri]
|
cmd = f"pg_dump {db_uri} | psql {ano_db_uri}"
|
||||||
log("sco_dump_and_send_db/_duplicate_db: {}".format(cmd))
|
log("sco_dump_and_send_db/_duplicate_db: {}".format(cmd))
|
||||||
try:
|
try:
|
||||||
_ = subprocess.check_output(cmd, shell=1)
|
_ = subprocess.check_output(cmd, shell=1)
|
||||||
@ -173,8 +173,9 @@ def _send_db(
|
|||||||
"""Dump this (anonymized) database and send it to tech support"""
|
"""Dump this (anonymized) database and send it to tech support"""
|
||||||
log(f"dumping anonymized database {ano_db_name}")
|
log(f"dumping anonymized database {ano_db_name}")
|
||||||
try:
|
try:
|
||||||
cmd = ["pg_dump", "--format=custom", ano_db_uri]
|
dump = subprocess.check_output(
|
||||||
dump = subprocess.check_output(cmd, shell=1)
|
f"pg_dump --format=custom {ano_db_name}", shell=1
|
||||||
|
)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
log(f"sco_dump_and_send_db: exception in anonymisation: {e}")
|
log(f"sco_dump_and_send_db: exception in anonymisation: {e}")
|
||||||
raise ScoValueError(
|
raise ScoValueError(
|
||||||
|
@ -205,6 +205,8 @@ def anonymize_users(cursor):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def uri_rm_passwd(uri):
|
||||||
|
return re.compile(r'(postgres://[^:]+:)([^@]+)(@)').sub(r'\1*****\3', uri)
|
||||||
|
|
||||||
def anonymize_db(cursor):
|
def anonymize_db(cursor):
|
||||||
"""Traite, une à une, les colonnes indiquées dans ANONYMIZED_FIELDS"""
|
"""Traite, une à une, les colonnes indiquées dans ANONYMIZED_FIELDS"""
|
||||||
@ -230,7 +232,7 @@ if __name__ == "__main__":
|
|||||||
cnx = psycopg2.connect(dburi)
|
cnx = psycopg2.connect(dburi)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log(f"\n*** Error: can't connect to database {dbname} ***\n")
|
log(f"\n*** Error: can't connect to database {dbname} ***\n")
|
||||||
log(f"""connexion uri was "{re.compile(r'(postgres://[^:]+:)([^@]+)(@)').sub(r'\1*****\3', uri)}" """)
|
log(f"""connexion uri was "{uri_rm_passwd(dburi)}" """)
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
cnx.set_session(autocommit=False)
|
cnx.set_session(autocommit=False)
|
||||||
@ -242,4 +244,4 @@ if __name__ == "__main__":
|
|||||||
anonymize_users(cursor)
|
anonymize_users(cursor)
|
||||||
|
|
||||||
cnx.commit()
|
cnx.commit()
|
||||||
cnx.close()
|
cnx.close()
|
Loading…
Reference in New Issue
Block a user