From e1ef8447f2379c8bf453b37c16943683bf2b108f Mon Sep 17 00:00:00 2001 From: Kevin Carter Date: Fri, 29 Mar 2024 20:27:37 -0500 Subject: [PATCH] feat: Update the mariadb ops guide to show how to dump the databases Signed-off-by: Kevin Carter --- docs/infrastructure-mariadb-connect.md | 13 ------- docs/infrastructure-mariadb-ops.md | 54 ++++++++++++++++++++++++++ mkdocs.yml | 2 +- 3 files changed, 55 insertions(+), 14 deletions(-) delete mode 100644 docs/infrastructure-mariadb-connect.md create mode 100644 docs/infrastructure-mariadb-ops.md diff --git a/docs/infrastructure-mariadb-connect.md b/docs/infrastructure-mariadb-connect.md deleted file mode 100644 index 7f00c951..00000000 --- a/docs/infrastructure-mariadb-connect.md +++ /dev/null @@ -1,13 +0,0 @@ -# Connect to the database - -Sometimes an operator may need to connect to the database to troubleshoot things or otherwise make modifications to the databases in place. The following command can be used to connect to the database from a node within the cluster. - -``` shell -mysql -h $(kubectl -n openstack get service maxscale-galera -o jsonpath='{.spec.clusterIP}') \ - -p$(kubectl --namespace openstack get secret maxscale -o jsonpath='{.data.password}' | base64 -d) \ - -u maxscale-galera-client -``` - -!!! info - - The following command will leverage your kube configuration and dynamically source the needed information to connect to the MySQL cluster. You will need to ensure you have installed the mysql client tools on the system you're attempting to connect from. diff --git a/docs/infrastructure-mariadb-ops.md b/docs/infrastructure-mariadb-ops.md new file mode 100644 index 00000000..5abd6f88 --- /dev/null +++ b/docs/infrastructure-mariadb-ops.md @@ -0,0 +1,54 @@ +# MariaDB Operations + +Tips and tricks for managing and operating the MariaDB cluster within a Genestack environment. + +## Connect to the database + +Sometimes an operator may need to connect to the database to troubleshoot things or otherwise make modifications to the databases in place. The following command can be used to connect to the database from a node within the cluster. + +``` shell +mysql -h $(kubectl -n openstack get service maxscale-galera -o jsonpath='{.spec.clusterIP}') \ + -p$(kubectl --namespace openstack get secret maxscale -o jsonpath='{.data.password}' | base64 -d) \ + -u maxscale-galera-client +``` + +!!! info + + The following command will leverage your kube configuration and dynamically source the needed information to connect to the MySQL cluster. You will need to ensure you have installed the mysql client tools on the system you're attempting to connect from. + +## Dumping the databases + +When running `mysqldump` or `mariadbdump` the following commands can be useful for generating a quick backup. + +``` shell +mysqldump --host=$(kubectl -n openstack get service mariadb-galera -o jsonpath='{.spec.clusterIP}')\ + --user=root \ + --password=$(kubectl --namespace openstack get secret mariadb -o jsonpath='{.data.root-password}' | base64 -d) \ + --single-transaction \ + --routines \ + --triggers \ + --events \ + ${DATABASE_NAME} \ + --result-file=/tmp/${DATABASE_NAME}-$(date +%s).sql +``` + +!!! example "Dump all databases as individual files in `/tmp`" + + ``` shell + mysql -h $(kubectl -n openstack get service mariadb-galera -o jsonpath='{.spec.clusterIP}') \ + -u root \ + -p$(kubectl --namespace openstack get secret mariadb -o jsonpath='{.data.root-password}' | base64 -d) \ + -e 'show databases;' \ + --column-names=false \ + --vertical | \ + awk '/[:alnum:]/' | \ + xargs -i mysqldump --host=$(kubectl -n openstack get service mariadb-galera -o jsonpath='{.spec.clusterIP}') \ + --user=root \ + --password=$(kubectl --namespace openstack get secret mariadb -o jsonpath='{.data.root-password}' | base64 -d) \ + --single-transaction \ + --routines \ + --triggers \ + --events \ + {} \ + --result-file=/tmp/{}-$(date +%s).sql + ``` diff --git a/mkdocs.yml b/mkdocs.yml index b493d968..72d30d94 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -206,7 +206,7 @@ nav: - Running Kubespray Upgrade: k8s-kubespray-upgrade.md - Infrastructure: - OVN Database Backup: infrastructure-ovn-db-backup.md - - Connecting to MySQL: infrastructure-mariadb-connect.md + - MariaDB Operations: infrastructure-mariadb-ops.md - OpenStack: - Generating Clouds YAML: openstack-clouds.md - Keystone Federation to Rackspace: openstack-keystone-federation.md