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

Allow specifying DB for export #207

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions functions
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ 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 DATABASE_NAME="${2:-$(get_database_name "$SERVICE")}"
local PASSWORD="$(service_password "$SERVICE")"

[[ -n $SSH_TTY ]] && stty -opost
Expand All @@ -118,7 +118,7 @@ service_import() {
if [[ -t 0 ]]; then
dokku_log_fail "No data provided on stdin."
fi
docker exec -i "$SERVICE_NAME" env PGPASSWORD="$PASSWORD" pg_restore -h localhost -cO --if-exists -d "$DATABASE_NAME" -U postgres -w
docker exec -i "$SERVICE_NAME" env PGPASSWORD="$PASSWORD" pg_restore -h localhost -cO --if-exists -C -d "$DATABASE_NAME" -U postgres -w
}

service_start() {
Expand Down
8 changes: 7 additions & 1 deletion subcommands/clone
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ service-clone-cmd() {
dokku_log_info2 "Cloning $SERVICE to $NEW_SERVICE @ $PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION"
service_create "$NEW_SERVICE" "${@:3}"
dokku_log_info1 "Copying data from $SERVICE to $NEW_SERVICE"
service_export "$SERVICE" | service_import "$NEW_SERVICE" >/dev/null 2>&1 || true
for DATABASE_NAME in $(docker exec dokku.postgres.td1 psql -qtA -U postgres -c "SELECT datname FROM pg_catalog.pg_database;"); do
if [[ $DATABASE_NAME == "postgres" || $DATABASE_NAME == "template0" ]]; then
continue
fi
service_export "$SERVICE" "$DATABASE_NAME" | service_import "$NEW_SERVICE" "$DATABASE_NAME">/dev/null 2>&1 || true

done
dokku_log_info2 "Done"
}

Expand Down
3 changes: 2 additions & 1 deletion subcommands/export
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ service-export-cmd() {
local cmd="$PLUGIN_COMMAND_PREFIX:export" argv=("$@")
[[ ${argv[0]} == "$cmd" ]] && shift 1
declare SERVICE="$1"
declare DATABASE_NAME="$2"
is_implemented_command "$cmd" || dokku_log_fail "Not yet implemented"

[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a valid name for the service"
verify_service_name "$SERVICE"
service_export "$SERVICE"
service_export "$SERVICE" "$DATABASE_NAME"
}

service-export-cmd "$@"