Moved repositories and databases to local directory
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
project_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||
|
||||
find_legacy_volume() {
|
||||
volume_label=$1
|
||||
paired_label=$2
|
||||
volumes=$(docker volume ls -q --filter "label=com.docker.compose.volume=$volume_label")
|
||||
|
||||
if [ -z "$volumes" ]; then
|
||||
echo "No legacy '$volume_label' Docker volume was found." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
matching_volumes=''
|
||||
for volume in $volumes; do
|
||||
project=$(docker volume inspect --format '{{ index .Labels "com.docker.compose.project" }}' "$volume")
|
||||
paired_volume=$(docker volume ls -q \
|
||||
--filter "label=com.docker.compose.project=$project" \
|
||||
--filter "label=com.docker.compose.volume=$paired_label")
|
||||
if [ -n "$paired_volume" ]; then
|
||||
matching_volumes="$matching_volumes $volume"
|
||||
fi
|
||||
done
|
||||
|
||||
set -- $matching_volumes
|
||||
if [ "$#" -ne 1 ]; then
|
||||
echo "Could not identify one '$volume_label' volume paired with the legacy '$paired_label' volume." >&2
|
||||
echo "Set LEGACY_GITEA_VOLUME and LEGACY_POSTGRES_VOLUME explicitly and rerun." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf '%s\n' "$1"
|
||||
}
|
||||
|
||||
gitea_volume=${LEGACY_GITEA_VOLUME:-$(find_legacy_volume gitea_data postgres_data)}
|
||||
postgres_volume=${LEGACY_POSTGRES_VOLUME:-$(find_legacy_volume postgres_data gitea_data)}
|
||||
|
||||
for destination in "$project_dir/docker/gitea" "$project_dir/docker/postgres"; do
|
||||
mkdir -p "$destination"
|
||||
if [ -n "$(find "$destination" -mindepth 1 -print -quit)" ]; then
|
||||
echo "Migration destination '$destination' is not empty; refusing to overwrite data." >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
docker compose down
|
||||
|
||||
docker run --rm \
|
||||
--volume "$gitea_volume:/source/gitea:ro" \
|
||||
--volume "$postgres_volume:/source/postgres:ro" \
|
||||
--volume "$project_dir/docker:/destination" \
|
||||
alpine:3.21 sh -ec '
|
||||
cp -a /source/gitea/. /destination/gitea/
|
||||
cp -a /source/postgres/. /destination/postgres/
|
||||
'
|
||||
|
||||
echo "Migration complete. Start the server with: docker compose up -d"
|
||||
Reference in New Issue
Block a user