”工欲善其事,必先利其器。“—孔子《论语.录灵公》
首页 > 编程 > 维护开源备份工具:见解等

维护开源备份工具:见解等

发布于2024-07-31
浏览:793

Backup strategies might seem like a solved problem, yet system administrators often struggle with questions about how to backup data properly, where to store it, and how to standardize the backup process across different software environments. In 2011, we developed custom backup scripts that efficiently handled backups for our client's web projects. These scripts served us well for many years, storing backups in both our storage and external repositories as needed. However, as our software ecosystem grew and diversified, our scripts fell short, lacking support for new technologies like Redis and MySQL/PostgreSQL. The scripts also became cumbersome, with no monitoring system other than email alerts.

Our once compact scripts evolved into a complex and unmanageable system. Updating these scripts for different customers became challenging, particularly when they used customized versions. By early last year, we realized we needed a more modern solution.

In this article, we will explain all the difficulties we faced while developing nxs-backup and share our experiences and challenges. You can also test the tool on your project and share your experience, we would be very interested to hear from you. Now, let's get started!

We listed our requirements for a new system:

  • Backup data of the most commonly used software: (Files: discrete and incremental; MySQL; PostgreSQL; MongoDB; Redis);
  • Store backups in popular repositories: (FTP; SSH; SMB; NFS; WebDAV; S3);
  • Receive alerts in case of problems during the backup process;
  • Have a unified configuration file to manage backups centrally;
  • Add support for new software by connecting external modules;
  • Specify extra options for collecting dumps;
  • Be able to restore backups with standard tools;
  • Ease of initial configuration. All these requirements were listed based on our needs about 5 years ago. Unfortunately, not all of them were released.

We looked at open-source solutions that already existed even before creating our first version of nxs-backup. But they all had their flaws. For example, Bacula is overloaded with unnecessary functions for us, initial configuration is — rather a laborious occupation due to a lot of manual work (for example, for writing/searching scripts of database backups), and to recover copies need to use special utilities, etc.

No surprise that we faced the same problem while having an idea of rewriting our tool. The possibility of the fact that in four years something has changed and new tools have appeared online was not that high, but still.

We studied a couple of new tools that were not considered before. But, as discussed earlier, these also did not suit us. Because they did not fully meet our requirements.

We finally came to two important conclusions:

  1. None of the existing solutions was fully suitable for us;
  2. It seems we’ve had enough experience and craziness to write our solution for the first time. And we basically could do that again. So that’s what we did.

Before exploring the new version, let’s take a look at what we had before and why it was not enough for us.

The old version supported such DBs as MySQL, PostgreSQL, Redis, MongoDB, discrete and incremental copying of files, multiple remote storages (S3; SMB; NFS; FTP; SSH; WebDAV) and had such features as backup rotation, logging, e-mail notifications, and external modules.

Now, more on what we were concerned about.

Run a binary file without restarting the source file on any Linux

Over time, the list of systems we work with has grown considerably. Now we serve projects that use other than standard deb and rpm compatible distributions such as Arch, Suse, Alt, etc.

Recent systems had difficulty running nxs-backup because we only collected deb and rpm packages and supported a limited list of system versions. Somewhere we re-plucked the whole package, somewhere just binary, somewhere we just had to run the source code.

Working with the old version was very inconvenient for engineers, due to the need to work with the source. Not to mention that installation and updating in such mode take more time. Instead of setting up 10 servers per hour, you only had to spend an hour on one server.

We’ve known for a long time that it’s much better when you have a binary without system dependencies that you can run on any distribution and not experience problems with different versions of libraries and architectural differences in systems. We wanted this tool to be the same.

Minimize docker image with nxs-backup and support ENV in configuration files

Lately, so many projects are working in a containerized environment. These projects also require backups, and we run nxs-backup in containers. For containerized environments, it’s very important to minimize the image size and be able to work with environment variables.

The old version did not provide an opportunity to work with environment variables. The main problem was that passwords had to be stored directly in the config. Because of this, instead of a set of variables containing only passwords, you have to put the whole config into a variable. Editing large environment variables requires more concentration from engineers and makes troubleshooting a bit more difficult.

Also, when working with the old version, we had to use an already large Debian image, in which we needed to add several libraries and applications for correct backups.

Even using a slim version of the image we got a minimum size of ~250Mb, which is quite a lot for one small utility. In some cases, this affected the starting process of the collection because of how long the image was pulled onto the node. We wanted to get an image that wasn’t larger than 50 MB.

Work with remote storage without fuse

Another problem for container environments is using fuse to mount remote storage.

While you are running backups on the host, this is still acceptable: you have installed the right packages and enabled fuse in the kernel, and now it works.

Things get interesting when you need fuse in a container. Without an upgrade of privileges with direct access to the core of the host system, the problem is not solved, and this is a significant decrease in the security level.

This needs to be coordinated, not all customers agree to weaken security policies. That’s why we had to make a terrible amount of workarounds we don’t even want to recall. Furthermore, the additional layer increases the probability of failure and requires additional monitoring of the state of the mounted resources. It is safer and more stable to work with remote storage using their API directly.

Monitoring status and sending notifications not only to email

Today, teams are less and less using email in their daily work. It is understandable because it’s much faster to discuss the issue in a group chat or on a group call. Telegram, Slack, Mattermost, MS Teams, and other similar products are widely distributed by that.

We also have a bot, which sends various alerts and notifies us about them. And of course, we’d like to see reports of backups crashing in the workspace like Telegram, not email, among hundreds of other emails. By the way, some customers also want to see information about failures in their Slack or other messenger.

In addition, you long want to be able to track the status and see the details of the work in real-time. To do this, you need to change the format of the application, turning it into a demon.

Insufficient performance

Another acute pain was insufficient performance in certain scenarios.

One of the clients has a huge file dump of almost a terabyte and all of it is small files — text, pictures, etc. We’re collecting incremental copies of this stuff, and have the following problem — a yearly copy takes THREE days. Yeah, well, the old version just can’t digest that volume in less than a day.

Given the circumstances, we are, in fact, unable to recover data on a specific date, which we do not like at all.

Initially, we implemented our backup solution in Python due to its simplicity and flexibility. However, as demands grew, the Python-based solution became inadequate. After a thorough discussion, we decided to rewrite the system in Go for several reasons:

  1. Compilation and Dependencies: Go's AOT compiler produces a universal, dependency-free binary, simplifying deployment across different systems;
  2. Performance: Go's inherent multithreading capabilities promised better performance;
  3. Team Expertise: We had more developers experienced in Go than in Python.

Finding a solution

All of the above problems, to a greater or lesser extent, caused quite a palpable pain to the IT department, causing them to spend precious time on certainly important things, but these costs could have been avoided. Moreover, in certain situations certain risks were created for business owners — the probability of being without data for a certain day, although extremely low, but not zero. We refused to accept the state of affairs.

Nxs-backup 3.0

The result of our work was a new version of nxs-backup v 3.0 which recently had an update to v3.8.0
Key features of the new version:

  • Implement the corresponding interfaces of all storage facilities and all types of backups. Jobs and storage are initialized at the start, and not while the work is running;
  • Work with remote storage via API. For this, we use various libraries;
  • Use environment variables in configs, thanks to the go-nxs-appctx mini-application framework that we use in our projects;
  • Send log events via hooks. You can configure different levels and receive only errors or events of the desired level;
  • Specify not only the period of time for backup, but also a specific number of backups;
  • Backups now simply run on your Linux starting with the 2.6 kernel. This made it much easier to work with non-standard systems and faster to build Docker images. The image itself was reduced to 23 MB (with additional MySQL and SQL clients included);
  • Ability to collect, export, and save different metrics in Prometheus-compatible format.
  • Limiting resource consumption for local disk rate and remote storage.

We have tried to keep most of the configurations and application logic, but some changes are present. All of them are related to the optimization and correction of defects in the previous version.

For example, we put the connection parameters to the remote repositories into the basic configuration so that we don’t prescribe them for different types of backups each time.

Below is an example of the basic configuration for backups. It contains general settings such as notification channels, remote storage, logging, and job list. This is the basic main config with mail notification, we strongly recommend using email notifications as the default method. If you need more features you can see the reference in the documentation.

server_name: wp-server
project_name: My Best Project

loglevel: info

notifications:
  mail:
    enabled: true
    smtp_server: smtp.gmail.com
    smtp_port: 465
    smtp_user: [email protected]
    smtp_password: some5Tr0n9P@s5worD
    recipients:
      - [email protected]
      - [email protected]
  webhooks: []
storage_connects: []
jobs: []
include_jobs_configs: [ "conf.d/*.conf" ]

A few words about pitfalls

We expected to face certain challenges. It would be foolish to think otherwise. But two problems caused the strongest butthurt.

Image description

Memory leak or non-optimal algorithm

Even in the previous version of nxs-backup we used our own implementation of file archiving. The logic of this solution was to try to avoid using external tools to create backups, and working with files was the easiest step possible.

In practice, the solution proved to be workable, although not particularly effective on a large number of files, as could be seen from the tests. Back then we wrote it off to Python’s specifics and hoped to see a significant difference when we switched to Go.

When we finally got to the load testing of the new version, we got disappointing results. There were no performance gains and memory consumption was even higher than before. We were looking for a solution. Read a lot of articles and research on this topic, but they all said that the use of «filepath.Walk» and «filepath.WalkDir» is the best option. The performance of these methods only increases with the release of new versions of the language.

In an attempt to optimize memory consumption, we have even made mistakes in creating incremental copies. By the way, broken options were actually more effective. For obvious reasons, we did not use them.

Eventually, it all stuck to the number of files to be processed. We tested 10 million. Garbage Collector does not seem to be able to clear this amount of generated variables.

Eventually, realizing that we could bury too much time here, we decided to abandon our implementation in favor of a time-tested and truly effective solution — GNU tar.

We may come back to the idea of self-implementation later when we come up with a more efficient solution to handle tens of millions of files.

Such a different ftp

Another problem came up when working with ftp. It turned out that different servers behave differently for the same requests.

And it’s a really serious problem when for the same request you get either a normal answer, or an error that doesn’t seem to have anything to do with your request, or you don’t get a bug when you expect it.

So, we had to give up using the library “prasad83/goftp” in favor of a simpler “jlaffaye/ftp”, because the first could not work correctly with the Selectel server. The error was that when connecting, the first one tried to get the list of files in the working directory and got the error of access rights to the higher directory. With “jlaffaye/ftp” such a problem does not exist, because it is simpler and does not send any requests to the server.

The next problem was a disconnect when there were no requests. Not all servers behave this way, but some do. So we had to check before each request whether the connector had fallen off and reconnected.

The cherry on top was the problem of getting files from the server, or to be clear, an attempt to get a file that did not exist. Some servers give an error when trying to access such a file, others return a valid io.Reader interface object that can even be read, only you get an empty cut of bytes.

All of these situations have been discovered empirically and have to be handled on their own side.

Conclusions

Most importantly, we fixed the problems of the old version, the things that affected the work of engineers and created certain risks for business.

We still have unrealized “wants” from the last version, such as:

  • Backup encryption;
  • Restore from backup using nxs-backup tools;
  • Web interface to manage the list of jobs and their settings.

This list is now extended with new ones:

  • Own job scheduler. Use customized settings instead of system crones;
  • New backup types (Clickhouse, Elastic, lvm, etc).

And, of course, we will be happy to know the community’s opinion. What other development opportunities do you see? What options would you add?

You can read the documentation and learn more about nxs-backup on its website, there is also a troubleshooting section on our website if you want to leave any issues.

We already made a poll in our Telegram channel about upcoming features. Follow us to participate in such activities and contribute to the development of the tool!

See you next time!

版本声明 本文转载于:https://dev.to/nixys/maintaining-an-open-source-backup-tool-insights-and-more-1n1e?1如有侵犯,请联系[email protected]删除
最新教程 更多>
  • 深入研究 Reactjs
    深入研究 Reactjs
    模因生成器 Meme Generator 是一个有趣的交互式 Web 应用程序,允许用户使用各种模板创建自定义 Meme。我已经通过教育平台学习软件开发几个月了,这个项目是课程的一部分。 目录 演示 特征 技术堆栈 安装 用法 作者 执照 表达您的支持 ...
    编程 发布于2024-12-21
  • 如何使用 CSS 禁用链接?
    如何使用 CSS 禁用链接?
    CSS禁用链接技巧问题:是否可以使用CSS禁用链接?例如,如果您有一个名为“当前页”的类,您可能希望阻止该类的链接在单击时处于活动状态。解决方案:以下 CSS 代码片段提供了一个简单的解决方案:[aria-current="page"] { pointer-events: n...
    编程 发布于2024-12-21
  • 如何使我的 Python 类 JSON 可序列化?
    如何使我的 Python 类 JSON 可序列化?
    使 Python 类 JSON 可序列化序列化允许将对象转换为适合持久或传输的格式。在 JSON 中序列化自定义类通常会导致 TypeError,因为它们的非 JSON 可序列化性质。实现 toJSON() 方法一种方法是创建一个类的 toJSON() 方法,手动处理其序列化。这需要实现自定义 JS...
    编程 发布于2024-12-21
  • 如何使用 MySQL 查找今天生日的用户?
    如何使用 MySQL 查找今天生日的用户?
    如何使用 MySQL 识别今天生日的用户使用 MySQL 确定今天是否是用户的生日涉及查找生日匹配的所有行今天的日期。这可以通过一个简单的 MySQL 查询来实现,该查询将存储为 UNIX 时间戳的生日与今天的日期进行比较。以下 SQL 查询将获取今天有生日的所有用户: FROM USERS ...
    编程 发布于2024-12-21
  • 如何在 PHP 中正确使用 INSERT INTO 准备语句?
    如何在 PHP 中正确使用 INSERT INTO 准备语句?
    将准备好的语句与 INSERT INTO 合并在遍历 PHP 的迷宫深度:数据对象时,在尝试执行 MySQL 时出现了一个令人困惑的难题使用准备好的语句进行查询,特别是用于 INSERT INTO 操作。考虑以下代码片段:$statement = $link->prepare("IN...
    编程 发布于2024-12-21
  • 为什么 `Class object();` 不创建 C++ 对象?
    为什么 `Class object();` 不创建 C++ 对象?
    理解构造函数调用的缺失在 C 中,构造函数用于初始化类的对象。然而,在提供的代码片段中,构造函数没有被调用,导致意外的行为。问题有问题的行:Class object();实际上并不调用 Class 类的构造函数。相反,它声明一个返回 Class 对象的函数。要正确调用构造函数并创建对象,必须在行后附...
    编程 发布于2024-12-21
  • PHP 中的静态类与实例化类:何时选择什么?
    PHP 中的静态类与实例化类:何时选择什么?
    PHP 中的静态类与实例化类理解静态类和实例化类之间的区别在面向对象编程中至关重要。 PHP 作为一种流行的面向对象语言,提供了这两种选择。本文旨在阐明它们的适当用法。区别和适用性静态类与实例化对象不同,不保存特定数据并且不能复制。它们用作执行特定任务而不维护实例状态的实用函数。另一方面,实例化对象...
    编程 发布于2024-12-21
  • ES6 计算属性如何解决动态对象初始化挑战?
    ES6 计算属性如何解决动态对象初始化挑战?
    在 ES6 的对象初始化中使用动态属性名称在编程中经常会出现使用从外部源派生的属性名称创建对象的挑战。在查询中描述的场景中,我们尝试构造一个 JavaScript 对象,其属性的键在单独的变量 KEYS 中定义。但是,在为对象内的属性赋值时,我们遇到错误由于使用了点运算符 (.)。该运算符是为文字对...
    编程 发布于2024-12-21
  • 大批
    大批
    方法是可以在对象上调用的 fns 数组是对象,因此它们在 JS 中也有方法。 slice(begin):将数组的一部分提取到新数组中,而不改变原始数组。 let arr = ['a','b','c','d','e']; // Usecase: Extract till index p...
    编程 发布于2024-12-21
  • 为什么 Margin Top 不适用于 CSS 中的内联元素?
    为什么 Margin Top 不适用于 CSS 中的内联元素?
    顶部边距和内联元素在 CSS 中,margin 属性用于定义元素边框之外的间距。然而,在内联元素上使用 margin top 时会出现一个常见问题,特别是在 Firefox 中。问题:为什么内联元素的 margin top 似乎被忽略在 Firefox 中?答案:此行为并非 Firefox 独有,而...
    编程 发布于2024-12-21
  • 如何使用XPath通过CSS类高效定位HTML元素?
    如何使用XPath通过CSS类高效定位HTML元素?
    使用 XPath 按 CSS 类查找元素在网页抓取中,通常需要根据 CSS 类来定位 HTML 元素。 XPath 是一个用于导航 XML 和 HTML 文档的强大工具,它提供了一种实现此目的的方法。考虑一个 HTML 页面,其中的 div 元素具有名为“Test”的类。以下 XPath 查询可用于...
    编程 发布于2024-12-21
  • 尽管代码有效,为什么 POST 请求无法捕获 PHP 中的输入?
    尽管代码有效,为什么 POST 请求无法捕获 PHP 中的输入?
    解决 PHP 中的 POST 请求故障在提供的代码片段中:action=''而不是:action="<?php echo $_SERVER['PHP_SELF'];?>";?>"检查 $_POST数组:表单提交后使用 var_dump 检查 $_POST 数...
    编程 发布于2024-12-21
  • 为什么 `array_shift()` 会触发“严格标准:只有变量应该通过引用传递”?
    为什么 `array_shift()` 会触发“严格标准:只有变量应该通过引用传递”?
    错误信息“Strict Standards: Only Variables Should Be Passed by Reference”使用 array_shift() 时,可能会报告严格标准如果传递的参数是函数调用的结果,则会发出警告。这种行为看起来不一致,因为它并不总是触发警告。考虑以下代码:$...
    编程 发布于2024-12-21
  • 如何在 Pandas 中进行聚合?
    如何在 Pandas 中进行聚合?
    Pandas 中的聚合如何使用 Pandas 执行聚合?聚合函数会降低返回对象的维度。一些常见的聚合函数包括mean()、sum()、size()、count()、std()、var()和sem()。df1 = df.groupby(['A', 'B'], as_index=False)['C']....
    编程 发布于2024-12-21
  • 如何在 C++ 中初始化静态 `const std::string` 数据成员?
    如何在 C++ 中初始化静态 `const std::string` 数据成员?
    声明 const std::string 类型的静态数据成员在 C 中,直接在类定义中初始化 const std::string 类型的静态数据成员是不允许。相反,有两个选项可以定义此类数据成员:内联变量(C 17 或更高版本)使用内联变量,它定义并初始化类定义中的静态成员:class A { pr...
    编程 发布于2024-12-21

免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。

Copyright© 2022 湘ICP备2022001581号-3