Last active
October 18, 2024 03:26
-
-
Save kidGodzilla/92bfeb3c96b12c8c266f307052b55b9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
} | |
backup_storage_locations() { | |
cd /var/lib/dokku/data/storage | |
if ls -d */ > /dev/null 2>&1; then | |
echo "##############################" | |
echo "# Persistent Storage" | |
echo "##############################" | |
for d in */ ; do | |
appname=$(echo "$d" | sed 's:/*$::') | |
echo "sudo dokku storage:mount $appname /var/lib/dokku/data/storage/$appname:/storage" | |
done | |
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 "" | |
# nw_strr="${strr//$'\n'/ }" | |
# value=`cat config.txt` | |
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 "" | |
report=$(dokku resource:report "$appname") | |
current_cpu=$(echo "$report" | grep '_default_ limit cpu' | awk '{print $4}') | |
current_memory=$(echo "$report" | grep '_default_ limit memory' | awk '{print $4}') | |
echo "sudo dokku resource:limit --memory $current_memory --cpu $current_cpu $appname" | |
echo "" | |
# echo "$domains" | |
# echo "$env" | |
done | |
} | |
check_root | |
make_backups | |
backup_storage_locations |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.