How To Migrate Plausible Analytics From One Server To Another

No Comments

Do you want to migrate your Plausible Analytics from one server to another? In this post, I will show you how to do so without losing your data! For that, we will first look at some requirements and then I will show you everything step-by-step, with two different approaches!

Requirements

For the instructions in this post, there are some requirements. The first and most important one is that your current instance runs using Docker. The reason is that moving from one system to another should work seamlessly and I did not look at how to set plausible up without docker. The other requirements are:

That’s it, if these requirements are fulfilled I will show you how to migrate your current plausible analytics instance.

Only migrate Plausible Analytics data

Only migrating the data is my recommended way of migration, because the volumes of the database are really big, and takes a long time to create an archive of them and then move it to another host.

To get the data you should set up an automated backup mechanism that I explained in this post here. I would recommend setting it up on both hosts and after you finished come back here (The whole setup, so that you have a running plausible instance.)

In case you freshly set up the backup mechanism you should change the variable SCHEDULE of the pg-backup container to something like 0 * * * *. But instead of the 0, you change it to one minute ahead of your current time and also do the same for the cron file needed for the plausible_events_db container.

Doing this will create a backup of the current data and you can use this data for the migration.

Now let’s move the latest backups to the new host. The first folder you have to zip (zip -r events-db.zip <dirname>) can be found in the location of your plausible_events_db volumes. For me that is /var/docker/plausible/event-data/backup/ and the other one (already zipped) can be found in the location of your pg-backup volumes inside /var/docker/plausible/backup/postgres/last/ (for me).

Now move both of the files to new files using scp or an application like WinScp. After you moved the two files you have to import them into the two databases. For that follow the following steps:

Before these steps build all containers by running docker compose up -d plausible_db plausible_events_db plausible.

PostgreSQL

  1. check in the browser if everything works as expected (no websites there)
  2. move the backup file to the volume folder of plausible_db backups (for me /var/docker/plausible/backup/)
  3. docker exec -it plausible_db bash -c "zcat /var/lib/postgresql/backup/<backup-file>.sql.gz | psql --username=postgres --dbname=plausible_db -W"

Clickhouse

  1. check in the browser if everything works as expected (websites there, but no data)
  2. create a backup folder inside the event-data volume of the events-db container (for me: /var/docker/plausible/event-data)
  3. move the backup inside the new backup folder and unzip it (unzip events-db.zip)
  4. docker exec plausible_events_db bash -c "clickhouse-backup restore <backup-dir-name>"

With that, your data should be migrated from one host to another!

Migrate Plausible Analytics using Docker Volumes

Migrating Plausible Analytics by moving the volumes from one host to another is probably the simpler, but the more time-consuming method. The idea is that you first create a zip archive of the needed volumes of the container, then download these archives and place them in the needed location on the other host.

For example, in my instance, I would create an archive of the directory /var/docker/plausible and move it to the host also in the same directory /var/docker/plausible and then run docker compose up -d to create the container instances.

Conclusion

In this post, you learned how to migrate your Plausible Analytics instance from one host to another and I hope it worked flawlessly for you. If you have any questions feel free to send me an email or ask through the comments!

In case you liked this post consider subscribing to my newsletter to get monthly updates on all my posts!

Discussion (0)

Add Comment

Your email address will not be published. Required fields are marked *