Azure databricks 还原备份的操作

起因:databricks 面临从HK迁移到国内的情况,目前只是迁移单个库就好,不需要全迁移,问了下azure的技术支持,把数据通过azure客户端azure copy 到指定源--》目标 目录就可

这一块参考:

bash 复制代码
 https://docs.microsoft.com/zh-cn/azure/storage/common/storage-use-azcopy-blobs-copy

那拷贝过来后如何读取在storage目录中的数据呢?主要用的是python脚本来读取

bash 复制代码
#1、先要做好集群与storage的验证这一块没有搞好就需要重新来
# 目标表的databases

databaseName_target = "ods_xxx_xxx"

# Create tables including both of partition and non-partition

sqlQueryCreateExternalTable = "CREATE EXTERNAL TABLE IF NOT EXISTS {0}.{1} USING {2} LOCATION '{3}'"
sqlQueryRecoverPartitions = "ALTER TABLE {0}.{1} RECOVER PARTITIONS"
path ="/demo/warehouse/库名/"

for row in tableNames:
    try:
        flag = 0
        partitionName = ""
        tableBaseDirectory = spark.createDataFrame(dbutils.fs.ls((row["path"].replace('dbfs:', '')))).collect()

        for rowDirectory in tableBaseDirectory:
#            print(rowDirectory)
            if rowDirectory["size"] != 0:
                flag = -1
            else:
                partitionName = rowDirectory["name"].split('=')[0]
                
        if flag == -1:
            spark.sql(sqlQueryCreateExternalTable.format(databaseName_target, row["name"], dataSource, row["path"]))
            print("INFO: {0} completed.".format(sqlQueryCreateExternalTable.format(databaseName_target, row["name"], dataSource, row["path"])))
        else:
            spark.sql(sqlQueryCreateExternalTable.format(databaseName_target, row["name"], dataSource, row["path"]))
            print("WARN: Table {0}.{1} has PARTITIONED BY {2}.".format(databaseName_target, row["name"], partitionName))
            spark.sql(sqlQueryRecoverPartitions.format(databaseName_target, row["name"]))
            print("INFO: Table {0}.{1} has been RECOVER PARTITIONED BY {2} completed.".format(databaseName_target, row["name"], partitionName))
    except Exception as e:
        print(e)
        print("ERROR: Create table {0} failed.".format(row["name"]))
相关推荐
stark张宇2 天前
构建第一个AI聊天机器人:Flask+DeepSeek+Postgres实战
人工智能·postgresql·flask
百锦再11 天前
Django实现接口token检测的实现方案
数据库·python·django·sqlite·flask·fastapi·pip
QQ51100828511 天前
python+springboot+django/flask的校园资料分享系统
spring boot·python·django·flask·node.js·php
QQ_196328847511 天前
Python-flask框架西山区家政服务评价系统网站设计与开发-Pycharm django
python·pycharm·flask
计算机专业码农一枚11 天前
Python-flask框架基于推荐算法的在线课程推荐系统设计与实现-Pycharm django
python·flask·推荐算法
科技前瞻观察11 天前
腾讯控股下的销售易,如何重塑中国CRM格局?
microsoft
NGINX开源社区11 天前
使用 Microsoft Entra ID 配置 NGINX Plus 以实现 SAML SSO
后端·python·flask
电商API&Tina11 天前
京东商品详情API接口接入与应用
数据库·microsoft
發糞塗牆11 天前
【Azure 架构师学习笔记 】- Azure AI(7)-Azure认知服务-Document Intelligence进阶使用
人工智能·ai·azure
yuan1999712 天前
基于C#实现的专业级DXF文件显示控件
windows·microsoft·c#