Previously, in my blog post about migrating to Hexo, I mentioned my commitment to open-sourcing stable versions of the tools and services I’ve developed. Today, I’m here to fulfill that promise by introducing the “Database Backup Service Daily.”
This service is designed for automated database backups. It performs daily backups in the early morning and sends the backup files to your email as attachments, ensuring a zero-cost backup solution. It seamlessly integrates with your existing services without any disruption or additional dependencies, as long as it can connect to your database.
As we all know, data backup is an integral part of any service. However, due to time constraints, I hadn’t had the opportunity to properly organize this service. So, I decided to take advantage of the need for data backup in my self-hosted RSS project and, in the process, refine and open-source it.
Initially, I designed this service with Docker in mind, as my previous Typecho-based blog was built on a Docker architecture (as described in “Migrating to Docker”). While the service can work with non-Docker databases, Docker is the trend, and those who self-host services typically have the technical prowess to handle migrations effortlessly.
The service is implemented in PHP. Since I didn’t start with Docker, I chose PHP to leverage the existing environment. From a community and stability perspective, I opted for Laravel as the framework.
However, when I transitioned the entire service to Docker, I encountered some issues. The service was originally built using Laravel 5, and some components didn’t support PHP 7.4. As someone who likes to stay up-to-date, I made some modifications to make it compatible with PHP 7.4. While this saved me at the time, it significantly increased the cost of open-sourcing it later. Fortunately, it ran smoothly, and I’ve been using it for several years now since migrating to Hexo. It has proven to be highly reliable. Surprisingly, I found QQ Mail to be a better choice than Gmail for my email notifications: it offers automatic storage expansion, built-in WeChat notifications, and allows for custom archiving rules. It’s hassle-free! 👍
The most significant challenge I faced when open-sourcing this service was version upgrades. It consumed most of my time and effort. Specifically, the Backup Manager and Backup Manager Laravel components presented a significant hurdle 😞.
These components lacked support for PHP 8, and they weren’t addressing community pull requests. So, while I had managed to patch it to work with PHP 7.4, upgrading to PHP 8 would jeopardize the service’s stability.
Additionally, Laravel had progressed to version 8, while my original version was built on Laravel 5. Upgrading to versions 6 and 7 involved numerous changes.
Therefore, the service I’m open-sourcing now is a completely rewritten version. It supports PHP 8 (with JIT), Laravel 8, and the components used have been forked and modified by me 🤯 to ensure the highest quality of open source.
To ensure the quality of this open-source project, I’ve tested it with both PostgreSQL and MySQL, including the latest PostgreSQL 14 (released on September 30, 2021). Since the community response is not always immediate, and Alpine components haven’t been updated yet (the latest version is still in RC), I’ve limited the stable version for this example to
The PostgreSQL ecosystem is very strict about version compatibility. If versions don’t match, you can’t use them:
pg_dump: error: server version: 14.0; pg_dump version: 13.4 pg_dump: error: aborting because of server version mismatch
And downgrading or upgrading versions is not as straightforward as one might hope:
The data directory was initialized by PostgreSQL version 14, which is not compatible with this version 13.4
Of course, every open-source venture comes with its rewards: staying updated on the community’s latest developments, summarizing past experiences, and alleviating procrastination anxiety… 👻