Walking across my Minecraft backups with Plakar

本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。

Walking across my Minecraft backups with Plakar

Table of Contents Message to github and patreon sponsors: THANK YOU ❤️ If you like reading articles on this website, please ❤️ consider sharing on social networks to help increase visibility: this helps buy time for new articles and projects ! I take short consulting engagements — architecture review, technical due diligence, mail infrastructure — through aljuna.tech. TL;DR: I had an AI write a plakar integration to back up Minecraft servers without stopping them, it pauses world saves over RCON while the backup runs and lets players keep digging.

目录 致 GitHub 和 Patreon 赞助者:谢谢你们 ❤️ 如果您喜欢阅读本网站的文章,请 ❤️ 考虑在社交网络上分享以提高可见度:这有助于为新文章和项目争取时间!我通过 aljuna.tech 提供短期咨询服务,包括架构审查、技术尽职调查和邮件基础设施。 简而言之:我让 AI 编写了一个 Plakar 集成插件,用于在不停止 Minecraft 服务器的情况下进行备份。它会在备份期间通过 RCON 暂停世界存档,同时允许玩家继续游戏。

First, what’s plakar ? For those who haven’t followed, plakar is an open-source backup solution that I started in 2015, free to use, ISC-licensed, written in Go and built on top of kloset, a content-addressed storage engine that deduplicates, compresses and encrypts everything it stores and keeps snapshots immutable. It backs up from a lot of sources, stores on a lot of storages, and restores to a lot of destinations: a filesystem, an S3 bucket, an SFTP server and many more… These sources and destinations are not baked into plakar: they’re connectors, packaged as integrations that anyone can write and install. Don’t forget to star the project on Github and join the Plakar discord.

首先,什么是 Plakar? 对于那些还没关注的人,Plakar 是我于 2015 年启动的一个开源备份解决方案。它免费使用,采用 ISC 许可证,用 Go 语言编写,并构建在 kloset 之上。kloset 是一个内容寻址存储引擎,可以对存储的所有内容进行去重、压缩和加密,并保持快照不可变。它支持从多种来源备份,存储在多种存储介质上,并恢复到多种目的地:文件系统、S3 存储桶、SFTP 服务器等等……这些来源和目的地并非硬编码在 Plakar 中:它们是连接器,以集成插件的形式打包,任何人都可以编写和安装。 别忘了在 GitHub 上为该项目加星,并加入 Plakar 的 Discord。

What’s this article about ? For the last few years, I’ve been claiming that Plakar was designed with a goal to backup anything… but a claim is only a claim if it’s not backed up (pun intended) by facts. We have written 45 connectors so far but pretty much none of them are targeting general consumer products and tools, so… every now and then I’ll pick a random project, have an AI generate a fully-working connector for it, and make it available to the plakar community. I’ll use an AI because this is what most people will do and I really want to show that there’s no excuse not to protect your data, whatever it is, even if you’re not a programmer. I hope this will inspire people to write new connectors and share them with the community. Oh and one more note, this is not company endorsed and not done on my work time, I’m doing this on my spare time and distributing them on my personal Github account, just like any open-source contributor.

这篇文章是关于什么的? 过去几年里,我一直声称 Plakar 的设计目标是备份任何东西……但如果缺乏事实支持,声明终究只是声明。到目前为止,我们已经编写了 45 个连接器,但几乎没有一个是针对普通消费级产品和工具的。所以……我会不时挑选一个随机项目,让 AI 为其生成一个功能完备的连接器,并将其提供给 Plakar 社区。 我使用 AI 是因为这是大多数人会做的事情,我真的想证明,无论数据是什么,即使你不是程序员,也没有理由不去保护它。我希望这能激励人们编写新的连接器并与社区分享。 另外,请注意,这并非公司认可的项目,也不是在工作时间完成的。我是在业余时间做这件事,并像任何开源贡献者一样,将它们发布在我的个人 GitHub 账号上。

First one up: Minecraft. Why Minecraft needs care A Minecraft server looks like the easiest thing in the world to back up: it’s a directory, you copy it, done. Nope. A running server rewrites its region files all the time, and a copy taken while it does is a world made of chunks from different moments… which may or may not load the day you need it, and you’ll only find out then. The usual answers are to stop the server for the backup, which nobody enjoys when there are people playing, or to wrap rsync in a shell script that pokes the console and hopes for the best. While looking for existing solutions people implemented I found a fair share of those scripts and well… it’s very often a leap of faith. plakar already knows how to back up a directory, deduplicate it, encrypt it and push it wherever you want, so the missing piece was small: tell the server to hold still, back up, let it go.

第一个项目:Minecraft。 为什么 Minecraft 需要特别处理 Minecraft 服务器看起来是世界上最容易备份的东西:它只是一个目录,复制一下就完成了。不,事实并非如此。运行中的服务器会不断重写其区域文件,如果在重写过程中进行复制,得到的存档将是由不同时间点的区块组成的……当你需要恢复时,它可能无法加载,而你只有在那时才会发现。 通常的解决方法是停止服务器进行备份(当有人在玩时,没人喜欢这样),或者将 rsync 封装在 shell 脚本中,通过向控制台发送指令来碰运气。在寻找人们实现的现有解决方案时,我发现了很多这样的脚本,嗯……这通常是在赌运气。 Plakar 已经具备了备份目录、去重、加密并将其推送到任何地方的能力,所以缺失的部分很简单:告诉服务器暂停,进行备份,然后恢复运行。

Here’s the prompt that was used Nothing hidden, this is the prompt that produced the integration with Claude Opus 5.5: Implement a fully working minecraft server integration for Plakar, inspiring yourself from other integrations in PlakarKorp/integrations. It needs to provide fully working and consistent backup and restore. It needs to be tested on a real implementation with a roundtrip: back up worlds, restore them to a new instance, ensure they are identical. Write full test coverage validating behavior not code. This is under-specified, of course, but with our straight-forward SDK and other examples, it’s enough to get going.

这是所使用的提示词 毫无保留,这就是生成与 Claude Opus 5.5 集成的提示词: 为 Plakar 实现一个功能完备的 Minecraft 服务器集成,参考 PlakarKorp/integrations 中的其他集成。它需要提供功能完备且一致的备份和恢复功能。它需要在真实的实现中进行往返测试:备份世界,将其恢复到新实例,并确保它们完全相同。编写完整的测试覆盖率,验证行为而非代码。 当然,这描述得不够详尽,但凭借我们直观的 SDK 和其他示例,这已经足够开始了。

How does it work ? Every Minecraft server ships with RCON, a remote console that accepts the same commands an operator would type, so there is no need to be clever. The importer connects to it and wraps the backup with four steps: save-off: autosave stops and the region files stop changing save-all flush: everything loaded in memory is written to disk the directory is backed up like any other save-on: autosave resumes once the last file has been read Players keep playing throughout, whatever they do during the backup stays in memory until autosave resumes and lands on disk as usual. A stopped server doesn’t need any of this and is backed up as is. The importer and exporter are really the fs connectors with the server-side care added on top, which means excludes, permissions, ownership and times behave exactly like a regular filesystem backup. It also means the whole server directory goes in, not just the world: server.properties, whitelist and bans, plugins or mods and their configuration, everything you’d need to bring the server back up elsewhere.

它是如何工作的? 每个 Minecraft 服务器都自带 RCON,这是一个远程控制台,接受操作员输入的相同命令,因此无需耍小聪明。导入器连接到它,并通过四个步骤封装备份过程: save-off:自动保存停止,区域文件停止更改。 save-all flush:内存中加载的所有内容被写入磁盘。 像备份其他目录一样备份该目录。 save-on:一旦读取完最后一个文件,自动保存就会恢复。 玩家在整个过程中可以继续游戏,他们在备份期间所做的任何操作都会保留在内存中,直到自动保存恢复并像往常一样写入磁盘。已停止的服务器不需要这些步骤,直接按原样备份即可。 导入器和导出器实际上就是添加了服务器端处理逻辑的 fs 连接器,这意味着排除项、权限、所有权和时间戳的行为与常规文件系统备份完全相同。这也意味着整个服务器目录都会被备份,而不仅仅是世界文件:server.properties、白名单和封禁列表、插件或模组及其配置,以及你在其他地方恢复服务器所需的一切。

Installing The package is built and available in the devel channel, so installing it is a one-liner: $ plakar pkg add -devel minecraft If you’d rather build it yourself, the code lives on the integration/minecraft branch of poolpOrg/plakar-integrations and make install packages it and installs it in your local plakar: $ git clone -b integration/minecraft https://github.com/poolpOrg/plakar-integrations $ cd plakar-integrations/minecraft $ make install

安装 该软件包已构建并可在 devel 通道中获取,因此安装只需一行命令: $ plakar pkg add -devel minecraft 如果你更愿意自己构建,代码位于 poolpOrg/plakar-integrations 的 integration/minecraft 分支中,make install 会将其打包并安装到你的本地 Plakar 中: $ git clone -b integration/minecraft https://github.com/poolpOrg/plakar-integrations $ cd plakar-integrations/minecraft $ make install

Enabling RCON If RCON isn’t enabled already, it’s three lines in server.properties and a restart of the server: enable-rcon=true rcon.port=25575 rcon.password=choose-one The integration reads these settings from the server directory so there’s nothing to configure on the plakar side. Keep in mind that the console speaks plaintext, so keep the port on localhost or on a private network and not on the internet (please !). Without RCON, a stopped server still backs up fine, but a running one is refused rather than copied inconsistently. I’d rather have a backup fail loudly tonight than have a restore fail silently in three months.

启用 RCON 如果尚未启用 RCON,只需在 server.properties 中添加三行内容并重启服务器即可: enable-rcon=true rcon.port=25575 rcon.password=choose-one 该集成会从服务器目录中读取这些设置,因此 Plakar 端无需进行任何配置。请记住,控制台使用明文通信,因此请将端口保持在 localhost 或私有网络上,不要暴露在互联网上(拜托了!)。 如果没有 RCON,已停止的服务器仍然可以正常备份,但运行中的服务器会被拒绝备份,而不是进行不一致的复制。我宁愿备份在今晚大声报错失败,也不愿在三个月后恢复时悄无声息地失败。

Backing up Assuming a repository was created with plakar at /var/backups/minecraft create, backing up the server is just: $ plakar a

备份 假设已使用 plakar 在 /var/backups/minecraft 创建了存储库,备份服务器只需执行: $ plakar a