From 4e737e739f83d78f4602122d1b4593a4e8d2f99a Mon Sep 17 00:00:00 2001 From: Paul Lietar Date: Sat, 30 Nov 2013 02:45:32 +0000 Subject: [PATCH 1/3] Add a backup-check used to validate the archive. This allows plugins to refuse a backup, before the import process starts. Users can force the import using -f. --- plugins/backup/commands | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 From a4451e82accdf514eb866e64a35d14c6c2df245a Mon Sep 17 00:00:00 2001 From: Paul Lietar Date: Sat, 30 Nov 2013 02:45:58 +0000 Subject: [PATCH 2/3] Merge ssh keys rather than overwriting them. --- plugins/00_dokku-standard/backup-import | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From 5c58a5e8e7257d517d6763343f8aba429fcafa1d Mon Sep 17 00:00:00 2001 From: Paul Lietar Date: Sat, 30 Nov 2013 02:46:42 +0000 Subject: [PATCH 3/3] Add a backup-check to avoid reimporting apps. --- plugins/00_dokku-standard/backup-check | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100755 plugins/00_dokku-standard/backup-check 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 +