WIP: Prebuilt docker image #803
2 changed files with 43 additions and 12 deletions
|
@ -3,8 +3,6 @@ services:
|
||||||
image: postgres:16-alpine
|
image: postgres:16-alpine
|
||||||
shm_size: 4gb
|
shm_size: 4gb
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
env_file:
|
|
||||||
- .env
|
|
||||||
environment: {
|
environment: {
|
||||||
# This might seem insecure but is usually not a problem.
|
# This might seem insecure but is usually not a problem.
|
||||||
# You should leave this at the "akkoma" default.
|
# You should leave this at the "akkoma" default.
|
||||||
|
@ -24,8 +22,6 @@ services:
|
||||||
akkoma:
|
akkoma:
|
||||||
image: akkoma/akkoma:latest
|
image: akkoma/akkoma:latest
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
env_file:
|
|
||||||
- .env
|
|
||||||
links:
|
links:
|
||||||
- db
|
- db
|
||||||
ports: [
|
ports: [
|
||||||
|
|
|
@ -14,32 +14,67 @@ fi
|
||||||
data_directory=$1
|
data_directory=$1
|
||||||
old_version=$2
|
old_version=$2
|
||||||
new_version=$3
|
new_version=$3
|
||||||
|
new_data_directory=$data_directory.new
|
||||||
|
|
||||||
|
# we'll need the credentials to create the new container
|
||||||
|
echo "Please provide the credentials for your database"
|
||||||
|
echo "If you set a different password for the old container, you'll need to provide it here! Check your config file if you're not sure"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "Database user (default 'akkoma'):"
|
||||||
|
read DB_USER
|
||||||
|
echo "Database password (default: 'akkoma'):"
|
||||||
|
read DB_PASS
|
||||||
|
echo "Database name (default: 'akkoma'):"
|
||||||
|
read DB_NAME
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "Ok! Using user:$DB_USER to migrate db:$DB_NAME from version $old_version to $new_version"
|
||||||
|
|
||||||
|
trap "docker stop pg$old_version pg$new_version" INT TERM
|
||||||
|
|
||||||
# Start a PostgreSQL 14 container
|
# Start a PostgreSQL 14 container
|
||||||
docker run --rm -d --name pg14 -v $(pwd)/$data_directory:/var/lib/postgresql/data -e "POSTGRES_PASSWORD=password" postgres:$old_version-alpine
|
docker run --rm -d --name pg$old_version \
|
||||||
|
-v $(pwd)/$data_directory:/var/lib/postgresql/data \
|
||||||
|
-e "POSTGRES_PASSWORD=$DB_PASS" \
|
||||||
|
-e "POSTGRES_USER=$DB_USER" \
|
||||||
|
-e "POSTGRES_DB=$DB_NAME" \
|
||||||
|
postgres:$old_version-alpine
|
||||||
|
|
||||||
# wait a bit for the container to start
|
# wait a bit for the container to start
|
||||||
sleep 10
|
sleep 10
|
||||||
|
|
||||||
# Dump the db from the old container
|
# Dump the db from the old container
|
||||||
docker exec pg14 pg_dumpall -U postgres > dump.sql
|
echo "Dumping your old database..."
|
||||||
|
|
||||||
|
docker exec pg$old_version pg_dumpall -U $DB_USER > dump.sql
|
||||||
|
|
||||||
# Stop the old container
|
# Stop the old container
|
||||||
docker stop pg14
|
echo "Stopping the old database..."
|
||||||
|
docker stop pg$old_version
|
||||||
|
|
||||||
# Start a PostgreSQL 16 container
|
# Start a PostgreSQL 16 container
|
||||||
docker run --rm -d --name pg16 -v $(pwd)/$data_directory.new:/var/lib/postgresql/data -e "POSTGRES_PASSWORD=password" postgres:$new_version-alpine
|
echo "Creating a new database with version $new_version..."
|
||||||
|
docker run --rm -d --name pg$new_version \
|
||||||
|
-v $(pwd)/$new_data_directory:/var/lib/postgresql/data \
|
||||||
|
-e "POSTGRES_PASSWORD=password" \
|
||||||
|
-e "POSTGRES_USER=$DB_USER" \
|
||||||
|
-e "POSTGRES_DB=$DB_NAME" \
|
||||||
|
postgres:$new_version-alpine
|
||||||
|
|
||||||
|
# wait for it
|
||||||
|
sleep 10
|
||||||
|
|
||||||
# Load the db into the new container
|
# Load the db into the new container
|
||||||
docker exec -i pg16 psql -U postgres < dump.sql
|
docker exec -i pg$new_version psql -U $DB_USER < dump.sql
|
||||||
|
|
||||||
# Stop the new container
|
# Stop the new container
|
||||||
docker stop pg16
|
docker stop pg$new_version
|
||||||
|
|
||||||
# Remove the dump file
|
# Remove the dump file
|
||||||
rm dump.sql
|
# rm dump.sql
|
||||||
|
|
||||||
echo "Migration complete! Your new database folder is $data_directory.new - you can now move your old data and replace it"
|
echo "Migration complete! Your new database folder is $data_directory.new - you can now move your old data and replace it"
|
||||||
|
|
||||||
echo "mv $data_directory $data_directory.old"
|
echo "mv $data_directory $data_directory.old"
|
||||||
echo "mv $data_directory.new $data_directory"
|
echo "mv $new_data_directory $data_directory"
|
Loading…
Reference in a new issue