From 8784ddaf0f9fc57341ccd8a5f2a1c206dea261cd Mon Sep 17 00:00:00 2001 From: RamiusLr Date: Wed, 12 Nov 2025 14:42:36 +0100 Subject: [PATCH] feat: add LICENSE and README --- LICENSE | 21 +++++++++ README.md | 102 ++++++++++++++++++++++++++++++++++++++++++++ internal/api/api.go | 3 +- 3 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 LICENSE create mode 100644 README.md diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0636659 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 RamiusLr + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..ef223b1 --- /dev/null +++ b/README.md @@ -0,0 +1,102 @@ +ddbb +=== + +`ddbb`, for *Docker DataBase Backup*, is a tool to manage dumps of docker stacks +databases. + +The purpose isn't to manage full versionning, RPO, RTO, etc. I just want +something simple to dump databases to a local file, that my backup tool would +next handle. + +This means this tool targets *Docker* databases only, and relies heavily on +*Docker* API and labels. + + +# Installation and prerequisites +Use this `compose.yaml` as a base example: +```yaml +services: + ddbb: + image: ramiuslr/ddbb + container_name: ddbb + restart: always + volumes: + - /var/run/docker.sock:/var/run/docker.sock:ro + - :/backups + networks: + - ddbb + ports: + - 3000:3000 + environment: + BACKUP_CRON: "0 11,23 * * *" + +networks: + ddbb: + name: ddbb +``` + +The `BACKUP_CRON` variable is the cron variable format to schedule automatic databases +dumps. You can check syntax on https://crontab.guru/. + +Then you can run it with: +```bash +docker compose up -d +``` +Please note that the container should have access to your databases networks, +and the *Docker* socket. + +You also need to declare your database credentials using variables, as show in +the example below. + +This tool has only been tested locally for now, and support only: +- `mariadb` +- `postgres` +- `mongodb` + +# Usage +## Setting up the targets +When you want to manage a database with `ddbb`, you just need to add two labels +to its *Compose* manifest, for example: +```yaml +services: + mariadb: + image: mariadb:11.8.2 + container_name: mariadb + restart: always + expose: + - 3306 + environment: + MARIADB_RANDOM_ROOT_PASSWORD: true + MARIADB_USER: + MARIADB_PASSWORD: + MARIADB_DATABASE: + volumes: + - ./mariadb:/var/lib/mysql + networks: + - ddbb + labels: + ddbb.enable: true + ddbb.kind: mariadb +``` +The kind can be one of those: +- `mariadb` +- `postgres` +- `mongodb` + +The tool will then "see" your database and be able to connect to it, to perform +the following actions: +- Dump +- Restore +- Integrity check + +# Building yourself +There is a `Justfile` (*Makefile* alternative), which produces a *Docker* image, so this is pretty simple: +```bash +just run +``` + +# Contributing +Every suggestion, issue, or PR is very welcome ! + +However, please note that I am developing this on my spare time, so I can't +guarantee response time, release dates, etc. diff --git a/internal/api/api.go b/internal/api/api.go index bbea897..a1bf11e 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -152,14 +152,15 @@ func triggerRestore(c *gin.Context) { func triggerIntegrityCheck(c *gin.Context) { // Read Id from JSON submitted data var req RequestBody + if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request"}) - return } if req.Id == "" { c.JSON(http.StatusBadRequest, gin.H{"error": "Missing backup job id"}) } + if isValidJobId(req.Id) { result, err := integrity.NewIntegrityCheckJob(selectJob(req.Id)) if err != nil {