db dump procedure

This commit is contained in:
sfigato 2024-07-19 23:59:23 +02:00
parent 0d1b272919
commit 8c2f5daa09
2 changed files with 30 additions and 8 deletions

View File

@ -1,6 +1,11 @@
DOCKER ?= docker
COMPOSE ?= docker compose
PUBLIC_URL ?= https://askar.abbiamoundominio.org
TMPDB_CONN = --host=127.0.0.1 --port=3307 --user=root --password=toor --ssl-verify-server-cert=FALSE
DUMP_CONN = -h 127.0.0.1 -P 3306 --user root --password=toor --ssl-verify-server-cert=FALSE
VERSIONED_DUMP = ./assets/db/dump.sql
TMP_PROD_DUMP = ./out/db.tmp.sql
PROD_DUMP = ./out/dump.sql
dev-run:
$(COMPOSE) up
@ -12,7 +17,7 @@ dev-clean:
$(COMPOSE) down --volumes
dev-dump:
mariadb-dump --hex-blob -h 127.0.0.1 -P 3306 --user root --password=toor askar > ./assets/db/dump.sql
mariadb-dump $(DUMP_CONN) askar > $(VERSIONED_DUMP)
./out:
mkdir ./out
@ -23,5 +28,22 @@ prepare-image:
$(DOCKER) build -t unit/askar-website .
$(DOCKER) image save -o out/image.tar unit/askar-website
prepare-db:
cat ./assets/db/dump.sql | sed -e 's;http://localhost:8080;$(PUBLIC_URL);g' > ./out/db.sql
tmpdb-start:
$(DOCKER) run -d --rm --name tmpdb \
-p 3307:3306 \
-e MYSQL_DATABASE=askar \
-e MYSQL_USER=askar \
-e MYSQL_PASSWORD=askar \
-e MYSQL_ROOT_PASSWORD=toor \
mysql:8
while ! mariadb-admin ping $(TMPDB_CONN); do sleep 1; done
tmpdb-stop:
$(DOCKER) stop tmpdb
tmpdb-do-dump:
cat $(VERSIONED_DUMP) | sed -e 's;http://localhost:8080;$(PUBLIC_URL);g' > $(TMP_PROD_DUMP)
cat $(TMP_PROD_DUMP) | grep -v -E '^/\*' | (echo "SET sql_mode = '';" && cat) | mariadb $(TMPDB_CONN) askar
mariadb-dump --default-character-set=binary --hex-blob $(TMPDB_CONN) askar | grep -v -E '^/\*' > $(PROD_DUMP)
prepare-db: tmpdb-start tmpdb-do-dump tmpdb-stop

File diff suppressed because one or more lines are too long