diff --git a/plugins/00_dokku-standard/backup-export b/plugins/00_dokku-standard/backup-export new file mode 100755 index 000000000..58d4ac43c --- /dev/null +++ b/plugins/00_dokku-standard/backup-export @@ -0,0 +1,8 @@ +#!/bin/bash +VERSION="$1" +BASE_DIR="$2" + +cat; +[[ -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..2fa31c13f --- /dev/null +++ b/plugins/00_dokku-standard/backup-import @@ -0,0 +1,13 @@ +#!/bin/bash +VERSION="$1" +IMPORT_DIR="$2" +TARGET_DIR="$3" + +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..f0cbeb6ed --- /dev/null +++ b/plugins/backup/commands @@ -0,0 +1,77 @@ +#!/bin/bash +set -e; case "$1" in + backup:export) + OUTPUT_FILE="$2" + BACKUP_DIR=/home/git + + if [[ ! -f $BACKUP_DIR/.dokku_backup_version ]]; then + echo "Unable to determine backup version" + exit 1 + fi + + 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 - + + # we want to insert the version file in the root of the file + pushd $BACKUP_DIR > /dev/null + tar --append -f $BACKUP_TMP_FILE .dokku_backup_version + ls -d */ > "$BACKUP_TMP_DIR/.dokku_backup_apps" + popd > /dev/null + + # we want to insert the apps file in the root of the file + pushd $BACKUP_TMP_DIR > /dev/null + 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/home/git" + TARGET_DIR="/home/git" + + # create all the app repositories + while read app; do git init --bare "$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 + + rm -rf $BACKUP_TMP_DIR + ;; + + help) + cat && cat<