Migrating my VPS

Just some small notes how I migrated my services from my Ubuntu 20.04 to 24.04 VPS with Docker

Migrating my VPS

This blog started on a VPS on Hetzner Cloud on the 16.06.2021. Yes, that is one of two ways to write dates. The other is reverse 2021-06-21. ๐Ÿ˜‰

Aaaanyway...

It has been rock solid. But all things have to come to an end. This machine was still running Ubuntu 20.04 given the provisioning date. I still had time up to 23.04.2025 because that is the EOL date and it would not get any more security updates. But I rather do it now than later. Also, I wanted to change a couple of things.

The migration

Honestly, it was nothing big-brain because I am okay with a couple of seconds of downtime.

Create a maintenance page

First: I spun up a static website that just showed something like: I am doing maintenance, be patient, and configured Caddy to serve this instead of my blog and a couple of other services I have running here.

Shutdown docker containers

Second: docker compose down for the blog and the services, I was moving. I have one folder for each service. One for my blog, another blog, analytics, etc. I did this one by one, finishing one and then moving to the next service. Why did I bring down the service? Because I want the database and filesystems of each service to be in a clean state to migrate.

The app was down and now there was no possibility to handle new requests. Now I needed to copy the data to the new server. So I created a tar.gz of that said folder and copied the data, right? Unfortunately, I did use docker volumes. Something I do not do anymore on my local server.

Me looking at docker volumes

Before creating that tar.gz file I first had to move the data from the volumes in /var/lib/docker/volumes to the folder of each service. The problem with docker volumes is, that you can not just copy over the data in /var/lib/docker/volumes to the next host. Docker has some kind of metadata in there and would not see those volumes. That is why I am not a fan of docker volumes.

โ“
Does anyone have an idea why docker volumes exist? I think they are almost useless.

Depending on the service it was mostly one database and a folder for files I had to move. I created a database and sometimes a data folder for the application and moved the data from the docker volumes to the respective database or data folder.

Now I could pack up the data and rsync the data to the new VM. A tip. You can use ssh -A on the first server to enable forwarding of your ssh-agent. Then you can use a command like rsync -a app.tgz name@IP:/home/name/docker/ to move the data to the new VM.

Start the services

Second to last step. Unarchive everything, docker compose up -d and I was good to go.

Switch DNS

On my original server, I still had the maintenance page up. Now I needed to update my DNS records to use the new IP. DNS TTL was as low as possible but DNS propagation is always tricky.

So people who got the new IP could reach my blog again and people who had the old IP just saw the static maintenance page.

What about you?

How do you host, upgrade and migrate your services on a VPS?

I am curious how you guys and gals are handling your services.

Last Words

How am I doing?

I love hearing from readers, and I am always looking for feedback. Is there anything you would like to read more or less of? You can just click on the ๐Ÿ‘ or ๐Ÿ‘Ž down below. What do you enjoy most about the newsletter, just let me know in the comments.

Have a great day! ๐Ÿ‘‹