Skip to content

Instantly share code, notes, and snippets.

@kidGodzilla
Created April 10, 2024 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kidGodzilla/92bfeb3c96b12c8c266f307052b55b9c to your computer and use it in GitHub Desktop.
Save kidGodzilla/92bfeb3c96b12c8c266f307052b55b9c to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
######################################################################
# This simple backup script generates commands to recreate dokku apps
#
# It creates the app, adds domains, and restores configuration for each app
# It does not handle databases, persistent storage, or other plugin settings
#
# Usage: Run this script on a Dokku server (you must either be logged in as the
# dokku user, or root, or `sudo su` first.
#
# Then, save the ouput of this script to a file. That's your backup.
# You can restore to a fresh dokku server install by running the generated commands
#
# Note: you will need to add remotes and `git push dokku main:master` for each app
# you deploy to the new server
######################################################################
# See Comments in the related GitHub Gist below for usage instructions
######################################################################
# Ensure we are running as root
check_root() {
if [ "$USER" != "root" ]; then
echo "Permission Denied"
echo "Can only be run by root"
exit
fi
}
make_backups() {
cd /home/dokku
for d in */ ; do
appname=$(echo "$d" | sed 's:/*$::')
echo "##############################"
echo "# $appname"
echo "##############################"
echo ""
echo "sudo dokku apps:create $appname"
echo ""
domains=`cat "$d/VHOST"`
env=`cat "$d/ENV"`
domains="${domains//$'\n'/ }"
env="${env//$'\n'/ }"
echo "sudo dokku domains:add $appname $domains"
echo ""
echo "sudo dokku config:set $appname $env"
echo "sudo dokku config:unset $appname GIT_REV"
echo ""
done
}
check_root
make_backups
@kidGodzilla
Copy link
Author

kidGodzilla commented Apr 10, 2024

Usage

This simple backup script generates commands to recreate dokku apps.

It creates the app, adds domains, and restores configuration for each app.

It does not handle databases, persistent storage, or other plugin settings.

Usage: Run this script on a Dokku server (you must either be logged in as the
dokku user, or root, or sudo su first.

Then, save the ouput of this script to a file. That's your backup.
You can restore to a fresh dokku server install by running the generated commands.

Note: you will need to add remotes and git push dokku main:master for each app you deploy to the new server.

wget https://gist.githubusercontent.com/kidGodzilla/92bfeb3c96b12c8c266f307052b55b9c/raw/bf87b77d851c9baaaf2419862ef2e3b74daec61c/dokku_simple_backup.sh

bash ./dokku_simple_backup.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment