【问题标题】:List azure file shares snapshots with node.js使用 node.js 列出 azure 文件共享快照
【发布时间】:2021-03-30 17:12:50
【问题描述】:

有没有办法在 node.js 中列出文件共享的快照列表?

示例代码:

const { ShareServiceClient, StorageSharedKeyCredential } = require("@azure/storage-file-share");
const credential = new StorageSharedKeyCredential(AZURE_STORAGE_ACCOUNT,AZURE_STORAGE_ACCESS_KEY);
const shareServiceClient = new ShareServiceClient(AZURE_STORAGE_CONNECTION_STRING,credential);
var shareName = "xxxxx";
var shareClient = shareServiceClient.getShareClient(shareName);

// Create a snapshot:
await shareClient.createSnapshot();

如何列出这个shareName拥有的快照?

【问题讨论】:

    标签: node.js azure snapshot storage-file-share


    【解决方案1】:

    因此,没有特殊的方法可以列出文件共享的快照。您需要调用ShareServiceClientlistShares 方法 (@azure/storage-file-share version 12.5.0),includeSnapshots 参数为 trueprefix 为共享名称。

    这是执行此操作的示例代码(未经测试的代码):

    const shareName = 'share-name';
    const listingOptions = {
        prefix: shareName,
        includeSnapshots: true
    };
    shareServiceClient.listShares(listingOptions).byPage().next()
    .then((result) => {
        const shareItems = result.value.shareItems;
        //Filter results where name of the share is same as share name and is a snapshot
        const shareSnapshots = shareItems.filter(s => s.name === shareName && s.snapshot && s.snapshot !== '');
        console.log(shareSnapshots);
    })
    .catch((error) => {
        console.log(error);
    })
    

    【讨论】:

    • 没错。这种方式有效。这里有一个代码: var shareName = "xxx"; const listingOptions = {前缀:shareName,includeSnapshots:true}; shareIter = shareServiceClient.listShares(listingOptions); shareItem = 等待 shareIter.next(); while (!shareItem.done) { console.log(Share ${i++}: ${shareItem.value.name} ${shareItem.value.snapshot}); shareItem = 等待 shareIter.next(); }
    猜你喜欢
    • 2021-07-28
    • 2021-06-20
    • 2019-05-18
    • 2012-08-09
    • 2017-04-02
    • 2016-07-03
    • 1970-01-01
    • 2022-06-30
    • 2011-12-07
    相关资源
    最近更新 更多