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"]))
相关推荐
想你依然心痛3 小时前
系统存储机制深度剖析:从Win11临时文件夹设计看微软存储架构演进
microsoft·架构
weixin_BYSJ19877 小时前
springboot3家政平台小程序--附源码00904
java·javascript·spring boot·python·django·flask·php
制造数据与AI践行者老蒋1 天前
离谱!PromptTemplate 遇上 JSON,花括号直接引发解析战争
数据库·microsoft·json
行者-全栈开发1 天前
CVE-2026-45659:Microsoft SharePoint远程代码执行漏洞深度解析与修复指南
microsoft·sharepoint·反序列化·运维自动化·安全修复·远程代码执行·cve-2026-45659
第二个人1 天前
Python Web开发:从Flask到FastAPI,我经历了什么
前端·python·flask
zwd20051 天前
Manim DLL 报错,先别重装 Python|把环境问题拆成可验证的步骤
microsoft
這花開嗎2 天前
2026年TTS文字转语音API哪家强?批量自动化配音成本与技术实测
python·flask·自动化
zandy10112 天前
体验家 XMPlus 问卷答题体验优化与完成率提升引擎:从交互设计到行为心理学的工程化实践
windows·microsoft·交互
Albart5752 天前
2026年Python入门路线图:从零到实战的30天逐日详解(三)
学习·flask·#python30 天入门·python 实战教程·pytest 单元测试·python 虚拟环境·logging 日志
码银2 天前
放弃了豆包,我使用Python做了一个桌面宠物
python·microsoft·宠物