Skip to content

Instantly share code, notes, and snippets.

@lilianalillyy
Last active December 26, 2024 22:13
Show Gist options
  • Save lilianalillyy/22af55f2ed40f280aa12ff6a9bb0471f to your computer and use it in GitHub Desktop.
Save lilianalillyy/22af55f2ed40f280aa12ff6a9bb0471f to your computer and use it in GitHub Desktop.
Plausible 2.0->2.1 transition and moving to new server

Moving Plausible to a new server + 2.1 upgrade

This is the summary of steps I've taken when migrating my Plausible 2.0 instance to a new server and then upgrading it to 2.1.

On the old server

  1. Shutdown Postgres & Clickhouse before backup
docker compose down plausible_db
docker compose down plausible_events_db
  1. Backup docker volumes
docker run -v plausible_event-data:/volume --rm loomchild/volume-backup backup - > plausible_event-data.tar.bz2
docker run -v plausible_db-data:/volume --rm loomchild/volume-backup backup - > plausible_db-data.tar.bz2
  1. Backup plausible
zip -r /home/plausible plausible.zip

Then upload the backup to the new server and extract it.

On the new server

  1. Install Docker
  2. First run that creates volumes on new server
docker compose up -d && docker compose down
  1. Restore volumes
docker run -i -v plausible_event-data:/volume --rm loomchild/volume-backup restore -f < plausible_event-data.tar.bz2
docker run -i -v plausible_db-data:/volume --rm loomchild/volume-backup restore -f < plausible_db-data.tar.bz2
  1. Run (without -d flag to see possible fuckups)
docker compose up
  1. Do a healthcheck by visiting the panel

Upgrade to 2.1

based on plausible/analytics#4125

Versions before upgrade:

  • upgrading from plausible/hosting 1d4f9e93c5d89efbaf68c1e5903f19792d703318
  • clickhouse 23.3.7.5-alpine
  • postgres 14-alpine
  • plausible/analytics 2.0
  1. Generate a new required TOTP_VAULT_KEY value if not present already
openssl rand -base64 32 # output is the generated value of TOTP_VALUE_KEY, add it to plausible-config.env
  1. Modify docker-compose.yml
plausible:
- image: plausible/analytics:v2.0.0
- command: sh -c "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate && /entrypoint.sh db init-admin && /entrypoint.sh run"
+ image: ghcr.io/plausible/community-edition:v2.1.0
+ command: sh -c "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate && /entrypoint.sh run"
  • If ClickHouse is on version 23+, don't upgrade yet, otherwise hope it works with:
plausible_events_db:
- image: clickhouse/clickhouse-server:22.6-alpine
+ image: clickhouse/clickhouse-server:24.3.3.102-alpine
  1. Restart Plausible
docker compose down && docker compose up -d

Optional: Upgrade to pg 16

based on https://github.com/plausible/community-edition/wiki/upgrade-postgresql

  1. Create a backup of the current database
docker compose stop plausible
docker compose exec plausible_db sh -c "pg_dump -U postgres plausible_db > plausible_db.bak"
docker compose cp plausible_db:plausible_db.bak plausible_db.bak
head plausible_db.bak
  1. Update the version in docker-compose.yml
  plausible_db:
-   image: postgres:12
+   image: postgres:16-alpine
  1. Remove old postgres container and volume
docker compose stop plausible plausible_db
docker compose rm plausible_db
docker volume rm plausible_db-data
  1. Launch new Postgres
docker compose up plausible_db -d
  1. Restore the backup
docker compose exec plausible_db createdb -U postgres plausible_db
docker compose cp plausible_db.bak plausible_db:plausible_db.bak
docker compose exec plausible_db sh -c "psql -U postgres -d plausible_db < plausible_db.bak"
  1. Start Plausible
docker compose up plausible -d

Optional: Migrate to new community-edition structure

  1. Get into clean git state
  • Copy plausible-conf.env to the side
  • If you have any changes against the origin, you must adapt them later on
  • git reset --hard
  1. Checkout to a new version
git remote set-url origin [email protected]:plausible/community-edition
git fetch
git checkout v2.1.4
  1. Configure
  • Copy old plausible-conf.env -> .env
  • Add HTTP_PORT TO .env: echo "HTTP_PORT=80" >> .env
  • Create compose.override.yml to expose Plausible on a specific port
services:
  plausible:
    ports:
      - <desired_port>:80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment