將安裝庫從一個集群複製到另一個地方

圖書館集群從源複製到目標集群與一個定製的Python腳本。

寫的manoj.hegde

去年發表在:2023年1月6日

如果你有一個高度定製的磚集群,您可能想要複製它,使用它為其他項目。當你克隆一個集群,隻有Apache火花複製配置和其他集群配置信息。默認安裝庫不是副本。

複製安裝庫,您可以運行一個Python腳本後克隆集群。

指令

識別源和目標

源集群是集群你想複製。

你想要的目標集群是集群複製。

你可以找到的< source-cluster-id >< target-cluster-id >通過選擇工作區中的集群,然後尋找集群ID在URL中。

https:// < databricks-instance > / # /設置/集群/ < cluster-id >

在下麵的截圖,集群ID0801 - 112947 n650q4k

創建一個磚個人訪問令牌

遵循個人用戶訪問令牌(AWS|Azure|GCP)的文檔創建一個個人訪問令牌。

創建一個秘密範圍

遵循創建一個Databricks-backed秘密範圍(AWS|Azure|GCP)文檔創建秘密範圍。

你的個人訪問令牌和磚實例存儲在保密範圍

遵循創建一個秘密Databricks-backed範圍(AWS|Azure|GCP)文檔存儲個人訪問令牌和磚實例創建新的秘密範圍內你的秘密。

磚實例是工作空間的主機名,例如,xxxxx.cloud.www.eheci.com。

使用Python腳本克隆安裝的庫

您可以使用這個例子Python腳本安裝庫集群從源複製到目標集群。

你需要運行腳本之前替換以下值:

  • < scope-name >——你的名字包含秘密範圍。
  • < secret-name-1 >——秘密的名字會握著你的磚實例。
  • < secret-name-2 >——秘密的名稱保存你的個人訪問令牌。
  • < source-cluster-id >——集群的集群ID你想複製。
  • < target-cluster-id >——集群的集群ID你想複製。

示例腳本複製到一個筆記本,附加到運行集群在工作區中。

% python導入請求從pyspark.sql進口json導入時間。導入類型(StructField, StringType StructType, IntegerType) API_URL = dbutils.secrets。get(範圍= " < scope-name >”,關鍵= < secret-name1 >) #https://xxxxx.cloud.www.eheci.com/令牌= dbutils.secrets。get(範圍= " < scope-name >”,關鍵= < secret-name2 >) #磚拍牌source_cluster_id = < source-cluster-id >“target_cluster_id = source_cluster_api_url = API_URL +“< target-cluster-id > / api / 2.0 /圖書館/集群狀態?cluster_id = " + = < source-cluster-id >響應請求。get (source_cluster_api_url header ={“授權”:“持票人”+ <標記>})庫=[]的library_info response.json () [' library_statuses ']: lib_type = library_info[‘圖書館’]狀態= library_info(的地位)libraries.append (lib_type)打印(“從源代碼庫集群(“+ source_cluster_id +”):“+ str(庫)+“\ n”) target_cluster_api_url = API_URL + / api / 2.0 /圖書館/安裝“target_lib_install_payload = json。轉儲({cluster_id: target_cluster_id,“庫”:庫})打印(“安裝在集群目標庫(“+ source_cluster_id +”)與有效載荷:”+ str (target_lib_install_payload) + " \ n ") =響應請求。帖子(target_cluster_api_url header ={“授權”:“持票人”+牌},data = target_lib_install_payload)如果反應。status_code = = 200:打印(“安裝請求成功。響應代碼:“+ str (response.status_code))else: print("Installation failed.Response code :"+str(response.status_code))

測試目標集群

腳本運行完成後,啟動目標集群,並驗證庫複製了。


這篇文章有用嗎?