简体   繁体   English

在数据块中创建具有当前日期的版本副本后,将增量表恢复到以前的版本

[英]Restore delta table to previous version after creating a copy of version with current date in databricks

I want to restore previous version of delta table by creating its copy first with copy job run date folder name and then restore delta table using that copy file我想通过首先使用复制作业运行日期文件夹名称创建其副本来恢复以前版本的增量表,然后使用该副本文件恢复增量表

Any suggestion here这里有任何建议

First create folder with backup, adjust added date to whatever else you want:首先创建带有备份的文件夹,将添加的日期调整为您想要的任何其他日期:

import datetime
path = 'dbfs:/mnt/your_dataset_path'
bck_path= path +'_backup_'+datetime.datetime.utcnow().strftime("%Y%m%d%H%M%S")
    
dbutils.fs.cp(path, bck_path)

Then restore using time travel, either using the backup path or the original:然后使用时间旅行恢复,使用备份路径或原始路径:

from delta.tables import *

deltaTable = DeltaTable.forPath(spark, '/mnt/your_dataset_path')  # path-based tables, or
deltaTable = DeltaTable.forName(spark, 'table-name')    # Hive metastore-based tables

deltaTable.restoreToVersion(0) # restore table to oldest version

deltaTable.restoreToTimestamp('2022-09-14') # restore to a specific timestamp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM