Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vdhaks111/85c40d0d0e611f98aa0838ddf41ebe0d to your computer and use it in GitHub Desktop.
Save vdhaks111/85c40d0d0e611f98aa0838ddf41ebe0d to your computer and use it in GitHub Desktop.
Unity Catalog metadata backup script
#
# For every table in information schema, make a backup copy of it to the storage location
#
table_list = spark.catalog.listTables(f"`{catalog_name}`.information_schema")
for table in table_list:
print(f'backing up {table.catalog}.information_schema.{table.name} to {storage_location}/{table.name}...')
info_schema_table_df = spark.sql(f"SELECT * FROM {table.catalog}.information_schema.{table.name}")
info_schema_table_df.write.format("delta").mode("overwrite").save(f"{storage_location}/{table.name}")
print('backup complete')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment