备份数据库与备份虚拟机

发布于 2024-12-01 23:30:04 字数 253 浏览 4 评论 0原文

我们正在为在 VM 管理程序上运行的 Django/Postgres 站点提供服务。我们现在正在尝试找出备份策略,并有两个可能的选择:

  1. 使用 pg_dump 直接备份数据库
  2. 通过复制 VM 映像直接备份 VM

我选择后者,因为我我想,我可以简单地备份与该网站有关的所有内容。但我不确定是否必须为此关闭虚拟机。

备份数据库的更好和更推荐的方法是什么?不使用虚拟机备份有什么原因吗?

谢谢

We're serving a Django/Postgres site running on a VM hypervisor. We're now trying to figure out our back up strategy and have two probable options:

  1. Back up the DB directly using pg_dump
  2. Back up the VM directly by copying the VM image

I'm with the latter as I think, I could simply back up everything that has to do with the site. I'm not sure whether I have to shut down the VM for this though.

What is a better and more recommended way of backing up a DB? Are there any reasons for not using the VM backup?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

可是我不能没有你 2024-12-08 23:30:04

这个问题基本上可以归结为,你可以考虑将 PostgreSQL 数据文件的热副本作为备份吗?

答案是:并非如此。 PostgreSQL 非常努力地通过使用 WAL 来确保其文件始终处于一致状态,并且可以在电源故障时幸存下来,但是从这些文件的副本启动它会使 PostgreSQL 进入恢复模式。如果备份发生在错误的时间并且 PostgreSQL 无法从这些文件的状态中恢复,那么您的备份就没用了。你不希望你的备份/恢复机制依赖于恢复机制(除非你正在处理“仅崩溃”软件,而 PostgreSQL 不是)。

PostgreSQL 无法从这些文件中恢复的概率并不高,但也不是零。另一方面,PostgreSQL 无法加载它生成的 SQL 转储的概率为零。我更喜欢失败概率较低的备份选择。 pg_dump 专为备份而设计。

The question basically boils down to, can you consider a hot copy of PostgreSQL's data files a backup?

The answer is: not really. PostgreSQL tries very hard through the use of WAL to ensure that its files are in a consistent state all the time and that it can survive a power failure, but starting it up from a copy of these files puts PostgreSQL into recovery mode. If the backup happened at the wrong second and PostgreSQL can't recover from the state of these files, your backup is useless. You don't want your backup/restore mechanism to depend on the recovery mechanism (unless you're dealing with "crash only" software, which PostgreSQL is not).

The probability of PostgreSQL not being able to recover from these files is not high, but it's not zero either. The probability of PostgreSQL not being able to load an SQL dump that it made, on the other hand, is zero. I prefer backup choices with lower probabilities of failure. pg_dump was designed for doing backups.

西瓜 2024-12-08 23:30:04

PostgreSQL 建议使用 pg_dump 进行备份,因为文件系统(或 VM)备份需要关闭数据库(并且有其他缺点):

http://www.postgresql.org/docs/8.1/static/backup-file.html

编辑:另外, pg_dump 备份将比同一数据库的文件系统转储小得多。

PostgreSQL recommends using pg_dump for backups, as a file system (or VM) backup requires the database to be shut down (and has other drawbacks):

http://www.postgresql.org/docs/8.1/static/backup-file.html

Edit: Also, a pg_dump backup will be significantly smaller than a filesystem dump of the same database.

不气馁 2024-12-08 23:30:04

还有一个附加选项。使用 PostgreSQL,您可以进行在线备份,从而可以对文件系统进行快照并保持一致性。您可以在这里查看详细信息:
http://www.postgresql.org/docs/9.0/static/continuous -archiving.html

当我们在虚拟机中运行 PostgreSQL 时,我们使用这种确切的方法进行备份。

There is an additional option. With PostgreSQL you can make an online backup that allows you to snapshot the file system and maintain consistency. You can see details here:
http://www.postgresql.org/docs/9.0/static/continuous-archiving.html

We use this exact method for making backups when we run PostgreSQL in a VM.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文