Migrate Mastodon from Masto.Host to Another Host via Cloudron
Intro
Wow, it’s been quite some time since I posted on my blog. Some stuff happened, and I’ll try to find time to write about it in the coming days. But right now, in the spirit of end-of-the-year cleaning (is that a thing?), I decided to spend some time to reduce some of my subscriptions. I won’t go into the details of the other services I’ve axed, but this post is focused on my personal Mastodon instance.
I’ve been hosting cdrum.social on Masto.Host for a while - I have nothing but respect for the service and the folks who run it. But, I need to cut some costs. I also have a cloud instance (VPS) where I host cdrum.photos (and frankly, I’m not sure about the future of that, since I’ve been using Instagram a bit more lately), and that instance is definitely underutilized. So I figured I’d migrate my Mastodon service over to that VPS.
This blog post details the process I took.
Migrating out of Masto.Host
Masto.Host makes it relatively easy to migrate out. Kudos to them!
From the console, navigate to Download Backup and scroll to the Generate a backup from live data section. You need to stop the server and request a new backup to make sure that you get everything, and that no data is lost from federation (if the server was still running). This means, downtime!.
Wait for it to shut down…
Now go back to the Backup section, and I opted to download only the media files I uploaded and not the cached files. I figured the cached files would be pulled later if I access those posts. I hope this was the right decision! 🤣
Luckily, this is a small backup in my case. When it’s done, you’ll get an email to download it.
Once it’s downloaded, now you can move onto the next step.
Migrating onto my Server - via Cloudron
I use Cloudron to manage the services on my dedicated vps.
On the Cloudron console, install Mastodon.
Select the correct domain you wish to host it on (make sure you add the domain to Cloudron - see Cloudron’s documentation) - and, make sure you update your domain’s DNS settings to point to the new host for the domain you chose!
Wait for it to install…
Then, connecting to the terminal of the Mastodon Application,
You can then uploaded the backup tar
you just downloaded from Masto.Host to the Mastodon container on the VPS managed by Cloudron into the /tmp
folder.
I untared the files in a new folder in /tmp
for easy access:
|
|
I then followed, largely, the instructions on Migrating Mastodon instances from Mastodon themselves: https://docs.joinmastodon.org/admin/migrating/.
Put the Cloudron Mastodon app in Repair mode to ensure the DB isn’t being written to.
Postgres DB
See https://docs.cloudron.io/guides/import-postgresql/ for Postgres-specific import instructions.
From the Cloudron Mastodon app Terminal (which we connected to above), do the following:
Clear out existing DB. (it was created for a fresh Mastodon installation):
|
|
Then restore the backup into the DB:
|
|
Secrets
Secrets from the old host are in the file secrets.txt
, specifically SECRET_KEY_BASE
, OTP_SECRET
, VAPID_PRIVATE_KEY
, and VAPID_PUBLIC_KEY
.
Copy all 4 into the /app/data/env.production
- I commented out the existing values in case.
Media Files
Media files from the backup are in the media/
folder. Move the media/*
folders to /app/data/system
, so now you have /app/data/system/media_attachments/
and /app/data/system/accounts/
.
Restart Mastodon
Back on Cloudron, disable recovery mode.
Access your Mastodon instance, and see if everything is working. I had lots of cached images broken (understandable considering I didn’t migrate the cache over). I refreshed with: /app/code/bin/tootctl account refresh --all
. This will take some time. You may need to adjust your ram settings, otherwise it may get killed.
Hope this helps some folks wanting to do what I just did!