Skip to content

Commit

Permalink
✨ Allow specifying DB for export
Browse files Browse the repository at this point in the history
✨ Actually clone the service, not just the SERVICE_NAME DB
See dokku#180
  • Loading branch information
schlepptop committed Jul 18, 2020
1 parent 56f688e commit 8bd7057
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
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 "$@"

0 comments on commit 8bd7057

Please sign in to comment.