Azure Linux VM 的应用程序一致性备份Application-consistent backup of Azure Linux VMs

创建 VM 的备份快照时,应用程序一致性意味着 VM 在还原后启动时启动应用程序。When taking backup snapshots of your VMs, application consistency means your applications start when the VMs boot after being restored. 正如你所想象,应用程序一致性非常重要。As you can imagine, application consistency is extremely important. 若要确保 Linux VM 是应用程序一致的,可以使用 Linux 前脚本和后脚本框架执行应用程序一致性备份。To ensure your Linux VMs are application consistent, you can use the Linux pre-script and post-script framework to take application-consistent backups. 前脚本和后脚本框架支持 Azure 资源管理器部署的 Linux 虚拟机。The pre-script and post-script framework supports Azure Resource Manager-deployed Linux virtual machines. 应用程序一致性脚本不支持 Service Manager 部署的虚拟机或 Windows 虚拟机。Scripts for application consistency do not support Service Manager-deployed virtual machines or Windows virtual machines.

框架工作原理How the framework works

该框架提供一个选项,用于在创建 VM 快照时运行自定义的操作前脚本和操作后脚本。The framework provides an option to run custom pre-scripts and post-scripts while you're taking VM snapshots. 前脚本在创建 VM 快照前的那一刻运行,后脚本在创建 VM 快照后立即运行。Pre-scripts run just before you take the VM snapshot, and post-scripts run immediately after you take the VM snapshot. 使用前脚本和后脚本可在创建 VM 快照时灵活控制应用程序和环境。Pre-scripts and post-scripts provide the flexibility to control your application and environment, while you're taking VM snapshots.

前脚本可以调用本机应用程序 API 来使 IO 处于静默状态并将内存中内容刷新到磁盘。Pre-scripts invoke native application APIs, which quiesce the IOs, and flush in-memory content to the disk. 这些操作可确保快照是应用程序一致的。These actions ensure the snapshot is application consistent. 后脚本使用本机应用程序 API 来解冻 IO,使应用程序能够在创建 VM 快照后恢复正常操作。Post-scripts use native application APIs to thaw the IOs, which enables the application to resume normal operations after the VM snapshot.

配置操作前脚本和操作后脚本的步骤Steps to configure pre-script and post-script

  1. 以 root 用户身份登录到要备份的 Linux VM。Sign in as the root user to the Linux VM that you want to back up.

  2. GitHub 下载 VMSnapshotScriptPluginConfig.json,并将其复制到要备份的所有 VM 的 /etc/azure 文件夹。From GitHub, download VMSnapshotScriptPluginConfig.json and copy it to the /etc/azure folder for all VMs you want to back up. 如果 /etc/azure 文件夹不存在,则创建它。If the /etc/azure folder doesn't exist, create it.

  3. 将应用程序的前脚本和后脚本复制到计划备份的所有 VM 上。Copy the pre-script and post-script for your application on all VMs you plan to back up. 可将脚本复制到 VM 上的任意位置。You can copy the scripts to any location on the VM. 确保在 VMSnapshotScriptPluginConfig.json 文件中更新脚本文件的完整路径。Be sure to update the full path of the script files in the VMSnapshotScriptPluginConfig.json file.

  4. 确保分配对这些文件的以下权限:Ensure the following permissions for these files:

    • VMSnapshotScriptPluginConfig.json:权限“600”。VMSnapshotScriptPluginConfig.json: Permission “600.” 例如,只有“root”用户才对此文件拥有“读取”和“写入”权限,任何用户都不得拥有其“执行”权限。For example, only “root” user should have “read” and “write” permissions to this file, and no user should have “execute” permissions.

    • 操作前脚本文件: 权限“700”。Pre-script file: Permission “700.” 例如,只有“root”用户才对此文件拥有“读取”、“写入”和“执行”权限。For example, only “root” user should have “read”, “write”, and “execute” permissions to this file.

    • 操作后脚本:权限“700”。 Post-script Permission “700.” 例如,只有“root”用户才对此文件拥有“读取”、“写入”和“执行”权限。For example, only “root” user should have “read”, “write”, and “execute” permissions to this file.

    重要

    该框架为用户提供强大功能。The framework gives users a lot of power. 保护该框架,并确保只有“root”用户可以访问关键 JSON 和脚本文件。Secure the framework, and ensure only “root” user has access to critical JSON and script files. 如果不符合要求,该脚本将不会运行,从而导致文件系统崩溃和生成不一致性备份。If the requirements aren't met, the script won't run, which results in a file system crash and inconsistent backup.

  5. 根据下述信息配置 VMSnapshotScriptPluginConfig.json:Configure VMSnapshotScriptPluginConfig.json as described here:

    • pluginName:将此字段保留原样,否则脚本可能无法按预期工作。pluginName: Leave this field as is, or your scripts might not work as expected.

    • preScriptLocation:提供要备份的 VM 上的操作前脚本的完整路径。preScriptLocation: Provide the full path of the pre-script on the VM that's going to be backed up.

    • postScriptLocation:提供要备份的 VM 上的操作后脚本的完整路径。postScriptLocation: Provide the full path of the post-script on the VM that's going to be backed up.

    • preScriptParams:提供需传递给操作前脚本的可选参数。preScriptParams: Provide the optional parameters that need to be passed to the pre-script. 所有参数都应当用引号引起来。All parameters should be in quotes. 如果使用多个参数,请用逗号分隔参数。If you use multiple parameters, separate the parameters with a comma.

    • postScriptParams:提供需传递给操作后脚本的可选参数。postScriptParams: Provide the optional parameters that need to be passed to the post-script. 所有参数都应当用引号引起来。All parameters should be in quotes. 如果使用多个参数,请用逗号分隔参数。If you use multiple parameters, separate the parameters with a comma.

    • preScriptNoOfRetries:设置发生任何错误时,程序终止前应重试操作前脚本的次数。preScriptNoOfRetries: Set the number of times the pre-script should be retried if there is any error before terminating. 0 表示发生失败时只尝试一次且不重试。Zero means only one try and no retry if there is a failure.

    • postScriptNoOfRetries:设置发生任何错误时,程序终止前应重试操作后脚本的次数。postScriptNoOfRetries: Set the number of times the post-script should be retried if there is any error before terminating. 0 表示发生失败时只尝试一次且不重试。Zero means only one try and no retry if there is a failure.

    • timeoutInSeconds:指定操作前脚本和操作后脚本的单次超时(最大值可以为 1800)。timeoutInSeconds: Specify individual timeouts for the pre-script and the post-script (maximum value can be 1800).

    • continueBackupOnFailure:如果希望在操作前脚本或操作后脚本失败时 Azure 备份故障回复到文件系统/崩溃一致性备份,请将此值设置为 true。continueBackupOnFailure: Set this value to true if you want Azure Backup to fall back to a file system consistent/crash consistent backup if pre-script or post-script fails. 如果将此值设置为 false,则脚本失败时,备份也会失败(除非拥有单磁盘 VM,它会故障回复到崩溃一致性备份,不管此项设置如何)。Setting this to false fails the backup in case of script failure (except when you have single-disk VM that falls back to crash-consistent backup regardless of this setting).

    • fsFreezeEnabled:指定为了确保文件系统一致性,在创建 VM 快照时是否应调用 Linux fsfreeze。fsFreezeEnabled: Specify whether Linux fsfreeze should be called while you're taking the VM snapshot to ensure file system consistency. 建议将此设置保留为 true,除非必须禁用 fsfreeze 才能让应用程序正常工作。We recommend keeping this setting set to true unless your application has a dependency on disabling fsfreeze.

    • ScriptsExecutionPollTimeSeconds:设置在每次轮询到脚本执行之间,扩展必须进入睡眠状态的时间。ScriptsExecutionPollTimeSeconds: Set the time the extension has to sleep between each poll to the script execution. 例如,如果值为 2,则扩展会每 2 秒检查一次前/后脚本执行是否完成。For example, if the value is 2, the extension checks whether the pre/post script execution completed every 2 seconds. 它可以采用的最小值和最大值分别为 1 和 5。The minimum and maximum value it can take is 1 and 5 respectively. 该值应严格为一个整数。The value should be strictly an integer.

  6. 现已配置脚本框架。The script framework is now configured. 如果已配置 VM 备份,则下一次备份将调用这些脚本,并触发应用程序一致性备份。If the VM backup is already configured, the next backup invokes the scripts and triggers application-consistent backup. 如果未配置 VM 备份,请使用将 Azure 虚拟机备份到恢复服务保管库进行配置。If the VM backup is not configured, configure it by using Back up Azure virtual machines to Recovery Services vaults.

故障排除Troubleshooting

编写操作前脚本和操作后脚本时,请确保添加相应的日志记录,并查看脚本日志来解决任何脚本问题。Make sure you add appropriate logging while writing your pre-script and post-script, and review your script logs to fix any script issues. 如果运行脚本时仍然遇到问题,请参阅下表中的详细信息。If you still have problems running scripts, refer to the following table for more information.

错误Error 错误消息Error message 建议的操作Recommended action
Pre-ScriptExecutionFailedPre-ScriptExecutionFailed 操作前脚本返回错误,因此备份可能不具有应用程序一致性。The pre-script returned an error, so backup might not be application-consistent. 查看脚本的失败日志来解决问题。Look at the failure logs for your script to fix the issue.
Post-ScriptExecutionFailedPost-ScriptExecutionFailed 操作后脚本返回了可能影响应用程序状态的错误。The post-script returned an error that might impact application state. 查看脚本的失败日志来解决问题,并检查应用程序状态。Look at the failure logs for your script to fix the issue and check the application state.
Pre-ScriptNotFoundPre-ScriptNotFound 在 VMSnapshotScriptPluginConfig.json 配置文件中指定的位置找不到操作前脚本。The pre-script was not found at the location that's specified in the VMSnapshotScriptPluginConfig.json config file. 确保配置文件中指定的路径处存在操作前脚本,以保证应用程序一致性备份。Make sure that pre-script is present at the path that's specified in the config file to ensure application-consistent backup.
Post-ScriptNotFoundPost-ScriptNotFound 在 VMSnapshotScriptPluginConfig.json 配置文件中指定的位置找不到操作后脚本。The post-script wasn't found at the location that's specified in the VMSnapshotScriptPluginConfig.json config file. 确保配置文件中指定的路径处存在操作后脚本,以保证应用程序一致性备份。Make sure that post-script is present at the path that's specified in the config file to ensure application-consistent backup.
IncorrectPluginhostFileIncorrectPluginhostFile VmSnapshotLinux 扩展随附的 Pluginhost 文件已损坏,因此操作前脚本和操作后脚本无法运行,且不会创建应用程序一致性的备份。The Pluginhost file, which comes with the VmSnapshotLinux extension, is corrupted, so pre-script and post-script cannot run and the backup won't be application-consistent. 卸载 VmSnapshotLinux 扩展,下一次备份时会自动重新安装它,这样即可解决问题。Uninstall the VmSnapshotLinux extension, and it will automatically be reinstalled with the next backup to fix the problem.
IncorrectJSONConfigFileIncorrectJSONConfigFile VMSnapshotScriptPluginConfig.json 文件不正确,因此操作前脚本和操作后脚本无法运行,且不会创建应用程序一致的备份。The VMSnapshotScriptPluginConfig.json file is incorrect, so pre-script and post-script cannot run and the backup won't be application-consistent. GitHub 下载副本并重新配置该文件。Download the copy from GitHub and configure it again.
InsufficientPermissionforPre-ScriptInsufficientPermissionforPre-Script 对于正在运行的脚本,“root”用户应是该文件的所有者,并且应对文件设置“700”权限(即只有“所有者”才拥有“读取”、“写入”和“执行”权限)。For running scripts, "root" user should be the owner of the file and the file should have “700” permissions (that is, only "owner" should have “read”, “write”, and “execute” permissions). 确保“root”用户是脚本文件的“所有者”,只有“所有者”才拥有“读取”、“写入”和“执行”权限。Make sure “root” user is the “owner” of the script file and that only "owner" has “read”, “write” and “execute” permissions.
InsufficientPermissionforPost-ScriptInsufficientPermissionforPost-Script 对于正在运行的脚本,root 用户应是该文件的所有者,并且应该对文件设置“700”权限(即,只有“所有者”才拥有“读取”、“写入”和“执行”权限)。For running scripts, root user should be the owner of the file and the file should have “700” permissions (that is, only "owner" should have “read”, “write”, and “execute” permissions). 确保“root”用户是脚本文件的“所有者”,只有“所有者”才拥有“读取”、“写入”和“执行”权限。Make sure “root” user is the “owner” of the script file and that only "owner" has “read”, “write” and “execute” permissions.
Pre-ScriptTimeoutPre-ScriptTimeout 执行应用程序一致性备份时操作前脚本超时。The execution of the application-consistent backup pre-script timed-out. 检查脚本,并在 /etc/azure 中的 VMSnapshotScriptPluginConfig.json 文件中增加超时时间。Check the script and increase the timeout in the VMSnapshotScriptPluginConfig.json file that's located at /etc/azure.
Post-ScriptTimeoutPost-ScriptTimeout 执行应用程序一致性备份时操作后脚本超时。The execution of the application-consistent backup post-script timed out. 检查脚本,并在 /etc/azure 中的 VMSnapshotScriptPluginConfig.json 文件中增加超时时间。Check the script and increase the timeout in the VMSnapshotScriptPluginConfig.json file that's located at /etc/azure.

后续步骤Next steps