列出具有 node.js 的 azure 文件共享快照

List azure file shares snapshots with node.js

有什么方法可以在 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拥有的快照?

因此,没有特殊的方法来列出文件共享的快照。您需要致电 listShares method of ShareServiceClient (@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);
})