diff --git a/contrib/dokku_client.sh b/contrib/dokku_client.sh index af644a1a6..e86a6962d 100755 --- a/contrib/dokku_client.sh +++ b/contrib/dokku_client.sh @@ -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) diff --git a/docs/backup-recovery.md b/docs/backup-recovery.md new file mode 100644 index 000000000..593068fc1 --- /dev/null +++ b/docs/backup-recovery.md @@ -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 , List bind mounts for app's container(s) (host:container) +storage:mount , Create a new bind mount +storage:unmount , 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]: +[300mb]: diff --git a/docs/development/plugin-triggers.md b/docs/development/plugin-triggers.md index 643d9a72a..00eafa59d 100644 --- a/docs/development/plugin-triggers.md +++ b/docs/development/plugin-triggers.md @@ -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. diff --git a/docs/dokku-events-logs.md b/docs/dokku-events-logs.md index 6c9b5f1d2..c93d82a1e 100644 --- a/docs/dokku-events-logs.md +++ b/docs/dokku-events-logs.md @@ -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 diff --git a/docs/template.html b/docs/template.html index 9e4f485d5..32f5fcce6 100644 --- a/docs/template.html +++ b/docs/template.html @@ -82,6 +82,7 @@ SSL Configuration Docker Container Options Dokku Event Logs + Backup and Recovery Community Contributions diff --git a/plugins/00_dokku-standard/backup-check b/plugins/00_dokku-standard/backup-check deleted file mode 100755 index a86a7e157..000000000 --- a/plugins/00_dokku-standard/backup-check +++ /dev/null @@ -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 diff --git a/plugins/00_dokku-standard/backup-export b/plugins/00_dokku-standard/backup-export deleted file mode 100755 index 8a1fcf24c..000000000 --- a/plugins/00_dokku-standard/backup-export +++ /dev/null @@ -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" diff --git a/plugins/00_dokku-standard/backup-import b/plugins/00_dokku-standard/backup-import deleted file mode 100755 index 6f2af5fbd..000000000 --- a/plugins/00_dokku-standard/backup-import +++ /dev/null @@ -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" diff --git a/plugins/20_events/backup-check b/plugins/20_events/backup-check deleted file mode 120000 index 5178a749f..000000000 --- a/plugins/20_events/backup-check +++ /dev/null @@ -1 +0,0 @@ -hook \ No newline at end of file diff --git a/plugins/20_events/backup-export b/plugins/20_events/backup-export deleted file mode 120000 index 5178a749f..000000000 --- a/plugins/20_events/backup-export +++ /dev/null @@ -1 +0,0 @@ -hook \ No newline at end of file diff --git a/plugins/20_events/backup-import b/plugins/20_events/backup-import deleted file mode 120000 index 5178a749f..000000000 --- a/plugins/20_events/backup-import +++ /dev/null @@ -1 +0,0 @@ -hook \ No newline at end of file diff --git a/plugins/backup/commands b/plugins/backup/commands deleted file mode 100755 index 32f6ddba6..000000000 --- a/plugins/backup/commands +++ /dev/null @@ -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< /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 deleted file mode 100755 index a8ca36873..000000000 --- a/plugins/nginx-vhosts/backup-export +++ /dev/null @@ -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 diff --git a/plugins/nginx-vhosts/backup-import b/plugins/nginx-vhosts/backup-import deleted file mode 100755 index f8ca3a148..000000000 --- a/plugins/nginx-vhosts/backup-import +++ /dev/null @@ -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