database CouchDB 备份和克隆数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/121599/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 06:58:15  来源:igfitidea点击:

CouchDB backups and cloning the database

databasecouchdbbackupadministration

提问by Kyle Burton

We're looking at CouchdDB for a CMS-ish application. What are some common patterns, best practices and workflow advice surrounding backing up our production database?

我们正在寻找 CouchdDB 的 CMS-ish 应用程序。围绕备份我们的生产数据库有哪些常见模式、最佳实践和工作流程建议?

I'm particularly interested in the process of cloning the database for use in development and testing.

我对克隆数据库以用于开发和测试的过程特别感兴趣。

Is it sufficient to just copy the files on disk out from under a live running instance? Can you clone database data between two live running instances?

仅从实时运行的实例下复制磁盘上的文件就足够了吗?您可以在两个实时运行的实例之间克隆数据库数据吗?

Advice and description of the techniques you use will be greatly appreciated.

对您使用的技术的建议和描述将不胜感激。

采纳答案by Marc Gear

CouchDB supports replication, so just replicate to another instance of CouchDB and backup from there, avoiding disturbing where you write changes to.

CouchDB 支持复制,因此只需复制到 CouchDB 的另一个实例并从那里备份,避免打扰您将更改写入的位置。

http://wiki.apache.org/couchdb/FrequentlyAskedQuestions#how_replication

http://wiki.apache.org/couchdb/FrequentlyAskedQuestions#how_replication

You literally send a POST request to your CouchDB instance telling it where to replicate to, and it Works(tm)

你真的向你的 CouchDB 实例发送一个 POST 请求,告诉它复制到哪里,它可以工作(tm)

EDIT: You can just cp out the files from under the running database as long as you can accept the I/O hit.

编辑:只要您可以接受 I/O 命中,您就可以从正在运行的数据库下提取文件。

回答by Paul J. Davis

Another thing to be aware of is that you can copy files out from under a live database. Given that you may have a possibly large database, you could just copy it OOB from your test/production machine to another machine.

要注意的另一件事是您可以从实时数据库下复制文件。鉴于您可能有一个可能很大的数据库,您可以将它从测试/生产机器复制到另一台机器。

Depending on the write load of the machines it may be advisable to trigger a replication after the copy to gather any writes that were in progress when the file was copied. But replication of a few records would still be quicker than replication the entire database.

根据机器的写入负载,可能建议在复制后触发复制以收集复制文件时正在进行的任何写入。但是复制一些记录仍然比复制整个数据库要快。

For reference see: http://wiki.apache.org/couchdb/FilesystemBackups

参考:http: //wiki.apache.org/couchdb/FilesystemBackups

回答by Jan Lehnardt

I'd like to second Paul's suggestion: Just cpyour database files from under the live server if you can take the I/O-load hit. If you run a replicated copy anyway, you can safely copy from that too, without impacting your master's performance.

我想支持 Paul 的建议:cp如果您可以承受 I/O 负载的影响,只需从实时服务器下获取您的数据库文件。如果您无论如何都运行复制副本,您也可以安全地从中复制,而不会影响主服务器的性能。

回答by max

CouchDB also works very nicely with filesystem snapshots offered by modern filesystems like ZFS. Since the database file always is in a consistent state you can take the snapshot of the file any time without weakening the integrity guarantees provided by CouchDB.

CouchDB 还可以很好地与现代文件系统(如ZFS)提供的文件系统快照配合使用。由于数据库文件始终处于一致状态,因此您可以随时拍摄文件快照,而不会削弱 CouchDB 提供的完整性保证。

This results in nearly no I/O overhead. In case you have e.g. accidentally deleted a document from the database you can move the snapshot to another machine and extract the missing data there. You might even be able to replicate back to the production database, but I never have tried that.

这导致几乎没有 I/O 开销。如果您不小心从数据库中删除了一个文档,您可以将快照移动到另一台机器并在那里提取丢失的数据。您甚至可以复制回生产数据库,但我从未尝试过。

But always make sure you use exactly the same couchdb revisions when moving around database files. The on-disk format is still evolving in incompatible ways.

但在移动数据库文件时,请始终确保使用完全相同的 couchdb 修订版。磁盘格式仍在以不兼容的方式发展。

回答by coffeequant

CouchDB replication is horrible. I generally do tarwhich is much better.

CouchDB 复制太可怕了。我通常做tar,这要好得多。

  1. Stop the CouchDB service on the source host
  2. tar.gz the data files.
  3. On my Ubuntu servers this is typically in /var/lib/couchdb (sometimes in a subdirectory based on the Couch version). If you aren't sure where these files are, you can find the path in your CouchDb config files, or often by doing a ps -A w to see the full command that started CouchDb. Make sure you get the subdirectories that start with .when you archive the files.
  4. Restart the couchdb service on the source host.
  5. scpthe tar.gz file to the destination host and unpack them in a temporary location there.
  6. chownthe files to the user and group that owns the files already in the database directory on the destination. This is likely couchdb:couchdb. This is important, as messing up the file permissions is the only way I've managed to mess up this process so far.
  7. Stop CouchDB on the destination host.
  8. cpthe files into the destination directory. Again on my hosts this has been /var/lib/couchdb.
  9. Double check the file permissions in their new home.
  10. Restart CouchDB on the destination host.
  1. 停止源主机上的 CouchDB 服务
  2. tar.gz 数据文件。
  3. 在我的 Ubuntu 服务器上,这通常在 /var/lib/couchdb 中(有时在基于 Couch 版本的子目录中)。如果您不确定这些文件在哪里,您可以在 CouchDb 配置文件中找到路径,或者通常通过执行 ps -A w 来查看启动 CouchDb 的完整命令。确保.在存档文件时获得以开头的子目录。
  4. 重新启动源主机上的 couchdb 服务。
  5. scptar.gz 文件到目标主机并将它们解压缩到那里的临时位置。
  6. chown文件给拥有目标数据库目录中已有文件的用户和组。这可能是 couchdb:couchdb。这很重要,因为弄乱文件权限是迄今为止我设法弄乱这个过程的唯一方法。
  7. 在目标主机上停止 CouchDB。
  8. cp文件到目标目录。再次在我的主机上,这是 /var/lib/couchdb。
  9. 仔细检查他们新家中的文件权限。
  10. 在目标主机上重新启动 CouchDB。