From 15271eb7f956c9da46d91250bffca88ab9518b25 Mon Sep 17 00:00:00 2001 From: zhenghaoz <9030120+zhenghaoz@users.noreply.github.com> Date: Fri, 2 Oct 2026 03:52:50 +0000 Subject: [PATCH 1/3] Fix MySQL backups with generated search columns --- docker/backup/Dockerfile | 12 +++++++----- scripts/backup.sh | 17 +++++++++++++++-- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/docker/backup/Dockerfile b/docker/backup/Dockerfile index 3fb91ea..fc319b8 100644 --- a/docker/backup/Dockerfile +++ b/docker/backup/Dockerfile @@ -1,13 +1,15 @@ -FROM python:3.12 +FROM mysql:8.4 -# Install MySQL client. -RUN apt-get update && apt-get install -y mariadb-client +# Use the official MySQL dump client for MySQL generated-column support. +# Install Python and gzip for the S3 client and compressed backups. +RUN microdnf install -y python3-pip gzip && microdnf clean all # Install S3 client. -RUN pip install s3cmd +RUN pip3 install --no-cache-dir s3cmd # Copy files. COPY scripts/backup.sh ./ # Run backup task. -CMD bash backup.sh +ENTRYPOINT [] +CMD ["bash", "backup.sh"] diff --git a/scripts/backup.sh b/scripts/backup.sh index 13eaa5d..8e625b6 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -1,11 +1,24 @@ -set -e +#!/usr/bin/env bash +set -eo pipefail + +# MariaDB's dump client can emit explicit values for MySQL generated columns. +# Use the MySQL client so INSERTs omit those columns and remain importable. +if mysqldump --version | grep -qi mariadb; then + echo "Backup requires MySQL mysqldump; rebuild the backup image to replace the MariaDB client." >&2 + exit 1 +fi while true; do SQL_FILE=$(date '+%Y-%m-%d.%H').sql.gz # Dump and compress database in one stream - mysqldump --no-tablespaces -h ${MYSQL_HOST:=127.0.0.1} -u ${MYSQL_USER:=gorse} -p${MYSQL_PASSWORD:=gorse_pass} --ssl-verify-server-cert=0 ${MYSQL_DATABASE:=gorse} users items feedback flask_dance_oauth | gzip > $SQL_FILE + MYSQL_PWD="${MYSQL_PASSWORD:=gorse_pass}" mysqldump \ + --no-tablespaces --single-transaction --complete-insert \ + --column-statistics=0 --set-gtid-purged=OFF --ssl-mode=PREFERRED \ + -h "${MYSQL_HOST:=127.0.0.1}" -u "${MYSQL_USER:=gorse}" \ + "${MYSQL_DATABASE:=gorse}" users items feedback flask_dance_oauth \ + | gzip > "$SQL_FILE" # Upload SQL file s3cmd --access_key=$S3_ACCESS_KEY \ From 53d07e14aecaf6c3b77bbb834d5124a126656d79 Mon Sep 17 00:00:00 2001 From: zhenghaoz Date: Mon, 5 Oct 2026 09:18:44 +0800 Subject: [PATCH 2/3] Revert backup script changes --- scripts/backup.sh | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index 8e625b6..13eaa5d 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -1,24 +1,11 @@ -#!/usr/bin/env bash -set -eo pipefail - -# MariaDB's dump client can emit explicit values for MySQL generated columns. -# Use the MySQL client so INSERTs omit those columns and remain importable. -if mysqldump --version | grep -qi mariadb; then - echo "Backup requires MySQL mysqldump; rebuild the backup image to replace the MariaDB client." >&2 - exit 1 -fi +set -e while true; do SQL_FILE=$(date '+%Y-%m-%d.%H').sql.gz # Dump and compress database in one stream - MYSQL_PWD="${MYSQL_PASSWORD:=gorse_pass}" mysqldump \ - --no-tablespaces --single-transaction --complete-insert \ - --column-statistics=0 --set-gtid-purged=OFF --ssl-mode=PREFERRED \ - -h "${MYSQL_HOST:=127.0.0.1}" -u "${MYSQL_USER:=gorse}" \ - "${MYSQL_DATABASE:=gorse}" users items feedback flask_dance_oauth \ - | gzip > "$SQL_FILE" + mysqldump --no-tablespaces -h ${MYSQL_HOST:=127.0.0.1} -u ${MYSQL_USER:=gorse} -p${MYSQL_PASSWORD:=gorse_pass} --ssl-verify-server-cert=0 ${MYSQL_DATABASE:=gorse} users items feedback flask_dance_oauth | gzip > $SQL_FILE # Upload SQL file s3cmd --access_key=$S3_ACCESS_KEY \ From 718e3ef0c56beb61ef40befc19ea3fd46e7f1543 Mon Sep 17 00:00:00 2001 From: zhenghaoz Date: Mon, 5 Oct 2026 09:22:21 +0800 Subject: [PATCH 3/3] Use MySQL-compatible SSL mode in backup script --- scripts/backup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index 13eaa5d..c59f702 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -5,7 +5,7 @@ while true; do SQL_FILE=$(date '+%Y-%m-%d.%H').sql.gz # Dump and compress database in one stream - mysqldump --no-tablespaces -h ${MYSQL_HOST:=127.0.0.1} -u ${MYSQL_USER:=gorse} -p${MYSQL_PASSWORD:=gorse_pass} --ssl-verify-server-cert=0 ${MYSQL_DATABASE:=gorse} users items feedback flask_dance_oauth | gzip > $SQL_FILE + mysqldump --no-tablespaces -h ${MYSQL_HOST:=127.0.0.1} -u ${MYSQL_USER:=gorse} -p${MYSQL_PASSWORD:=gorse_pass} --ssl-mode=PREFERRED ${MYSQL_DATABASE:=gorse} users items feedback flask_dance_oauth | gzip > $SQL_FILE # Upload SQL file s3cmd --access_key=$S3_ACCESS_KEY \