Skip to content

Commit

Permalink
Remove stopper service from automation script
Browse files Browse the repository at this point in the history
  • Loading branch information
an3l committed Feb 14, 2024
1 parent 2fa4337 commit 965f16b
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 132 deletions.
1 change: 1 addition & 0 deletions examples/migration-8.0/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dump-data/*
25 changes: 6 additions & 19 deletions examples/migration-8.0/compose-mysql8.0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ services:
MARIADB_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
MARIADB_USER: ${DB_USER}
MARIADB_PASSWORD: ${DB_PASSWORD}
MARIADB_DB: ${DB_DATABASE}
MYSQL_CONT_NAME: ${MYSQL_name}
container_name: ${MARIADB_DUMP_name}
image: mariadb:lts
depends_on:
Expand All @@ -40,40 +42,25 @@ services:
interval: 20s
timeout: 20s
retries: 3
# command: >
# bash -c "
# echo 'MariaDB service started. Dump MySQL data ...'
# mariadb-dump -h mysql-container -uroot -psecret testdb > /etc/dump/mysql-dump-data.sql"
# user: ${UID}:${EUID}
volumes:
- mysqldump:/etc/dump/
# This will not exit container, but command: will
- ./dump-mysql.sh:/docker-entrypoint-initdb.d/dump-mysql.sh
networks:
- backend
# entrypoint: ["/docker-entrypoint-initdb.d/dump-mysql.sh"]

# We cannot share the same dump directory, we need to stop mariadb-dump
stopper:
image: docker:20.10
depends_on:
mariadb-dump:
condition: service_healthy
volumes:
- /var/run/docker.sock:/var/run/docker.sock
command: ["sh", "-c", "docker stop mariadb-container-dump"]

# Sidecar for insert dump file
mariadb-migrated-from-mysql8:
environment:
MARIADB_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
MARIADB_USER: ${DB_USER}
MARIADB_PASSWORD: ${DB_PASSWORD}
MARIADB_DB: ${DB_DATABASE}
container_name: ${MARIADB_MIGRATED_name}
image: mariadb:lts
depends_on:
mariadb-dump:
condition: service_completed_successfully
condition: service_healthy
# restart: true
volumes:
- mysqldump:/etc/dump/
- ./migrate-mariadb.sh:/docker-entrypoint-initdb.d/migrate-mariadb.sh
Expand All @@ -82,7 +69,7 @@ services:

volumes:
dbdata: {}
# sudo chown -R 999:999 ${PWD}/dump-data # host
# sudo chown -R 999:999 ${PWD}/dump-data # on host before running this file
mysqldump:
driver: local
driver_opts:
Expand Down

This file was deleted.

50 changes: 0 additions & 50 deletions examples/migration-8.0/dump-data/mysql-dump-data.sql

This file was deleted.

19 changes: 9 additions & 10 deletions examples/migration-8.0/dump-mysql.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#!/bin/bash

echo 'MariaDB service started. Dump MySQL data ...'
echo 'MariaDB service started.'
# Run your commands and exit container
whoami # mysql"
whoami # mysql
# sh -c "chown -R mysql:mysql /etc/dump" # Operation permitted
# sh -c "ls -la /etc/dump"
sh -c "mariadb-dump -h mysql-container -uroot -psecret testdb > /etc/dump/mysql-dump-data.sql"
sh -c "ls -la /etc/dump/"
echo "List before"
sh -c "cp /etc/dump/mysql-dump-data.sql /etc/dump/mysql-dump-data-utf8mb4_unicode_ci.sql"
sh -c "ls -la /etc/dump/"
echo "List after"
sh -c "sed -i 's/utf8mb4_0900_ai_ci/utf8mb4_unicode_ci/g' /etc/dump/mysql-dump-data-utf8mb4_unicode_ci.sql"
echo 'Dump and compress MySQL data with changed collation ...'
fileName="mysql-dump-data.sql.zst"
if [ -f "$fileName" ]; then
echo "File ${fileName} exists. Remove it ... "
rm "$fileName"
fi
sh -c "mariadb-dump -h${MYSQL_CONT_NAME} -uroot -p${MARIADB_ROOT_PASSWORD} ${MARIADB_DB} | sed 's/utf8mb4_0900/uca1400/g' | zstd > /etc/dump/${fileName}"
14 changes: 11 additions & 3 deletions examples/migration-8.0/migrate-mariadb.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#!/bin/bash
echo "Extract file"
oldFile="/etc/dump/mysql-dump.sql"
if [ -f "$oldFile" ]; then
echo "Old file ${oldFile} exists. Remove it ... "
rm "$oldFile"
echo "Extracting ..."
fi
sh -c "zstd -d /etc/dump/mysql-dump-data.sql.zst -o /etc/dump/mysql-dump.sql"
echo "Show data in MariaDB"
mariadb -uroot -psecret -e "create database testdb;"
mariadb -uroot -psecret testdb < /etc/dump/mysql-dump-data-utf8mb4_unicode_ci.sql
mariadb -uroot -psecret -e "show databases; select * from countries;"
mariadb -uroot -p"${MARIADB_ROOT_PASSWORD}" -e "create database testdb;"
mariadb -uroot -p"${MARIADB_ROOT_PASSWORD}" "${MARIADB_DB}" < /etc/dump/mysql-dump.sql
mariadb -uroot -p"${MARIADB_ROOT_PASSWORD}" -e "show databases; select * from testdb.countries;"

0 comments on commit 965f16b

Please sign in to comment.