Files
backup-docker-to-local/README.md

102 lines
4.5 KiB
Markdown
Raw Normal View History

2025-03-04 22:41:01 +01:00
# Backup Docker Volumes to Local (baudolo) 📦🔄
2025-03-12 20:52:47 +01:00
[![GitHub Sponsors](https://img.shields.io/badge/Sponsor-GitHub%20Sponsors-blue?logo=github)](https://github.com/sponsors/kevinveenbirkenbach) [![Patreon](https://img.shields.io/badge/Support-Patreon-orange?logo=patreon)](https://www.patreon.com/c/kevinveenbirkenbach) [![Buy Me a Coffee](https://img.shields.io/badge/Buy%20me%20a%20Coffee-Funding-yellow?logo=buymeacoffee)](https://buymeacoffee.com/kevinveenbirkenbach) [![PayPal](https://img.shields.io/badge/Donate-PayPal-blue?logo=paypal)](https://s.veen.world/paypaldonate)
2020-10-11 18:39:06 +02:00
2025-03-04 22:41:01 +01:00
**Backup Docker Volumes to Local** is a set of Python and shell scripts that enable you to perform incremental backups of all your Docker volumes using rsync. It is designed to integrate seamlessly with [Kevin's Package Manager](https://github.com/kevinveenbirkenbach/package-manager) under the alias **baudolo**, making it easy to install and manage. The tool supports both file and database recoveries with a clear, automated backup scheme.
2020-10-12 14:50:17 +02:00
2025-03-04 22:35:22 +01:00
[![License: AGPL v3](https://img.shields.io/badge/License-AGPL%20v3-blue.svg)](https://www.gnu.org/licenses/agpl-3.0) [![Docker Version](https://img.shields.io/badge/Docker-Yes-blue.svg)](https://www.docker.com) [![Python Version](https://img.shields.io/badge/Python-3.x-blue.svg)](https://www.python.org) [![GitHub stars](https://img.shields.io/github/stars/kevinveenbirkenbach/backup-docker-to-local.svg?style=social)](https://github.com/kevinveenbirkenbach/backup-docker-to-local/stargazers)
2020-12-26 16:31:47 +01:00
2025-03-04 22:35:22 +01:00
## 🎯 Goal
This project automates the backup of Docker volumes using incremental backups (rsync) and supports recovering both files and database dumps (MariaDB/PostgreSQL). A robust directory stamping mechanism ensures data integrity, and the tool also handles restarting Docker Compose services when necessary.
## 🚀 Features
- **Incremental Backups:** Uses rsync with `--link-dest` for efficient, versioned backups.
- **Database Backup Support:** Backs up MariaDB and PostgreSQL databases from running containers.
- **Volume Recovery:** Provides scripts to recover volumes and databases from backups.
- **Docker Compose Integration:** Option to automatically restart Docker Compose services after backup.
- **Flexible Configuration:** Easily integrated with your Docker environment with minimal setup.
- **Comprehensive Logging:** Detailed command output and error handling for safe operations.
## 🛠 Requirements
- **Linux Operating System** (with Docker installed) 🐧
- **Python 3.x** 🐍
- **Docker & Docker Compose** 🔧
- **rsync** installed on your system
## 📥 Installation
2025-03-04 22:41:01 +01:00
You can install **Backup Docker Volumes to Local** easily via [Kevin's Package Manager](https://github.com/kevinveenbirkenbach/package-manager) using the alias **baudolo**:
2020-10-12 14:51:09 +02:00
2020-10-12 14:52:00 +02:00
```bash
2025-04-19 00:04:29 +02:00
pkgmgr install baudolo
2020-10-12 14:52:00 +02:00
```
2020-10-12 14:50:17 +02:00
2025-03-04 22:35:22 +01:00
Alternatively, clone the repository directly:
2022-02-12 12:20:46 +00:00
```bash
2025-03-04 22:35:22 +01:00
git clone https://github.com/kevinveenbirkenbach/backup-docker-to-local.git
cd backup-docker-to-local
2022-02-12 12:20:46 +00:00
```
2025-03-04 22:35:22 +01:00
## 🚀 Usage
### Backup All Volumes
To backup all Docker volumes, simply run:
2021-08-19 13:09:44 +02:00
```bash
2025-03-04 22:35:22 +01:00
./backup-docker-to-local.sh
```
2025-03-04 22:35:22 +01:00
### Recovery
#### Recover Volume Files
```bash
2023-11-16 23:02:09 +01:00
bash ./recover-docker-from-local.sh "{{volume_name}}" "$(sha256sum /etc/machine-id | head -c 64)" "{{version_to_recover}}"
2025-03-04 22:35:22 +01:00
```
#### Recover Database
2025-03-04 22:35:22 +01:00
For example, to recover a MySQL/MariaDB database:
```bash
docker exec -i mysql_container mysql -uroot -psecret database < db.sql
2021-08-19 13:09:44 +02:00
```
2025-03-04 22:35:22 +01:00
#### Debug Mode
2022-02-12 12:20:46 +00:00
2025-03-04 22:35:22 +01:00
To inspect whats happening inside a container:
2020-12-27 10:12:47 +01:00
```bash
docker run -it --entrypoint /bin/sh --rm --volumes-from {{container_name}} -v /Backups/:/Backups/ kevinveenbirkenbach/alpine-rsync
```
2020-10-12 14:50:17 +02:00
2025-03-04 22:35:22 +01:00
## 🔍 Backup Scheme
The backup mechanism uses incremental backups with rsync and stamps directories with a unique hash. For more details on the backup scheme, check out [this blog post](https://blog.veen.world/blog/2020/12/26/how-i-backup-dedicated-root-servers/).
![Backup Scheme](https://blog.veen.world/wp-content/uploads/2020/12/server-backup-1024x755.jpg)
## 👨‍💻 Author
**Kevin Veen-Birkenbach**
- 📧 [kevin@veen.world](mailto:kevin@veen.world)
- 🌐 [https://www.veen.world/](https://www.veen.world/)
## 📜 License
2025-03-04 22:35:22 +01:00
This project is licensed under the **GNU Affero General Public License v3.0**. See the [LICENSE](./LICENSE) file for details.
2020-12-28 13:34:35 +01:00
2025-03-04 22:35:22 +01:00
## 🔗 More Information
2023-09-02 16:56:34 +02:00
2025-03-04 22:35:22 +01:00
- [Docker Volumes Documentation](https://docs.docker.com/storage/volumes/)
- [Docker Backup Volumes Blog](https://blog.ssdnodes.com/blog/docker-backup-volumes/)
- [Backup Strategies](https://en.wikipedia.org/wiki/Incremental_backup#Incremental)
2023-09-02 16:56:34 +02:00
2025-03-04 22:35:22 +01:00
---
2022-01-23 13:01:49 +01:00
2025-03-04 22:35:22 +01:00
Happy Backing Up! 🚀🔐