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"]))
相关推荐
编码者卢布11 小时前
【Azure Developer】IIS w3wp.exe 的 -m 参数:一个未被记录的管道模式标识
microsoft·flask·azure
qq_2837200511 小时前
Python Web 开发:Flask 快速入门教程
python·flask·web
洛水如云18 小时前
换新电脑数据迁移全攻略:2 种方法转移文件 / 系统
windows·microsoft·电脑
小熊Coding20 小时前
Windows 上安装 mysqlclient 时遇到了编译错误,核心原因是缺少 Microsoft Visual C++ 14.0 或更高版本 的编译环境。
c++·windows·python·microsoft·django·mysqlclient·bug记录
顾喵1 天前
SRIO通信总线
linux·windows·microsoft
yongyoudayee2 天前
2026中国企业出海CRM:五大平台技术能力对比
后端·python·flask
m0_738120722 天前
渗透测试基础ctfshow——Web应用安全与防护(四)
前端·安全·web安全·网络安全·flask·弱口令爆破
编码者卢布2 天前
【Azure App Service】PHP页面上传文件413错误的解决方案
microsoft·php·azure
BPM6662 天前
2026主流工作流引擎评测:从开源引擎到企业平台,AlphaFlow、Camunda、Flowable、IBM、Microsoft 怎么选?
microsoft·开源
Flying pigs~~2 天前
检索增强生成RAG项目tools_04:flask➕fastapi➕高并发
数据库·python·flask·大模型·fastapi·异步