My Mastodon relocation adventure
Jul 25, 2025The time had finally come: Mastodon (Bare Metal) on my old Ubuntu 20 container could no longer be updated from 4.3.9 onwards. Ruby was too old, PostgreSQL was too old. So I moved the entire system.
Copying data from the old system to the new one:
systemctl stop mastodon *
su - mastodon
pg_dump --format=custom --no-acl --no-owner --clean mastodon_production > mastodon_production.dump
scp mastodon_production.dump $new_host:
scp -r live/public/system $new_host:
shutdown -h now
The new system is Alpine Linux with Docker Compose:
cd /opt
git clone https://github.com/mastodon/mastodon live
cd live
git checkout v4.3.9
cp .env.production.sample .env.production
docker compose run --rm web bundle exec rake mastodon:setup
Fill the .env.production file with the generated values, then continue with the database and the data:
docker compose exec -ti db /bin/bash
su - postgres
psql
\c postgres
drop schema public;
create schema public;
grant all on schema public to postgres;
grant all on schema public to public;
\q
exit
exit
docker exec -i mastodon-db-1 pg_restore -U postgres -v --clean --no-acl --no-owner -d postgres < /root/mastodon_production.dump
mv /root/system public/
chown -R 991:991 public
docker compose up -d
Switch server in Nginx proxy, done.
Backā¦