冷备份期间网站数据库写入的最佳实践?

发布于 2024-12-21 09:04:30 字数 248 浏览 1 评论 0原文

假设您有一个大型、流行的数据库驱动网站。工地里整天整夜都有人。它们访问读取和写入数据库的页面。

在实施每日数据库备份计划时,涉及到进行冷备份,这意味着在备份过程中暂时关闭数据库或锁定表。这可确保在备份时不会将新数据插入数据库。

有哪些好的方法可以对站点控制器和模型进行编码,以便它们不会因表锁或数据库脱机而失败?您是否需要实现某种数据库写入队列系统或类似的系统?或者只是暂时让整个网站离线?或者只是进行实时备份而不锁定或关闭任何东西?什么是好的方法?

Lets say you have a large, popular database-driven website. There are people on the site all day and all night. They access pages that both read and write to the database.

When implementing a daily database backup plan, it involves doing cold backups, which means that you temporarily shutdown the database or lock tables while the backup is in progress. This ensures that new data is not inserted into the database while the backup is happening.

What are some good approaches to coding your site controllers and models so that they don't fail due to table locks or the database being offline? Do you need to implement some sort of database write queue system or something like that? Or just take the whole site offline temporarily? Or just do live backups without locking or shutting down anything? What is a good approach?

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

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

发布评论

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

评论(1

滥情空心 2024-12-28 09:04:30

使用复制,这是一个简单的场景

1主A,2从B,C

  • 在正常操作期间,您的应用程序应该
  • 在备份期间在A,B和C之间进行负载平衡,您的应用程序不应该读取/从A写
    • 解除 A 的 master 身份,将 B 提升为 master,将 Slave C 更改为监听 B
    • 使用A进行备份
    • 备份完成后
    • 改变A听B的声音(这意味着A从现在开始成为奴隶)
  • 当A追上时, 对于 B,(不再有延迟),将您的应用程序再次更改为 A、B、C 之间的负载平衡

对于第 2 天,只需重复整个周期,当然 master 现在是 B。

Use replication, here is a simple scenario

1 master A, 2 slaves B, C

  • during normal operation, your application should load balance between A,B and C
  • during back-up, your application should NOT read / write from A
    • relieve A from being master, promote B to master, change slave C to listen on B
    • use A for backup
    • after backup done
    • change A to listen from B (that's mean A become slave from now onward)
  • when A is catch up with B, (no more delay), change your application to load balance again between A,B,C

For Day 2, just repeat the whole cycle, of course master is now B.

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