How to update Mastodon to a new version

Updating Mastodon and creating backups are important steps to ensure the security and stability of your instance. Here’s a comprehensive tutorial on how to update Mastodon, including making backups of the database and assets:

Note: Always perform updates on a test/staging instance before applying them to your live instance. This tutorial assumes you have some basic knowledge of the command line and server administration.

Click here for the backup steps. It basically comes down to a Database dump, a settings file backup and a Redis dump. If you wish to backup your assets like images and stuff (User-uploaded files), backup the folder named “public/system”. Keep in mind that this folder can be rather large. Actually, it can become rather massive.

After a good 90 minutes, I gave up on trying to show you how large the asset folder is. So beware if you are going to make a backup of it. Perhaps you can just skip the cache folder?

You can always check the folder size by using NCDU, for which you can find the manual here. Also, installations may vary, but this is an example of my instance.


Upgrade procedure.

  1. su - mastodon
  2. cd /home/mastodon/live
  3. git fetch --tags
  4. git checkout [type the most recent version here, starting with the letter v. For example; v4.0.1
    
    Command example: git checkout v4.0.1
  5. bundle install
  6. yarn install
  7. RAILS_ENV=production bundle exec rails db:migrate
  8. RAILS_ENV=production bundle exec rails assets:precompile
  9. reboot now

And that should be it!

If you don’t want to restart your server, use the following commands instead of “reboot now”:

  1. exit
  2. systemctl restart mastodon-sidekiq
  3. systemctl reload mastodon-web

    The reload operation is a zero-downtime restart, also called a “phased restart”. As such, Mastodon upgrades usually do not require any advance notice to users about planned downtime. In rare cases, you can use the restart operation instead, but there will be a (short) felt interruption of service for your users.

  4. The streaming API server is also updated and requires a restart; doing so will result in all connected clients being disconnected, which can increase the load on your server:
systemctl restart mastodon-streaming

Done!

Loading

Mastodon: Manual backups

Prepare the folder

  1. Log in as root
  2. cd /home/mastodon
  3. mkdir backups
  4. cd backups

Making the backup

  1. Database (two steps)
    su - mastodon
    pg_dump -U mastodon mastodon_production -F t > DATE_FILENAME.tar
  2. Settings file (two steps)
    exit
    cp /home/mastodon/live/.env.production /home/mastodon/backups/DATE_.env.production
  3. Redis
    cp /var/lib/redis/dump.rdb /home/live/backups/DATE_dump.rdb

If you wish to backup your assets like images and stuff (User-uploaded files), backup the folder named “public/system”. Keep in mind that this folder can be rather large. Actually, it can become rather massive.

Loading

Mastodon: “There are pending database migrations. Please run them to ensure the application behaves as expected”

“There are pending database migrations. Please run them to ensure the application behaves as expected” or “Niet alle databasemigraties zijn voltooid. Je moet deze uitvoeren om er voor te zorgen dat de applicatie blijft werken zoals het hoort” can be solved with the following command, executed as user mastodon:

1.
su - mastodon
2. 
cd live
3.
RAILS_ENV=production bundle exec rails db:migrate

results in:

Loading

Brutally brief: Create a new database and or user in MYSQL

Log in:

mysql -u root -p

Create a user:

create user 'newuser'@'localhost' IDENTIFIED BY 'password';

Give them all the power:

grant all privileges on * . * TO 'newuser'@'localhost';

Reload privileges:

flush privileges;

Ditch a user: (Optional)

drop user 'newuser'@'localhost';

Log out:

\q

—————-

Log in:

mysql -u newuser -p

Create a database for the user:

create database db_name;

List databases: (Optional)

show databases;

Ditch database: (Optional)

drop database db_name;

Log out:

\q

Done.

Loading