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"]))
相关推荐
天庭鸡腿哥4 小时前
大小不足1M,干翻Windows!
microsoft·macos·visual studio·everything
2501_946244786 小时前
Flutter & OpenHarmony OA系统弹窗对话框组件开发指南
javascript·flutter·microsoft
`林中水滴`10 小时前
Linux Shell 命令:nohup、&、>、bg、fg、jobs 总结
linux·服务器·microsoft
38242782711 小时前
JS逆向:DOM交互与window.onload详解
microsoft
shizhenshide11 小时前
物联网(IoT)设备如何应对验证码?探讨无头浏览器与协议级解决方案
java·struts·microsoft·验证码·ezcaptcha
qq_139484288212 小时前
python基于大数据技术的酒店消费数据分析系统
大数据·python·scrapy·django·flask
旧梦吟12 小时前
脚本网页 双子星棋
算法·flask·游戏引擎·css3·html5
Microsoft Word13 小时前
如何使用SpringAI编写自己的Manus
microsoft
小宇的天下1 天前
Calibre eqDRC(方程化 DRC)核心技术解析与实战指南(14-1)
数据库·windows·microsoft
weixin_462446231 天前
基于 Flask + lunar-python 的农历转换 API 实战(公历 ↔ 农历 / 干支 / 生肖 / 节日)
python·flask·节日