Because of how plugin commands are implemented, their output can be incredibly verbose. Rather than executing even the `set -eo pipefail` parts of a plugin, we immediately check if the command is implemented by a plugin. If it is not, then we continue on as normal. One side-effect of this change is that plugin commands need to be duplicated again: - once in the command array - once for the actual body of the command - once in the help output This is also quite hackish, and probably not the best way to decrease trace output. Note that we drop approximately 2k lines worth of logs with this change.
97 lines
2.6 KiB
Bash
Executable File
97 lines
2.6 KiB
Bash
Executable File
#!/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 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
|