Skip to content
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

feat: backup all db #133

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions functions
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ service_export() {
local SERVICE="$1"
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
local SERVICE_NAME="$(get_service_name "$SERVICE")"
local DATABASE_NAME="$(get_database_name "$SERVICE")"
local PASSWORD="$(service_password "$SERVICE")"
local ROOTPASSWORD="$(service_root_password "$SERVICE")"

[[ -n $SSH_TTY ]] && stty -opost
docker exec "$SERVICE_NAME" bash -c "printf '[client]\ndefault-character-set=utf8mb4\npassword=$PASSWORD\n' > /root/credentials.cnf"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason we dropped the character set here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I probably left it out by accident

docker exec "$SERVICE_NAME" mysqldump --defaults-extra-file=/root/credentials.cnf --user=mysql --single-transaction --quick "$DATABASE_NAME"
docker exec "$SERVICE_NAME" rm /root/credentials.cnf
docker exec "$SERVICE_NAME" bash -c "printf '[client]\nuser=root\npassword=$ROOTPASSWORD\n' > /root/credentials.cnf"
docker exec "$SERVICE_NAME" bash -c "printf 'show databases;' | mysql --defaults-extra-file=/root/credentials.cnf | grep -wvE 'Database|mysql|sys|information_schema|performance_schema' > databases_to_backup"
docker exec "$SERVICE_NAME" bash -c "cat databases_to_backup | xargs mysqldump --defaults-extra-file=/root/credentials.cnf --single-transaction --quick --databases"
docker exec "$SERVICE_NAME" rm /root/credentials.cnf databases_to_backup
status=$?
[[ -n $SSH_TTY ]] && stty opost
exit $status
Expand All @@ -135,7 +135,10 @@ service_import() {
if [[ -t 0 ]]; then
dokku_log_fail "No data provided on stdin."
fi
docker exec -i "$SERVICE_NAME" mysql --user=root --password="$ROOTPASSWORD" "$DATABASE_NAME"

docker exec "$SERVICE_NAME" bash -c "printf '[client]\nuser=root\npassword=$ROOTPASSWORD\n' > /root/credentials.cnf"
docker exec -i "$SERVICE_NAME" mysql --defaults-extra-file=/root/credentials.cnf "$DATABASE_NAME"
docker exec "$SERVICE_NAME" rm /root/credentials.cnf
Comment on lines -138 to +141
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this particular change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is introduced to surpress warnings from mysql

Warning: Using a password on the command line interface can be insecure.

https://stackoverflow.com/questions/20751352/suppress-warning-messages-using-mysql-from-within-terminal-but-password-written

}

service_start() {
Expand Down