Introduce backup plugin to export/import settings

This commit is contained in:
Alexander
2013-10-26 23:46:38 +02:00
parent 59ef6510bc
commit 8981b9e613
7 changed files with 128 additions and 0 deletions

View File

@@ -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"

View File

@@ -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

77
plugins/backup/commands Executable file
View File

@@ -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<<EOF
backup:export [file] Export dokku configuration files
backup:import [file] Import dokku configuration files
EOF
;;
esac
cat

5
plugins/config/backup-export Executable file
View File

@@ -0,0 +1,5 @@
#!/bin/bash
VERSION="$1"
BASE_DIR="$2"
cat; find $BASE_DIR -regex ".*/ENV"

9
plugins/config/backup-import Executable file
View File

@@ -0,0 +1,9 @@
#!/bin/bash
VERSION="$1"
IMPORT_DIR="$2"
TARGET_DIR="$3"
cd $IMPORT_DIR
for file in `find . -regex ".*/ENV"`; do
cp $file $TARGET_DIR$file
done

View File

@@ -0,0 +1,5 @@
#!/bin/bash
VERSION="$1"
BASE_DIR="$2"
cat; find $BASE_DIR -regex ".*ssl/server\(.crt\|.key\)";

View File

@@ -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