繁体   English   中英

无法从 Databricks 笔记本的 Azure 存储容器中删除目录

[英]Not able to delete directory from Azure Storage container by Databricks notebook

我正在尝试从安装到我的 DBFS 的 Azure 存储容器中删除空目录

我能够列出所有没有文件的目录。

%sh
find /dbfs/mnt/test/logs/2021 -empty -type d

结果:

/dbfs/mnt/test/logs/2021/02/12
/dbfs/mnt/test/logs/2021/02/15
/dbfs/mnt/test/logs/2021/02/16

但是当我尝试删除它们时,由于资源暂时不可用而失败。

%sh
find /dbfs/mnt/test/logs/ -type d -exec rmdir {} \; 

结果:

rmdir: failed to remove '/dbfs/mnt/test/logs/': Directory not empty
rmdir: failed to remove '/dbfs/mnt/test/logs/2021': Directory not empty
rmdir: failed to remove '/dbfs/mnt/test/logs/2021/02': Directory not empty
rmdir: failed to remove '/dbfs/mnt/test/logs/2021/02/12': Resource temporarily unavailable

我能够成功删除某些天以前的文件。删除目录不起作用。 (以下命令删除正在工作的文件

%sh
find /dbfs/mnt/test/logs/ -name "*.log" -type f -mtime +5 -exec rm -f {} \; 

首先要记住 - DBFS 是对云 blob 存储的抽象,其中没有真正的目录 - 它们只是用于组织数据的前缀。 如果您执行%sh ls -ls /dbfs/mnt/test/logs/您可能会注意到所有目录都将具有相同的时间戳,并且可能是最近的一个 - 我不记得它是如何计算的了。 只有文件有时间戳。

因此,如果您需要可靠地删除目录,最好使用dbutils.fs.rm('/mnt/test/logs/', True) (在 Python 中,或在 Scala 中类似)递归地删除目录(参见docs )。 但是有一些限制,比如不支持通配符等,所以需要生成要删除的目录列表,然后进行删除。

暂无
暂无

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

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