diff --git a/plugins/00_dokku-standard/backup-export b/plugins/00_dokku-standard/backup-export new file mode 100755 index 000000000..102ef082c --- /dev/null +++ b/plugins/00_dokku-standard/backup-export @@ -0,0 +1,9 @@ +#!/bin/bash +VERSION="$1" +BASE_DIR="$2" + +cat; +[[ -f $BASE_DIR/.sshcommand ]] && echo "$BASE_DIR/.sshcommand" +[[ -f $BASE_DIR/.ssh/authorized_keys ]] && echo "$BASE_DIR/.ssh/authorized_keys" +[[ -f $BASE_DIR/HOSTNAME ]] && echo "$BASE_DIR/HOSTNAME" +[[ -f $BASE_DIR/VHOST ]] && echo "$BASE_DIR/VHOST" diff --git a/plugins/00_dokku-standard/backup-import b/plugins/00_dokku-standard/backup-import new file mode 100755 index 000000000..a3f691d9d --- /dev/null +++ b/plugins/00_dokku-standard/backup-import @@ -0,0 +1,14 @@ +#!/bin/bash +VERSION="$1" +IMPORT_DIR="$2" +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 + chmod 0700 $TARGET_DIR/.ssh + chmod 0600 $TARGET_DIR/.ssh/* +fi +[[ -f $IMPORT_DIR/HOSTNAME ]] && mv $IMPORT_DIR/HOSTNAME $TARGET_DIR/HOSTNAME +[[ -f $IMPORT_DIR/VHOST ]] && mv $IMPORT_DIR/VHOST $TARGET_DIR/VHOST diff --git a/plugins/backup/commands b/plugins/backup/commands new file mode 100755 index 000000000..635b44a8e --- /dev/null +++ b/plugins/backup/commands @@ -0,0 +1,73 @@ +#!/bin/bash +CURRENT_BACKUP_VERSION=1 +set -e; case "$1" in + backup:export) + OUTPUT_FILE="$2" + BACKUP_DIR="$DOKKU_ROOT" + + BACKUP_TMP_DIR=$(mktemp -d) + BACKUP_TMP_FILE="$BACKUP_TMP_DIR/backup.tar" + + pluginhook backup-export 1 $BACKUP_DIR | tar -cf $BACKUP_TMP_FILE --files-from - + + pushd $BACKUP_DIR > /dev/null + ls -d */ | grep -oE '[^/]+' > "$BACKUP_TMP_DIR/.dokku_backup_apps" + popd > /dev/null + + # we want to insert the files in the root of the tar + pushd $BACKUP_TMP_DIR > /dev/null + echo $CURRENT_BACKUP_VERSION > .dokku_backup_version + tar --append -f $BACKUP_TMP_FILE .dokku_backup_version + tar --append -f $BACKUP_TMP_FILE .dokku_backup_apps + popd > /dev/null + + # if no file specified, output to stdout + if [[ -z $OUTPUT_FILE ]]; then + cat $BACKUP_TMP_FILE + else + mv $BACKUP_TMP_FILE $OUTPUT_FILE + fi + + rm -rf $BACKUP_TMP_DIR + ;; + + backup:import) + INPUT_FILE="$2" + [[ -z $INPUT_FILE ]] && INPUT_FILE="-" + + BACKUP_TMP_DIR=$(mktemp -d) + + tar xf $INPUT_FILE --directory=$BACKUP_TMP_DIR + + if [[ ! -f $BACKUP_TMP_DIR/.dokku_backup_version ]]; then + echo "Unable to determine backup version" + exit 1 + fi + + VERSION=$(< $BACKUP_TMP_DIR/.dokku_backup_version) + if [[ $VERSION -ne 1 ]]; then + echo "Unknown format version $VERSION" + exit 1 + fi + + BACKUP_ROOT="$BACKUP_TMP_DIR""$DOKKU_ROOT" + TARGET_DIR="$DOKKU_ROOT" + + # create all the app directories + while read app; do mkdir "$TARGET_DIR/$app"; done < $BACKUP_TMP_DIR/.dokku_backup_apps > /dev/null + + # have the plugins import their stuff + pluginhook backup-import $VERSION "$BACKUP_ROOT" $TARGET_DIR "$BACKUP_TMP_DIR/.dokku_backup_apps" + + rm -rf $BACKUP_TMP_DIR + ;; + + help) + cat && cat< /dev/null + PRERECEIVE_HOOK="$APP_PATH/hooks/pre-receive" + cat > $PRERECEIVE_HOOK < /dev/null diff --git a/plugins/nginx-vhosts/backup-export b/plugins/nginx-vhosts/backup-export new file mode 100755 index 000000000..e4dc88c8c --- /dev/null +++ b/plugins/nginx-vhosts/backup-export @@ -0,0 +1,5 @@ +#!/bin/bash +VERSION="$1" +BASE_DIR="$2" + +cat; find $BASE_DIR -regex ".*ssl/server\(.crt\|.key\)"; diff --git a/plugins/nginx-vhosts/backup-import b/plugins/nginx-vhosts/backup-import new file mode 100755 index 000000000..d31bb0b26 --- /dev/null +++ b/plugins/nginx-vhosts/backup-import @@ -0,0 +1,11 @@ +#!/bin/bash +VERSION="$1" +IMPORT_DIR="$2" +TARGET_DIR="$3" + +cd $IMPORT_DIR + +for file in `find . -regex ".*ssl/server\(.crt\|.key\)"`; do + mkdir -p $(dirname $TARGET_DIR$file) + cp $file $TARGET_DIR$file +done