1
0
mirror of https://yerbamate.ml/nutomic/peertube.social synced 2024-11-28 18:18:21 -05:00

Add migration script

This commit is contained in:
Felix Ableitner 2019-03-11 22:02:07 +01:00
parent 5a3c073def
commit 171620046d
2 changed files with 81 additions and 5 deletions

View File

@ -10,7 +10,7 @@ services:
- "443:443" # The HTTPS port
volumes:
- /var/run/docker.sock:/var/run/docker.sock # So that Traefik can listen to the Docker events
- ./docker-volume/traefik/acme.json:/etc/acme.json
- ./docker-volumes/traefik/acme.json:/etc/acme.json
- ./traefik.toml:/traefik.toml
restart: "always"
# If you want to use the Traefik dashboard, you should expose it on a
@ -27,8 +27,8 @@ services:
traefik.frontend.rule: "Host:${PEERTUBE_WEBSERVER_HOSTNAME}"
traefik.port: "9000"
volumes:
- ./docker-volume/data:/data
- ./docker-volume/config:/config
- ./docker-volumes/data:/data
- ./docker-volumes/config:/config
depends_on:
- postgres
- redis
@ -42,7 +42,7 @@ services:
POSTGRES_PASSWORD: ${PEERTUBE_DB_PASSWORD}
POSTGRES_DB: peertube
volumes:
- ./docker-volume/db:/var/lib/postgresql/data
- ./docker-volumes/db:/var/lib/postgresql/data
restart: "always"
labels:
traefik.enable: "false"
@ -50,7 +50,7 @@ services:
redis:
image: redis:5-alpine
volumes:
- ./docker-volume/redis:/data
- ./docker-volumes/redis:/data
restart: "always"
labels:
- "traefik.enable=false"

76
migration.sh Executable file
View File

@ -0,0 +1,76 @@
#!/bin/bash
set -e
DOMAIN="peertube.social"
OLD_SERVER="migration-user@$DOMAIN"
OLD_BASE_FOLDER="/var/www/peertube"
NEW_BASE_FOLDER="/peertube/docker-volumes"
RSYNC_PARAMS="-a --rsync-path=\"sudo rsync\" --bwlimit=5000"
function sync-volumes {
mkdir -p "$NEW_BASE_FOLDER"
mkdir -p "$NEW_BASE_FOLDER/data/"
rsync $RSYNC_PARAMS "$OLD_SERVER:$OLD_BASE_FOLDER/config/" "$NEW_BASE_FOLDER/config/"
rsync $RSYNC_PARAMS "$OLD_SERVER:$OLD_BASE_FOLDER/storage/avatars/" "$NEW_BASE_FOLDER/data/avatars/"
rsync $RSYNC_PARAMS "$OLD_SERVER:$OLD_BASE_FOLDER/storage/cache/" "$NEW_BASE_FOLDER/data/cache/"
rsync $RSYNC_PARAMS "$OLD_SERVER:$OLD_BASE_FOLDER/storage/captions/" "$NEW_BASE_FOLDER/data/captions/"
rsync $RSYNC_PARAMS "$OLD_SERVER:$OLD_BASE_FOLDER/storage/previews/" "$NEW_BASE_FOLDER/data/previews/"
rsync $RSYNC_PARAMS "$OLD_SERVER:$OLD_BASE_FOLDER/storage/thumbnails/" "$NEW_BASE_FOLDER/data/thumbnails/"
rsync $RSYNC_PARAMS "$OLD_SERVER:$OLD_BASE_FOLDER/storage/torrents/" "$NEW_BASE_FOLDER/data/torrents/"
# TODO: change folders in config/docker-compose
rsync $RSYNC_PARAMS "$OLD_SERVER:$OLD_BASE_FOLDER/storage/external/videos/" "/mnt/external/videos/"
rsync $RSYNC_PARAMS "$OLD_SERVER:$OLD_BASE_FOLDER/storage/external/redundancy/" "/mnt/external/redundancy/"
rsync $RSYNC_PARAMS "$OLD_SERVER:$OLD_BASE_FOLDER/storage/external/tmp/" "/mnt/external/tmp/"
}
if [ "$(whoami)" != "root" ]; then
echo "You need to run this script as root"
exit 1
fi
if [ "$(ssh "$OLD_SERVER" sudo whoami)" != "root" ]; then
echo "passwordless sudo needs to be available on $OLD_SERVER"
exit 1
fi
echo "Before running this script, ensure the following:
- this script is running on the new server (migration target)
- docker-compose based setup for peertube is already installed in /peertube/
- set reverse dns for new server to $DOMAIN
- set DNS TTL for $DOMAIN to the minimum possible value
- new external storage is mounted under /mnt/external/
- backups are in place and tested (ideally also of videos)
"
read -p "Continue? [y/N] " yn
if [ "$yn" != "y" ]; then
exit
fi
# remove any existing volume files
# https://stackoverflow.com/a/790245
rm -r "$NEW_BASE_FOLDER"/* | true
# dont delete this because it would take too long to sync
#rm -r "/mnt/external/*" | true
# copy volumes to local server
# we do this while the old server is still running to reduce downtime
sync-volumes
read -p "Initial copy complete. Do you want to complete the migration now? [y/N] " yn
if [ "$yn" != "y" ]; then
exit
fi
# shutdown peertube (it will keep seeding videos)
ssh $OLD_SERVER sudo systemctl stop peertube
# now that the old server is offline, we can do a final copy
sync-volumes
# TODO: also need to update domain in .env and traefik.toml (maybe with sed, or just set it before we migrate)
docker-compose -f "$NEW_BASE_FOLDER/docker-compose.yaml" up -d
echo "Now update the dns entries for $DOMAIN to point at the new server"