db_archiver_3.py 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. def fetch_archived_data_upload_to_s3_and_delete(
  2. archive_host, db_name, table_name, archive_db_name, archive_table_name,
  3. column_name_to_log_in_file, transaction_size, where_clause):
  4. no_of_rows_archived = db_utils.get_count_of_rows_archived(
  5. archive_db_name, archive_table_name)
  6. if not no_of_rows_archived:
  7. logging.info(
  8. f'Archive table {archive_db_name}.{archive_table_name} '
  9. f'had no rows, dropping archive table')
  10. db_utils.drop_archive_table(archive_db_name, archive_table_name)
  11. return None
  12. local_file_name, s3_path = db_utils.get_file_names(
  13. db_name, table_name, archive_db_name, archive_table_name,
  14. column_name_to_log_in_file, where_clause)
  15. archive_utils.archive_to_file(
  16. archive_host, archive_db_name, archive_table_name, transaction_size, local_file_name)
  17. gzip_file_name = compress_to_gzip(local_file_name)
  18. gzip_s3_path = f'{s3_path}.gz'
  19. # s3_utils.upload_to_s3(local_file_name, s3_path)
  20. s3_utils.upload_to_s3(gzip_file_name, gzip_s3_path)
  21. logging.info(f'Deleting local file: {local_file_name}')
  22. os.remove(local_file_name)
  23. os.remove(gzip_file_name)
  24. db_utils.drop_archive_table(archive_db_name, archive_table_name)
  25. return None