华为云NFS使用API删除大文件目录

最近在使用华为云SFS时,如果一个目录存储文件数超过100W,执行 "rm -rf path"时,存在删不动的情况,可以使用华为云API接口,执行异步删除。

华为官网:

删除文件系统目录_弹性文件服务 SFS_API参考_SFS Turbo API说明_目录管理_华为云删除文件系统目录在2023年6月1号之后创建的文件系统支持该API操作。 警告:该API为删除文件系统子目录数据的高危操作,删除后无法恢复,使用前请确认下发的文件系统目录是否正确。您可以在API Explorer中调试该接口,支持自动认证鉴权。API Explorer可以自动生成SDK代码示例,并提供SDK代码示例调试功能。DELETE https://support.huaweicloud.com/api-sfs/DeleteFsDir.html

实现代码:

java 复制代码
import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.sfsturbo.v1.region.SFSTurboRegion;
import com.huaweicloud.sdk.sfsturbo.v1.*;
import com.huaweicloud.sdk.sfsturbo.v1.model.*;


/**
 * TODO 删除NFS文件系统目录,高危险操作,务必谨慎执行!!!
 * TODO 删除NFS文件系统目录,高危险操作,务必谨慎执行!!!
 * TODO 删除NFS文件系统目录,高危险操作,务必谨慎执行!!!
 *
 *
 * @author XHH
 */
public class DeleteFsDirSolution {

    public static void main(String[] args) {

        String ak = "<Your AK>";
        String sk = "<Your SK>";

        String pathStr = "<Your Path>";
        String shareId = "<文件系统ID>";

        // 删除
        delFsDir(ak, sk, shareId, pathStr);
    }
    private static void delFsDir(String ak, String sk, String shareId, String pathStr) {

        ICredential auth = new BasicCredentials().withAk(ak).withSk(sk);
        SFSTurboClient client = SFSTurboClient.newBuilder()
                .withCredential(auth)
                .withRegion(SFSTurboRegion.valueOf("cn-southwest-2"))
                .build();
        DeleteFsDirRequest request = new DeleteFsDirRequest();
        request.withShareId(shareId);
        DeleteFsDirRequestBody body = new DeleteFsDirRequestBody();
        body.withPath(pathStr);
        request.withBody(body);

        System.out.println("删除路径: " +pathStr);
        try {
            DeleteFsDirResponse response = client.deleteFsDir(request);
            System.out.println("response ===> " + response.toString());
        } catch (ConnectionException | RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println("删除路径: " +pathStr+ " --> HttpStatusCode:" + e.getHttpStatusCode() + " --> RequestId:" + e.getRequestId() + " --> ErrorMsg:" + e.getErrorMsg());
        }

    }


}
相关推荐
2301_7703737319 分钟前
Java集合
java·开发语言
哈喽姥爷27 分钟前
Spring Boot---自动配置原理和自定义Starter
java·spring boot·后端·自定义starter·自动配置原理
2301_780789661 小时前
渗透测试真的能发现系统漏洞吗
服务器·网络·安全·web安全·网络安全
sunshine-sm2 小时前
CentOS Steam 9安装 Redis
linux·运维·服务器·redis·centos
老华带你飞2 小时前
考研论坛平台|考研论坛小程序系统|基于java和微信小程序的考研论坛平台小程序设计与实现(源码+数据库+文档)
java·vue.js·spring boot·考研·小程序·毕设·考研论坛平台小程序
CHEN5_022 小时前
leetcode-hot100 11.盛水最多容器
java·算法·leetcode
songx_992 小时前
leetcode18(无重复字符的最长子串)
java·算法·leetcode
sunshine-sm3 小时前
CentOS Steam 9安装 MySQL 8
linux·运维·服务器·数据库·mysql·centos·centos stream
在路上`3 小时前
前端学习之后端java小白(三)-sql外键约束一对多
java·前端·学习
dazhong20123 小时前
Spring Boot 项目新增 Module 完整指南
java·spring boot·后端