diff --git a/plugins/00_dokku-standard/backup-check b/plugins/00_dokku-standard/backup-check new file mode 100755 index 000000000..91e7bfb51 --- /dev/null +++ b/plugins/00_dokku-standard/backup-check @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +VERSION="$1" +IMPORT_DIR="$2" +TARGET_DIR="$3" +APPS="$(< $4 )" + +ret=0 + +for app in $APPS; do + if [[ -d $TARGET_DIR/$app ]]; then + ret=1 + echo "Trying to import application $app which already exists." 2>&1 + fi +done + +exit $ret + diff --git a/plugins/00_dokku-standard/backup-import b/plugins/00_dokku-standard/backup-import index 076c0e930..86404a99b 100755 --- a/plugins/00_dokku-standard/backup-import +++ b/plugins/00_dokku-standard/backup-import @@ -6,8 +6,8 @@ TARGET_DIR="$3" [[ -f $IMPORT_DIR/.sshcommand ]] && mv $IMPORT_DIR/.sshcommand $TARGET_DIR/.sshcommand if [[ -f $IMPORT_DIR/.ssh/authorized_keys ]]; then - mkdir $TARGET_DIR/.ssh - mv $IMPORT_DIR/.ssh/authorized_keys $TARGET_DIR/.ssh/authorized_keys + mkdir -p $TARGET_DIR/.ssh + cat $IMPORT_DIR/.ssh/authorized_keys $TARGET_DIR/.ssh/authorized_keys | uniq > $TARGET_DIR/.ssh/authorized_keys chmod 0700 $TARGET_DIR/.ssh chmod 0600 $TARGET_DIR/.ssh/* fi diff --git a/plugins/backup/commands b/plugins/backup/commands index a4e406e79..9aa6cdc65 100755 --- a/plugins/backup/commands +++ b/plugins/backup/commands @@ -33,6 +33,13 @@ set -e; case "$1" in ;; backup:import) + if [[ $2 == "-f" ]]; then + force=true + shift + else + force=false + fi + INPUT_FILE="$2" [[ -z $INPUT_FILE ]] && INPUT_FILE="-" @@ -56,6 +63,15 @@ set -e; case "$1" in BACKUP_ROOT="$BACKUP_TMP_DIR""$DOKKU_ROOT" TARGET_DIR="$DOKKU_ROOT" + if ! pluginhook backup-check $VERSION "$BACKUP_ROOT" "$TARGET_DIR" "$BACKUP_TMP_DIR/.dokku_backup_apps"; then + if $force; then + echo "-f used. Ignoring warnings." + else + echo "Archive did not pass sanity checks. Use -f to import anyway" >&2 + exit 1 + fi + fi + # create all the app directories while read app; do mkdir "$TARGET_DIR/$app"; echo "Imported $app"; done < $BACKUP_TMP_DIR/.dokku_backup_apps