-
-
Save vdhaks111/85c40d0d0e611f98aa0838ddf41ebe0d to your computer and use it in GitHub Desktop.
Unity Catalog metadata backup script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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