Azure 文件的共享快照概述Overview of share snapshots for Azure Files

Azure 文件提供了获取文件共享的共享快照的功能。Azure Files provides the capability to take share snapshots of file shares. 共享快照可以捕获在某个时间点的共享状态。Share snapshots capture the share state at that point in time. 本文介绍共享快照提供的功能,以及如何在自定义用例中加以利用。In this article, we describe what capabilities share snapshots provide and how you can take advantage of them in your custom use case.

何时使用共享快照When to use share snapshots

防止应用程序错误和数据损坏Protection against application error and data corruption

使用文件共享的应用程序执行写入、读取、存储、传输和处理等操作。Applications that use file shares perform operations such as writing, reading, storage, transmission, and processing. 如果应用程序配置不当或引入了意外的 bug,某些块可能会出现意外的覆盖或损坏。If an application is misconfigured or an unintentional bug is introduced, accidental overwrite or damage can happen to a few blocks. 为了帮助防止这种情况,可在部署新应用程序代码之前创建共享快照。To help protect against these scenarios, you can take a share snapshot before you deploy new application code. 如果在新部署中引入了 bug 或应用程序错误,可以恢复到该文件共享中的先前数据版本。If a bug or application error is introduced with the new deployment, you can go back to a previous version of your data on that file share.

防止意外删除或意外更改Protection against accidental deletions or unintended changes

假设我们要处理文件共享中的某个文本文件。Imagine that you're working on a text file in a file share. 关闭该文本文件后,无法撤消所做的更改。After the text file is closed, you lose the ability to undo your changes. 在这些情况下,需要恢复文件的先前版本。In these cases, you then need to recover a previous version of the file. 使用共享快照可在文件被意外重命名或删除时将其恢复到先前的版本。You can use share snapshots to recover previous versions of the file if it's accidentally renamed or deleted.

常规备份目的General backup purposes

创建文件共享后,可以定期创建文件共享的共享快照,以便使用它进行数据备份。After you create a file share, you can periodically create a share snapshot of the file share to use it for data backup. 定期创建共享快照有助于维护之前版本的数据,以备未来审计之需或灾难恢复之用。A share snapshot, when taken periodically, helps maintain previous versions of data that can be used for future audit requirements or disaster recovery.

功能Capabilities

共享快照是数据在一个时间点只读副本。A share snapshot is a point-in-time, read-only copy of your data. 可以使用 REST API 创建、删除和管理快照。You can create, delete, and manage snapshots by using the REST API. 此外,客户端库、Azure CLI 和 Azure 门户中也提供了相同的功能。Same capabilities are also available in the client library, Azure CLI, and Azure portal.

可以使用 REST API 和 SMB 查看共享快照。You can view snapshots of a share by using both the REST API and SMB. 可以检索目录或文件的版本列表,并且可以直接将特定版本作为驱动器装载(仅适用于 Windows - 请参阅限制)。You can retrieve the list of versions of the directory or file, and you can mount a specific version directly as a drive (only available on Windows - see Limits).

在创建共享快照后,可以读取、复制或删除该快照,但无法对其进行修改。After a share snapshot is created, it can be read, copied, or deleted, but not modified. 无法将整个共享快照复制到另一个存储帐户。You can't copy a whole share snapshot to another storage account. 必须使用 AzCopy 或其他复制机制逐个复制文件。You have to do that file by file, by using AzCopy or other copying mechanisms.

共享快照功能是在文件共享级别提供的。Share snapshot capability is provided at the file share level. 检索是在单个文件级别提供的,可用于还原单个文件。Retrieval is provided at individual file level, to allow for restoring individual files. 可以使用 SMB、REST API、门户、客户端库或 PowerShell/CLI 工具还原整个文件共享。You can restore a complete file share by using SMB, the REST API, the portal, the client library, or PowerShell/CLI tooling.

文件共享的共享快照与其基本文件共享相同。A share snapshot of a file share is identical to its base file share. 唯一的差别在于,共享 URI 的后面追加了一个 DateTime 值,用于指示共享快照的创建时间。The only difference is that a DateTime value is appended to the share URI to indicate the time at which the share snapshot was taken. 例如,如果文件共享 URI 为“http://storagesample.core.file.chinacloudapi.cn/myshare”,则共享快照 URI 类似于:For example, if a file share URI is http://storagesample.core.file.chinacloudapi.cn/myshare, the share snapshot URI is similar to:

http://storagesample.core.file.chinacloudapi.cn/myshare?snapshot=2011-03-09T01:42:34.9360000Z

除非显式删除,否则共享快照会一直保留。Share snapshots persist until they are explicitly deleted. 共享快照的生存期不能长于其基本文件共享。A share snapshot cannot outlive its base file share. 可以枚举与基本文件共享相关联的快照,以跟踪当前快照。You can enumerate the snapshots associated with the base file share to track your current snapshots.

创建文件共享的共享快照时,共享系统属性中的文件会被复制到具有相同值的共享快照中。When you create a share snapshot of a file share, the files in the share's system properties are copied to the share snapshot with the same values. 基本文件和文件共享的元数据也会复制到共享快照,除非在创建共享快照时为其指定了不同的元数据。The base files and the file share's metadata are also copied to the share snapshot, unless you specify separate metadata for the share snapshot when you create it.

除非先删除所有共享快照,否则无法删除具有共享快照的共享。You cannot delete a share that has share snapshots unless you delete all the share snapshots first.

空间使用量Space usage

共享快照在本质上是递增的。Share snapshots are incremental in nature. 只会保存最新共享快照之后发生更改的数据。Only the data that has changed after your most recent share snapshot is saved. 这将减少创建共享快照所需的时间,并节省存储成本。This minimizes the time required to create the share snapshot and saves on storage costs. 对象或属性或元数据更新操作的任何写入操作,都将被计入“已更改内容”,并存储在共享快照中。Any write operation to the object or property or metadata update operation is counted toward "changed content" and is stored in the share snapshot.

为了节省空间,可以在改动幅度最大的期间删除共享快照。To conserve space, you can delete the share snapshot for the period when the churn was highest.

尽管共享快照是增量方式进行保存的,但只需保留最新的共享快照即可还原共享。Even though share snapshots are saved incrementally, you need to retain only the most recent share snapshot in order to restore the share. 删除共享快照时,仅删除该共享快照所独有的数据。When you delete a share snapshot, only the data unique to that share snapshot is removed. 活动快照包含浏览和还原数据(从创建共享快照开始)到原始位置或替代位置所需的所有信息。Active snapshots contain all the information that you need to browse and restore your data (from the time the share snapshot was taken) to the original location or an alternate location. 可以在项级还原。You can restore at the item level.

快照不计入 5-TB 共享限制。Snapshots don't count toward your 5-TB share limit. 共享快照占用的总空间没有限制。There is no limit to how much space share snapshots occupy in total. 存储帐户限制仍然适用。Storage account limits still apply.

限制Limits

Azure 文件目前允许的共享快照的上限是 200 个。The maximum number of share snapshots that Azure Files allows today is 200. 在 200 个共享快照之后,必须删除旧的共享快照,以便创建新的共享快照。After 200 share snapshots, you have to delete older share snapshots in order to create new ones.

对创建共享快照的同时调用没有限制。There is no limit to the simultaneous calls for creating share snapshots. 特定文件共享所能占用的共享快照空间没有限制。There is no limit to amount of space that share snapshots of a particular file share can consume.

目前,不能在 Linux 上装载共享快照。Today, it is not possible to mount share snapshots on Linux. 这是因为 Linux SMB 客户端不支持像 Windows 那样装载快照。This is because the Linux SMB client does not support mounting snapshots like Windows does.

数据从共享快照复制回共享Copying data back to a share from share snapshot

涉及文件和共享快照的复制操作遵循以下规则:Copy operations that involve files and share snapshots follow these rules:

可以将文件共享快照中的各个文件复制到其基本共享或任何其他位置。You can copy individual files in a file share snapshot over to its base share or any other location. 通过从共享快照中逐个复制文件,可以还原文件的早期版本或还原完整的文件共享。You can restore an earlier version of a file or restore the complete file share by copying file by file from the share snapshot. 共享快照不会被提升到基本共享。The share snapshot is not promoted to base share.

复制后共享快照保持不变,但基本文件共享将被共享快照中可用的数据副本覆盖。The share snapshot remains intact after copying, but the base file share is overwritten with a copy of the data that was available in the share snapshot. 所有还原后的文件会计入“已更改内容”。All the restored files count toward "changed content."

可将共享快照中的文件复制到具有不同名称的不同目标。You can copy a file in a share snapshot to a different destination with a different name. 生成的目标文件是可写文件,而不是共享快照。The resulting destination file is a writable file and not a share snapshot. 在这种情况下,基本文件共享将保持不变。In this case, your base file share will remain intact.

使用副本覆盖目标文件时,与原始目标文件关联的所有共享快照均将保持不变。When a destination file is overwritten with a copy, any share snapshots associated with the original destination file remain intact.

常规最佳做法General best practices

在 Azure 上运行基础结构时,尽可能自动备份数据恢复。When you're running infrastructure on Azure, automate backups for data recovery whenever possible. 自动化操作比手动流程更可靠,有助于提高数据保护和可恢复性。Automated actions are more reliable than manual processes, helping to improve data protection and recoverability. 可以使用 REST API、客户端 SDK 或脚本来实现自动化。You can use the REST API, the Client SDK, or scripting for automation.

在部署共享快照计划程序之前,仔细考虑共享快照频率和保留设置,以免产生不必要的费用。Before you deploy the share snapshot scheduler, carefully consider your share snapshot frequency and retention settings to avoid incurring unnecessary charges.

共享快照只提供文件级保护。Share snapshots provide only file-level protection. 共享快照无法防止文件共享或存储帐户中的意外删除。Share snapshots don't prevent fat-finger deletions on a file share or storage account. 为了帮助防止存储帐户被意外删除,可以启用软删除,或是锁定存储帐户和/或资源组。To help protect a storage account from accidental deletions, you can either enable soft delete, or lock the storage account and/or the resource group.

后续步骤Next steps