mirror of
https://github.com/dokku/dokku.git
synced 2026-02-24 04:00:36 +01:00
Plugins with commands will need to implement a catch-all command that exits with the `DOKKU_NOT_IMPLEMENTED_EXIT`` code (10). This signals to dokku that a given plugin has indeed not executed anything for a plugin (which may not always be the case). Using plugins that do not implement this pattern will result in those plugins silencing the error message.
100 lines
2.5 KiB
Bash
Executable File
100 lines
2.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
|
|
|
CURRENT_BACKUP_VERSION=1
|
|
|
|
case "$1" in
|
|
backup:export)
|
|
OUTPUT_FILE="$2"
|
|
BACKUP_DIR="$DOKKU_ROOT"
|
|
|
|
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 -
|
|
|
|
pushd $BACKUP_DIR > /dev/null
|
|
ls -d */ | grep -oE '[^/]+' > "$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
|
|
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
|
|
|
|
echo "Importing a version $VERSION backup..."
|
|
|
|
BACKUP_ROOT="$BACKUP_TMP_DIR""$DOKKU_ROOT"
|
|
TARGET_DIR="$DOKKU_ROOT"
|
|
|
|
if ! pluginhook backup-check $VERSION "$BACKUP_ROOT" "$TARGET_DIR" "$BACKUP_TMP_DIR/.dokku_backup_apps"; then
|
|
if $force; then
|
|
echo "-f used. Ignoring warnings."
|
|
else
|
|
echo "Archive did not pass sanity checks. Use -f to import anyway" >&2
|
|
exit 1
|
|
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
|
|
pluginhook 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 && cat<<EOF
|
|
backup:export [file] Export dokku configuration files
|
|
backup:import [file] Import dokku configuration files
|
|
EOF
|
|
;;
|
|
|
|
*)
|
|
exit $DOKKU_NOT_IMPLEMENTED_EXIT
|
|
;;
|
|
|
|
esac
|