0

有没有办法在 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拥有的快照?

4

1 回答 1

1

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

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

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);
})
于 2021-03-31T00:57:58.217 回答