在 Azure Database for PostgreSQL - 单一服务器中进行备份和还原Backup and restore in Azure Database for PostgreSQL - Single Server

Azure Database for PostgreSQL 可自动创建服务器备份并将其存储在用户配置的本地冗余或异地冗余存储中。Azure Database for PostgreSQL automatically creates server backups and stores them in user configured locally redundant or geo-redundant storage. 备份可以用来将服务器还原到某个时间点。Backups can be used to restore your server to a point-in-time. 备份和还原是任何业务连续性策略的基本组成部分,因为它们可以保护数据免遭意外损坏或删除。Backup and restore are an essential part of any business continuity strategy because they protect your data from accidental corruption or deletion.

备份Backups

Azure Database for PostgreSQL 对数据文件和事务日志进行备份。Azure Database for PostgreSQL takes backups of the data files and the transaction log. 根据支持的最大存储大小,我们会进行完整备份和差异备份(最大 4 TB 的存储服务器)或快照备份(最大 16 TB 的存储服务器)。Depending on the supported maximum storage size, we either take full and differential backups (4-TB max storage servers) or snapshot backups (up to 16-TB max storage servers). 可以通过这些备份将服务器还原到所配置的备份保留期中的任意时间点。These backups allow you to restore a server to any point-in-time within your configured backup retention period. 默认的备份保留期为七天。The default backup retention period is seven days. 可以选择将其配置为长达 35 天。You can optionally configure it up to 35 days. 所有备份都使用 AES 256 位加密进行加密。All backups are encrypted using AES 256-bit encryption.

无法导出这些备份文件。These backup files cannot be exported. 这些备份只能用于 Azure Database for PostgreSQL 中的还原操作。The backups can only be used for restore operations in Azure Database for PostgreSQL. 可以使用 pg_dump 复制数据库。You can use pg_dump to copy a database.

备份频率Backup frequency

存储容量最大 4 TB 的服务器Servers with up to 4-TB storage

对于支持最多 4 TB 存储容量的服务器,每周进行一次完整备份。For servers which support up to 4-TB maximum storage, full backups occur once every week. 差异备份一天进行两次。Differential backups occur twice a day. 事务日志备份每五分钟进行一次。Transaction log backups occur every five minutes.

存储容量最大 16 TB 的服务器Servers with up to 16-TB storage

Azure 区域的子集中,所有新预配的服务器最多可以支持 16 TB 的存储容量。In a subset of Azure regions, all newly provisioned servers can support up to 16-TB storage. 这些大型存储服务器上的备份是基于快照的。Backups on these large storage servers are snapshot-based. 第一次完整快照备份在创建服务器后立即进行计划。The first full snapshot backup is scheduled immediately after a server is created. 第一次完整快照备份将作为服务器的基准备份保留。That first full snapshot backup is retained as the server's base backup. 后续快照备份仅为差异备份。Subsequent snapshot backups are differential backups only. 差异快照备份不按固定计划进行。Differential snapshot backups do not occur on a fixed schedule. 在一天之内,将执行三次差异快照备份。In a day, three differential snapshot backups are performed. 事务日志备份每五分钟进行一次。Transaction log backups occur every five minutes.

备份保留Backup retention

根据服务器上的备份保持期设置来保留备份。Backups are retained based on the backup retention period setting on the server. 可以选择 7 到 35 天的保留期。You can select a retention period of 7 to 35 days. 默认保持期为 7 天。The default retention period is 7 days. 可以在服务器创建期间或以后通过使用 Azure 门户Azure CLI 更新备份配置来设置保留期。You can set the retention period during server creation or later by updating the backup configuration using Azure portal or Azure CLI.

备份保留期控制可以往回检索多长时间的时间点还原,因为它基于可用备份。The backup retention period governs how far back in time a point-in-time restore can be retrieved, since it's based on backups available. 从恢复的角度来看,备份保留期也可以视为恢复时段。The backup retention period can also be treated as a recovery window from a restore perspective. 在备份保留期间内执行时间点还原所需的所有备份都保留在备份存储中。All backups required to perform a point-in-time restore within the backup retention period are retained in backup storage. 例如,如果备份保留期设置为 7 天,则认为恢复时段是最近 7 天。For example - if the backup retention period is set to 7 days, the recovery window is considered last 7 days. 在这种情况下,将保留在过去 7 天内还原服务器所需的所有备份。In this scenario, all the backups required to restore the server in last 7 days are retained. 备份保留期为 7 天:With a backup retention window of seven days:

  • 存储容量最大达 4 TB 的服务器将保留最多 2 个完整数据库备份、所有差异备份和自最早的完整数据库备份以来执行的事务日志备份。Servers with up to 4-TB storage will retain up to 2 full database backups, all the differential backups, and transaction log backups performed since the earliest full database backup.
  • 存储容量最大达 16 TB 的服务器将保留完整数据库快照、所有差异快照和过去 8 天的事务日志备份。Servers with up to 16-TB storage will retain the full database snapshot, all the differential snapshots and transaction log backups in last 8 days.

备份冗余选项Backup redundancy options

使用 Azure Database for PostgreSQL 时,可以灵活地在“常规用途”层和“内存优化”层中选择本地冗余或异地冗余备份存储。Azure Database for PostgreSQL provides the flexibility to choose between locally redundant or geo-redundant backup storage in the General Purpose and Memory Optimized tiers. 当备份存储在异地冗余备份存储中时,这些备份不仅会存储在托管服务器所在的区域中,还会复制到配对的数据中心When the backups are stored in geo-redundant backup storage, they are not only stored within the region in which your server is hosted, but are also replicated to a paired data center. 这样可以在发生灾难时提供更好的保护,并且可以将服务器还原到其他区域。This provides better protection and ability to restore your server in a different region in the event of a disaster. “基本”层仅提供本地冗余备份存储。The Basic tier only offers locally redundant backup storage.

重要

只能在服务器创建期间为备份配置本地冗余或异地冗余存储。Configuring locally redundant or geo-redundant storage for backup is only allowed during server create. 预配服务器以后,不能更改备份存储冗余选项。Once the server is provisioned, you cannot change the backup storage redundancy option.

备份存储成本Backup storage cost

Azure Database for PostgreSQL 最高可以提供 100% 的已预配服务器存储作为备份存储,不收取任何额外费用。Azure Database for PostgreSQL provides up to 100% of your provisioned server storage as backup storage at no additional cost. 超出的备份存储使用量按每月每 GB 标准收费。Any additional backup storage used is charged in GB per month. 例如,如果为服务器配置了 250 GB 的存储空间,则可以为服务器备份提供 250 GB 的额外存储空间,而不另外收费。For example, if you have provisioned a server with 250 GB of storage, you have 250 GB of additional storage available for server backups at no additional charge. 备份所消耗的存储量超过 250GB 将按照定价模型收费。Storage consumed for backups more than 250 GB is charged as per the pricing model.

可以使用 Azure 门户中提供的 Azure Monitor 中的已使用的备份存储指标来监视服务器使用的备份存储。You can use the Backup Storage used metric in Azure Monitor available in the Azure portal to monitor the backup storage consumed by a server. “已使用的备份存储”指标表示基于为服务器设置的备份保留期所保留的所有完整数据库备份、差异备份和日志备份所消耗的存储的总和。The Backup Storage used metric represents the sum of storage consumed by all the full database backups, differential backups, and log backups retained based on the backup retention period set for the server. 备份的频率由服务进行管控,已在前面进行了说明。The frequency of the backups is service managed and explained earlier. 无论数据库的总大小如何,如果服务器上的事务性活动繁重,都会导致备份存储使用率增加。Heavy transactional activity on the server can cause backup storage usage to increase irrespective of the total database size. 对于异地冗余存储,备份存储使用率是本地冗余存储的两倍。For geo-redundant storage, backup storage usage is twice that of the locally redundant storage.

控制备份存储成本的主要方法是设置适当的备份保留期,并选择正确的备份冗余选项以满足恢复目标。The primary means of controlling the backup storage cost is by setting the appropriate backup retention period and choosing the right backup redundancy options to meet your desired recovery goals. 可以选择 7 到 35 天的保留期。You can select a retention period from a range of 7 to 35 days. 常规用途和内存优化服务器可以选择使用异地冗余存储进行备份。General Purpose and Memory Optimized servers can choose to have geo-redundant storage for backups.

还原Restore

在 Azure Database for PostgreSQL 中进行还原时,会根据原始服务器的备份创建新的服务器。In Azure Database for PostgreSQL, performing a restore creates a new server from the original server's backups.

可以使用两种类型的还原:There are two types of restore available:

  • 时间点还原 :可以与任一备份冗余选项配合使用,所创建的新服务器与原始服务器位于同一区域。Point-in-time restore is available with either backup redundancy option and creates a new server in the same region as your original server.
  • 异地还原 :只能在已将服务器配置为进行异地冗余存储的情况下使用,用于将服务器还原到另一区域。Geo-restore is available only if you configured your server for geo-redundant storage and it allows you to restore your server to a different region.

估计的恢复时间取决于若干因素,包括数据库大小、事务日志大小、网络带宽,以及在同一区域同时进行恢复的数据库总数。The estimated time of recovery depends on several factors including the database sizes, the transaction log size, the network bandwidth, and the total number of databases recovering in the same region at the same time. 恢复时间通常少于 12 小时。The recovery time is usually less than 12 hours.

重要

已删除的服务器 无法 还原。Deleted servers cannot be restored. 如果删除服务器,则属于该服务器的所有数据库也会被删除且不可恢复。If you delete the server, all databases that belong to the server are also deleted and cannot be recovered. 为了防止服务器资源在部署后遭意外删除或意外更改,管理员可以利用管理锁To protect server resources, post deployment, from accidental deletion or unexpected changes, administrators can leverage management locks.

时间点还原Point-in-time restore

可以还原到备份保留期中的任意时间点,不管备份冗余选项如何。Independent of your backup redundancy option, you can perform a restore to any point in time within your backup retention period. 新服务器在原始服务器所在的 Azure 区域中创建。A new server is created in the same Azure region as the original server. 它在创建时,使用原始服务器在定价层、计算的代、vCore 数、存储大小、备份保留期和备份冗余选项方面的配置。It is created with the original server's configuration for the pricing tier, compute generation, number of vCores, storage size, backup retention period, and backup redundancy option.

多种情况下可以使用时间点还原。Point-in-time restore is useful in multiple scenarios. 例如,用户意外删除了数据、删除了重要的表或数据库,或者应用程序因为缺陷而意外地使用错误数据覆盖了正确数据。For example, when a user accidentally deletes data, drops an important table or database, or if an application accidentally overwrites good data with bad data due to an application defect.

可能需要等到下一个事务日志备份进行后,才能还原到上一个五分钟内的某个时间点。You may need to wait for the next transaction log backup to be taken before you can restore to a point in time within the last five minutes.

异地还原Geo-restore

如果已将服务器配置为进行异地冗余备份,则可将服务器还原到另一 Azure 区域,只要服务在该区域可用即可。You can restore a server to another Azure region where the service is available if you have configured your server for geo-redundant backups. 支持存储容量最大达 4 TB 的服务器可以还原到异地配对区域,也可以还原到支持存储容量最大达 16 TB 的任何区域。Servers that support up to 4 TB of storage can be restored to the geo-paired region, or to any region that supports up to 16 TB of storage. 对于支持存储容量最大达 16 TB 的服务器,也可以在支持 16 TB 服务器的任何区域中还原异地备份。For servers that support up to 16 TB of storage, geo-backups can be restored in any region that support 16 TB servers as well. 查看 Azure Database for PostgeSQL 定价层,以获取受支持区域的列表。Review Azure Database for PostgeSQL pricing tiers for the list of supported regions.

当服务器因其所在的区域发生事故而不可用时,异地还原是默认的恢复选项。Geo-restore is the default recovery option when your server is unavailable because of an incident in the region where the server is hosted. 如果区域中出现的大规模事件导致数据库应用程序不可用,可以根据异地冗余备份将服务器还原到任何其他区域中的服务器。If a large-scale incident in a region results in unavailability of your database application, you can restore a server from the geo-redundant backups to a server in any other region. 提取备份后,会延迟一段时间才会将其复制到其他区域中。There is a delay between when a backup is taken and when it is replicated to different region. 此延迟可能长达一小时,因此发生灾难时,会有长达 1 小时的数据丢失风险。This delay can be up to an hour, so, if a disaster occurs, there can be up to one hour data loss.

在异地还原过程中,可以更改的服务器配置包括计算的代、vCore、备份保持期和备份冗余选项。During geo-restore, the server configurations that can be changed include compute generation, vCore, backup retention period, and backup redundancy options. 不支持更改定价层(“基本”、“常规用途”或“内存优化”)或存储大小。Changing pricing tier (Basic, General Purpose, or Memory Optimized) or storage size is not supported.

执行还原后任务Perform post-restore tasks

从任一恢复机制还原后,都应执行以下任务,然后用户和应用程序才能重新运行:After a restore from either recovery mechanism, you should perform the following tasks to get your users and applications back up and running:

  • 如果需要使用新服务器来替换原始服务器,则请将客户端和客户端应用程序重定向到新服务器If the new server is meant to replace the original server, redirect clients and client applications to the new server
  • 对于要进行连接的用户,请确保设置适当的服务器级防火墙规则和 VNet 规则。Ensure appropriate server-level firewall and VNet rules are in place for users to connect. 不会从源服务器复制这些规则。These rules are not copied over from the original server.
  • 确保设置适当的登录名和数据库级权限Ensure appropriate logins and database level permissions are in place
  • 视情况配置警报Configure alerts, as appropriate

后续步骤Next steps