-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build: add make
targets to dump the database
#13771
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When working on the DB locally, it's sometimes necessary to make backups, particularly when testing schema migrations. This adds two Make targets, `make mysql-dump` and `make postgres-dump`, to facilitate that. Tested with both `make start PROFILE=postgres` and `make start PROFILE=mysql`. Results for MySQL: ```console $ make mysql-dump GIT_COMMIT=c9f0376594aed5ae0ebc53d3bf2970300406860f GIT_BRANCH=feat-cli-db-generator2 GIT_TAG=untagged GIT_TREE_STATE=dirty RELEASE_TAG=false DEV_BRANCH=true VERSION=latest KUBECTX=k3d-k3s-default DOCKER_DESKTOP=false K3D=true DOCKER_PUSH=false TARGET_PLATFORM=linux/amd64 RUN_MODE=local PROFILE=minimal AUTH_MODE=hybrid SECURE=false STATIC_FILES=false ALWAYS_OFFLOAD_NODE_STATUS=false UPPERIO_DB_DEBUG=0 LOG_LEVEL=debug NAMESPACED=true kubectl exec svc/mysql -- mysqldump --no-tablespaces -u mysql -ppassword argo > "db-dumps/mysql-2024-10-16T17:23:43Z.sql" mysqldump: [Warning] Using a password on the command line interface can be insecure. $ make mysql-cli < db-dumps/mysql-2024-10-16T17\:23\:43Z.sql GIT_COMMIT=c9f0376594aed5ae0ebc53d3bf2970300406860f GIT_BRANCH=feat-cli-db-generator2 GIT_TAG=untagged GIT_TREE_STATE=dirty RELEASE_TAG=false DEV_BRANCH=true VERSION=latest KUBECTX=k3d-k3s-default DOCKER_DESKTOP=false K3D=true DOCKER_PUSH=false TARGET_PLATFORM=linux/amd64 RUN_MODE=local PROFILE=minimal AUTH_MODE=hybrid SECURE=false STATIC_FILES=false ALWAYS_OFFLOAD_NODE_STATUS=false UPPERIO_DB_DEBUG=0 LOG_LEVEL=debug NAMESPACED=true kubectl exec -ti svc/mysql -- mysql -u mysql -ppassword argo Unable to use a TTY - input is not a terminal or the right kind of file mysql: [Warning] Using a password on the command line interface can be insecure. ``` Results for PostgreSQL: ``` $ make postgres-dump GIT_COMMIT=c9f0376594aed5ae0ebc53d3bf2970300406860f GIT_BRANCH=feat-cli-db-generator2 GIT_TAG=untagged GIT_TREE_STATE=dirty RELEASE_TAG=false DEV_BRANCH=true VERSION=latest KUBECTX=k3d-k3s-default DOCKER_DESKTOP=false K3D=true DOCKER_PUSH=false TARGET_PLATFORM=linux/amd64 RUN_MODE=local PROFILE=minimal AUTH_MODE=hybrid SECURE=false STATIC_FILES=false ALWAYS_OFFLOAD_NODE_STATUS=false UPPERIO_DB_DEBUG=0 LOG_LEVEL=debug NAMESPACED=true kubectl exec svc/postgres -- pg_dump -U postgres > "db-dumps/postgres-2024-10-16T17:26:56Z.sql" $ make postgres-cli < db-dumps/postgres-2024-10-16T17\:28\:02Z.sql GIT_COMMIT=d05cf6459cdd956cb621a6552f009e21db0a3789 GIT_BRANCH=main GIT_TAG=untagged GIT_TREE_STATE=dirty RELEASE_TAG=false DEV_BRANCH=false VERSION=latest KUBECTX=k3d-k3s-default DOCKER_DESKTOP=false K3D=true DOCKER_PUSH=false TARGET_PLATFORM=linux/amd64 RUN_MODE=local PROFILE=minimal AUTH_MODE=hybrid SECURE=false STATIC_FILES=true ALWAYS_OFFLOAD_NODE_STATUS=false UPPERIO_DB_DEBUG=0 LOG_LEVEL=debug NAMESPACED=true kubectl exec -ti svc/postgres -- psql -U postgres Unable to use a TTY - input is not a terminal or the right kind of file SET SET SET SET SET set_config ------------ (1 row) SET SET SET SET ALTER TABLE DROP INDEX DROP INDEX DROP INDEX DROP INDEX DROP INDEX DROP INDEX ALTER TABLE ALTER TABLE ALTER TABLE DROP TABLE DROP TABLE DROP TABLE DROP TABLE SET SET CREATE TABLE ALTER TABLE CREATE TABLE ALTER TABLE CREATE TABLE ALTER TABLE CREATE TABLE ALTER TABLE COPY 0 COPY 0 COPY 0 COPY 2 ALTER TABLE ALTER TABLE ALTER TABLE CREATE INDEX CREATE INDEX CREATE INDEX CREATE INDEX CREATE INDEX CREATE INDEX ALTER TABLE ``` Signed-off-by: Mason Malone <651224+MasonM@users.noreply.github.com>
agilgur5
changed the title
test: add Make targets to dump the database
build: add Oct 16, 2024
make
targets to dump the database
agilgur5
added
area/build
Build or GithubAction/CI issues
area/workflow-archive
area/contributing
Contributing docs, ownership, etc. Also devtools like devcontainer and Nix
labels
Oct 16, 2024
Joibel
approved these changes
Oct 17, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one, thank you.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area/build
Build or GithubAction/CI issues
area/contributing
Contributing docs, ownership, etc. Also devtools like devcontainer and Nix
area/workflow-archive
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
When working on the DB locally, it's sometimes necessary to make backups, particularly when testing schema migrations (e.g. #13601).
This is similar to #13715, and I thought about combining the two PRs, but I figured it's better to keep them separate, since they don't conflict with each other.
Modifications
This adds two Make targets,
make mysql-dump
andmake postgres-dump
, to runmysqldump
andpg_dump
, respectively. I also simplified the existingmake mysql-cli
andmake postgres-cli
commands to usekubectl exec svc/...
instead of manually grabbing the pod, since passing a service tokubectl exec
will cause it to automatically select the first (and only) pod in the service.Verification
Tested with both
make start PROFILE=postgres
andmake start PROFILE=mysql
.Results for MySQL
Results for PostgreSQL