diff --git a/plugins/ps/subcommands/restore b/plugins/ps/subcommands/restore index 9f37cf524..b9c209fd1 100755 --- a/plugins/ps/subcommands/restore +++ b/plugins/ps/subcommands/restore @@ -9,6 +9,9 @@ ps_restore_cmd() { local cmd="ps:restore" local APP="$2" + local DOKKU_SCHEDULER=$(config_get "$APP" DOKKU_SCHEDULER || echo "docker-local") + plugn trigger pre-restore "$DOKKU_SCHEDULER" + if [[ -n "$APP" ]]; then if ! (is_deployed "$APP"); then dokku_log_warn "App $APP has not been deployed" diff --git a/plugins/scheduler-docker-local/pre-restore b/plugins/scheduler-docker-local/pre-restore new file mode 100755 index 000000000..660cd5193 --- /dev/null +++ b/plugins/scheduler-docker-local/pre-restore @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" + +scheduler-docker-local-pre-restore() { + declare desc="scheduler-docker-local pre-restore plugin trigger" + declare trigger="scheduler-docker-local pre-restore" + declare DOKKU_SCHEDULER="$1" + + if [[ "$DOKKU_SCHEDULER" != "docker-local" ]]; then + return + fi + + # delete all "old" containers + # shellcheck disable=SC2046 + docker rm $(docker ps --format "{{.Names}}" -a -f "label=$DOKKU_CONTAINER_LABEL" -q | grep -E '(.+\..+\.[0-9]+\.[0-9]+$)') &> /dev/null || true +} + +scheduler-docker-local-pre-restore "$@"