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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.