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"]))
相关推荐
自在极意功。20 小时前
Web开发中的分层解耦
java·microsoft·web开发·解耦
txzz88881 天前
网络应用netstart命令
网络·windows·计算机网络·microsoft
计算机学姐1 天前
基于Python的在线考试系统【2026最新】
开发语言·vue.js·后端·python·mysql·django·flask
Q_Q5110082851 天前
python+springboot+django/flask基于深度学习的音乐推荐系统
spring boot·python·django·flask·node.js·php
Q_Q5110082851 天前
python+springboot+django/flask基于深度学习的淘宝用户购物可视化与行为预测系统
spring boot·python·django·flask·node.js·php
Q_Q5110082851 天前
python+django/flask+vue基于spark的西南天气数据的分析与应用系统
spring boot·python·spark·django·flask·node.js
Q_Q5110082851 天前
python+springboot+django/flask基于深度学习的旅游推荐系统
spring boot·python·django·flask·node.js·php
闲人编程1 天前
Flask-SQLAlchemy高级用法:关系建模与复杂查询
后端·python·flask·一对多·多对多·一对一·自引用
Q_Q5110082851 天前
python+django/flask+vue基于深度学习的家庭用电量预测模型研究系统
spring boot·python·django·flask·node.js·php
武藤一雄1 天前
[WPF] 万字拆解依赖属性与附加属性
前端·microsoft·c#·.net·wpf