Merge pull request #1687 from u2mejc/u2mejc-nobackup

Deprecate and remove dokku backup plugin, replace with documentation.
This commit is contained in:
Jose Diaz-Gonzalez
2016-03-02 19:29:07 -05:00
20 changed files with 48 additions and 300 deletions

View File

@@ -54,7 +54,7 @@ if [[ ! -z $DOKKU_HOST ]]; then
if [[ "$appname" != "" ]] && [[ -n "$*" ]]; then
case "$1" in
apps|backup*|help|plugins*|ps:restartall|trace|version)
apps|help|plugins*|ps:restartall|trace|version)
true
;;
apps:destroy)

45
docs/backup-recovery.md Normal file
View File

@@ -0,0 +1,45 @@
# Backup and Recovery
> The backup plugin was deprecated in 0.4.x, below are backup recommendations for 0.5.x and later.
## Backup and Migration Tutorial
Because Dokku is git based, rebuilding a deployed app is as easy as pushing from git. You can push to a new server by updating the dokku remote in you local app's repo.
```
$ git remote rm dokku
$ git remote add dokku dokku@[dokku.me:dokku.me]
$ git push dokku [master]
```
## Databases
Some plugins, like the official [dokku-postgres] plugin, have built-in commands that allow non-volatile data be exported and imported.
For [dokku-postgres], use:
```
dokku postgres:export [db_name] > [db_name].dump
dokku postgres:import [db_name] < [db_name].dump
```
## Volumes and Static Assets
Dokku doesn't enforce a [300mb] limit on apps, but it's best practice to keep binary assets outside of git. Since containers are considered volatile in Dokku, external stores like s3 or storage mounts should be used for non-volatile items like user uploads. The dokku storage core plugin can be used to mount local directories / volumes inside the docker container.
```
storage:list <app>, List bind mounts for app's container(s) (host:container)
storage:mount <app> <host-dir:container-dir>, Create a new bind mount
storage:unmount <app> <host-dir:container-dir>, Remove an existing bind mount
```
## Disaster Recovery
The best plan for disaster recovery is to always keep multiple (remote) copies of your local repo, static assets and periodic database dumps. In case of an emergency when your git repo and backups are completely lost, you can recover the last pushed copy from your remote dokku server (assuming you still have the ssh key).
```
mkdir [app-name] ; cd !$
git init && git remote add dokku dokku@[dokku.me:app-name]
git pull dokku/master && git checkout dokku/master
```
[dokku-postgres]: <https://github.com/dokku/dokku-postgres>
[300mb]: <https://devcenter.heroku.com/articles/slug-compiler#slug-size>

View File

@@ -23,7 +23,7 @@ echo "$NEW_SUBDOMAIN.$VHOST"
## Available plugin triggers
There are a number of plugin-related triggers. These can be optionally implemented by plugins and allow integration into the standard dokku setup/backup/teardown process.
There are a number of plugin-related triggers. These can be optionally implemented by plugins and allow integration into the standard dokku setup/teardown process.
The following plugin triggers describe those available to a dokku installation. As well, there is an example for each trigger that you can use as templates for your own plugin development.
@@ -120,67 +120,6 @@ EOF
esac
```
### `backup-export`
- Description: Used to backup files for a given plugin. If your plugin writes files to disk, this plugin trigger should be used to echo out their full paths. Any files listed will be copied by the backup plugin to the backup tar.gz.
- Invoked by: `dokku backup:export`
- Arguments: `$VERSION $DOKKU_ROOT`
- Example:
```shell
#!/usr/bin/env bash
# Echos out the location of every `REDIRECT` file
# that are used by the apps
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
shopt -s nullglob
VERSION="$1"
DOKKU_ROOT="$2"
cat; for i in $DOKKU_ROOT/*/REDIRECT; do echo $i; done
```
### `backup-check`
- Description: Checks that a backup being imported passes sanity checks.
- Invoked by: `dokku backup:import`
- Arguments: `$VERSION $BACKUP_ROOT $DOKKU_ROOT $BACKUP_TMP_DIR/.dokku_backup_apps`
- Example:
```shell
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
# TODO
```
### `backup-import`
- Description: Allows a plugin to import specific files from a `$BACKUP_ROOT` to the `DOKKU_ROOT` directory.
- Invoked by: `dokku backup:import`
- Arguments: `$VERSION $BACKUP_ROOT $DOKKU_ROOT $BACKUP_TMP_DIR/.dokku_backup_apps`
- Example:
```shell
#!/usr/bin/env bash
# Copies all redirect files from the backup
# into the correct app path.
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
shopt -s nullglob
VERSION="$1"
BACKUP_ROOT="$2"
DOKKU_ROOT="$3"
cd $BACKUP_ROOT
for file in */REDIRECT; do
cp $file "$DOKKU_ROOT/$file"
done
```
### `pre-build-buildpack`
- Description: Allows you to run commands before the build image is created for a given app. For instance, this can be useful to add env vars to your container. Only applies to applications using buildpacks.

View File

@@ -44,7 +44,6 @@ Jul 3 16:30:02 dokku.me dokku[131384]: INVOKED: docker-args-run( rubyapp )
You can list all events that are currently being recorded via `dokku events:list`:
```
=====> Events currently logged
backup-check
docker-args-build
pre-delete
post-deploy
@@ -56,8 +55,6 @@ post-build-buildpack
post-domains-update
post-release-dockerfile
check-deploy
backup-import
backup-export
git-pre-pull
git-post-pull
nginx-hostname

View File

@@ -83,6 +83,7 @@
<a href="/dokku/docker-options/" class="list-group-item">Docker Container Options</a>
<a href="/dokku/dokku-storage/" class="list-group-item">Storage Plugin</a>
<a href="/dokku/dokku-events-logs/" class="list-group-item">Dokku Event Logs</a>
<a href="/dokku/backup-recovery/" class="list-group-item">Backup and Recovery</a>
<a href="#" class="list-group-item disabled">Community Contributions</a>

View File

@@ -1,18 +0,0 @@
#!/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

View File

@@ -1,11 +0,0 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
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"

View File

@@ -1,16 +0,0 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
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 -p "$TARGET_DIR/.ssh"
cat "$IMPORT_DIR/.ssh/authorized_keys" "$TARGET_DIR/.ssh/authorized_keys" | uniq > tmpfile && mv tmpfile "$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"

View File

@@ -1 +0,0 @@
hook

View File

@@ -1 +0,0 @@
hook

View File

@@ -1 +0,0 @@
hook

View File

@@ -1,96 +0,0 @@
#!/usr/bin/env bash
[[ " backup:export backup:import help backup:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT"
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
case "$1" in
backup:export)
CURRENT_BACKUP_VERSION=1
OUTPUT_FILE="$2"
BACKUP_DIR="$DOKKU_ROOT"
BACKUP_TMP_DIR=$(mktemp -d)
BACKUP_TMP_FILE="$BACKUP_TMP_DIR/backup.tar"
: | plugn trigger backup-export 1 "$BACKUP_DIR" | tar -cf "$BACKUP_TMP_FILE" --files-from -
pushd "$BACKUP_DIR" > /dev/null
find . -maxdepth 1 -type d -not -name . | sed 's:./::g' > "$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)
if [[ $2 == "-f" ]]; then
force=true
shift
else
force=false
fi
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
dokku_log_fail "Unable to determine backup version"
fi
VERSION=$(< "$BACKUP_TMP_DIR/.dokku_backup_version")
if [[ $VERSION -ne 1 ]]; then
dokku_log_fail "Unknown format version $VERSION"
fi
echo "Importing a version $VERSION backup..."
BACKUP_ROOT="$BACKUP_TMP_DIR""$DOKKU_ROOT"
TARGET_DIR="$DOKKU_ROOT"
if ! plugn trigger backup-check "$VERSION" "$BACKUP_ROOT" "$TARGET_DIR" "$BACKUP_TMP_DIR/.dokku_backup_apps"; then
if $force; then
echo "-f used. Ignoring warnings."
else
dokku_log_fail "Archive did not pass sanity checks. Use -f to import anyway"
fi
fi
# create all the app directories
while read -r app; do mkdir "$TARGET_DIR/$app"; echo "Imported $app"; done < "$BACKUP_TMP_DIR/.dokku_backup_apps"
# have the plugins import their stuff
plugn trigger backup-import "$VERSION" "$BACKUP_ROOT" "$TARGET_DIR" "$BACKUP_TMP_DIR/.dokku_backup_apps"
rm -rf "$BACKUP_TMP_DIR"
echo "Import complete."
;;
help | backup:help)
cat<<EOF
backup:export [file], Export dokku configuration files
backup:import [file], Import dokku configuration files
EOF
;;
*)
exit "$DOKKU_NOT_IMPLEMENTED_EXIT"
;;
esac

View File

@@ -1,4 +0,0 @@
[plugin]
description = "dokku core backup plugin"
version = "0.4.0"
[plugin.config]

View File

@@ -1,8 +0,0 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
shopt -s nullglob
VERSION="$1"
BASE_DIR="$2"
cat; for i in $BASE_DIR/*/ENV; do echo "$i"; done

View File

@@ -1,12 +0,0 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
shopt -s nullglob
VERSION="$1"
IMPORT_DIR="$2"
TARGET_DIR="$3"
cd "$IMPORT_DIR"
for file in */ENV; do
cp "$file" "$TARGET_DIR/$file"
done

View File

@@ -1,9 +0,0 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
shopt -s nullglob
VERSION="$1"
BASE_DIR="$2"
cat; for i in $BASE_DIR/*/VHOST; do echo "$i"; done
cat; for i in $BASE_DIR/*/nginx.conf.template; do echo "$i"; done

View File

@@ -1,15 +0,0 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
shopt -s nullglob
VERSION="$1"
IMPORT_DIR="$2"
TARGET_DIR="$3"
cd "$IMPORT_DIR"
for file in */VHOST; do
cp "$file" "$TARGET_DIR/$file"
done
for file in */nginx.conf.template; do
cp "$file" "$TARGET_DIR/$file"
done

View File

@@ -1,20 +0,0 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
VERSION="$1"
IMPORT_DIR="$2"
TARGET_DIR="$3"
APPS="$4"
while read -r APP; do
APP_PATH="$TARGET_DIR/$APP";
git init --bare "$APP_PATH" > /dev/null
PRERECEIVE_HOOK="$APP_PATH/hooks/pre-receive"
cat > "$PRERECEIVE_HOOK" <<EOF
#!/usr/bin/env bash
set -e; set -o pipefail;
cat | DOKKU_ROOT="$DOKKU_ROOT" dokku git-hook "$APP"
EOF
chmod +x "$PRERECEIVE_HOOK"
done < "$APPS" > /dev/null

View File

@@ -1,8 +0,0 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
shopt -s nullglob
VERSION="$1"
BASE_DIR="$2"
cat; for i in $BASE_DIR/*/tls/server.*; do echo "$i"; done

View File

@@ -1,14 +0,0 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
shopt -s nullglob
VERSION="$1"
IMPORT_DIR="$2"
TARGET_DIR="$3"
cd "$IMPORT_DIR"
for file in */tls/server.*; do
mkdir -p "$(dirname "$TARGET_DIR$file")"
cp "$file" "$TARGET_DIR$file"
done