dokku-sync/dokku-sync.sh
2024-07-10 16:02:16 +02:00

54 lines
1.4 KiB
Bash

#!/bin/sh
# vim: set ts=2 sw=2 et:
set -e
set -u
LOCAL="danaos.infra.glenux.net"
REMOTE="dinlas.infra.glenux.net"
SSH_REMOTE="root@$REMOTE"
SSH_KEY="$HOME/.ssh/dinlas-to-danaos_rsync2022_ed25519"
sshrun() {
ssh -i "$SSH_KEY" root@dinlas.infra.glenux.net "$*"
}
# mkdir -p /srv/backup
# APPS=$ (sshrun "dokku ls" |awk '/^[^--]/ { print $1; }')
# Stop all remote services
sshrun "dokku ps:stop --all"
sshrun "dokku mariadb:list |tail -n+2 |xargs -iSERVICE -- dokku mariadb:stop SERVICE"
sshrun "dokku postgres:list |tail -n+2 |xargs -iSERVICE -- dokku postgres:stop SERVICE"
sshrun "dokku redis:list |tail -n+2 |xargs -iSERVICE -- dokku redis:stop SERVICE"
sshrun "dokku mongo:list |tail -n+2 |xargs -iSERVICE -- dokku mongo:stop SERVICE"
sshrun "systemctl stop docker"
sshrun "systemctl stop docker.socket"
# Stop all local services
dokku ps:stop --all
systemctl stop docker
systemctl stop docker.socket
# Copy all data
mkdir -p /home/dokku/
mkdir -p /home/data/
mkdir -p /var/lib/dokku/
rsync -avz --delete "$SSH_REMOTE:/home/dokku/" /home/dokku/
rsync -avz --delete "$SSH_REMOTE:/var/lib/dokku/" /var/lib/dokku/
rsync -avz --delete "$SSH_REMOTE:/home/data/" /home/data/
rsync -avz --delete "$SSH_REMOTE:/home/git/" /home/git/
# Start all local services
dokku apps:list
# Patch URLs from imported domains
find /home/dokku/ -name VHOST -or -name URLS \
| xargs -iFILE -- \
sed -i "s/$REMOTE/$LOCAL/g" FILE
echo "SUCCESS"