确保 mysqldump 的数据完整性<->同步

发布于 2024-08-02 07:56:01 字数 312 浏览 2 评论 0 原文

我使用 rsync 来备份服务器上的文件,并使用 mysqldump 来备份数据库。我担心的是:

我的数据库上的 mysqldump 大约需要 30 秒。我有一个名为 photos 的表,用于存储有关用户上传的图像的信息,包括文件的路径。我担心在完成 mysqldump 所需的 30 秒内上传或删除照片会发生什么。如果发生这种情况,然后我要恢复 rsync 文件和 mysqldump 数据,那么我可能会查看一个数据库,其中包含指向已删除照片的行,或者包含已成功上传的照片的缺失行。

如何确保 mysqldump 与 rsync 完全匹配?

提前致谢, 布莱恩

I use rsync to back up the files on my server, and mysqldump to back up my database. Here's my concern:

A mysqldump on my database takes about 30 seconds. I have a table called photos that stores info about the images a user has uploaded, including the path to the file. I am worried about what will happen when photos are uploaded or deleted during the 30 seconds it takes to complete the mysqldump. If that happened and I were then to restore the rsync'd files and the mysqldump data, I could then be looking at a database that contains rows pointing to deleted photos, or missing rows for photos that were successfully uploaded.

How can I make sure the mysqldump exactly matches the rsync?

Thanks in advance,
Brian

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

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

发布评论

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

评论(3

姜生凉生 2024-08-09 07:56:01

使用 锁定表阻止您正在备份的表中的任何写入活动。然后在 mysqldump 完成后解锁它们。

Use LOCK TABLES to block any write activity from the tables you're backing up. Then unlock them once your mysqldump is finished.

暖心男生 2024-08-09 07:56:01

我认为答案很简单,只需在完成 mysqldump 后运行 rsync :) 这样,在最坏的情况下,您将有几个不在数据库转储中的新文件,但不会有不一致的数据库条目。

I think the answer is simple, just run rsync AFTER you complete mysqldump :) This way at worst you will have a couple NEW files that are not in the db dump, but you will not have inconsistent db entries.

笨死的猪 2024-08-09 07:56:01

您可以对生成的 mysqldump(在服务器上)和通过 rsync 传输的(本地)进行 MD5,然后比较两个哈希值以确保它们匹配。
另一种选择是在版本控制文件上设置 mysqldump(使用 git 或 svn 或您最喜欢的 vcs)。例如,git 的优点是您可以轻松设置一些提交后挂钩将更改推送到远程服务器,并且上传的只是版本之间的差异,而不是整个转储。这样你就可以考虑缩短备份周期。

You could MD5 the resulting mysqldump (on the server) and the transfered (locally) by rsync, then compare the two hashes to ensure they match.
Another alternative, is to set mysqldump on a version controlled file (with git or svn or your favorite vcs). The advantage with git, for example, is that you could easily setup some post-commit hooks to push the changes to a remote server, and the upload would be just the differences between versions, not the entire dump. This way you could think in decreasing the backup period.

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