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 1: Always perform updates on a test/staging instance before applying them to your live instance. This tutorial assumes you have some basic command line and server administration knowledge.
Note 2: If you made alterations to your files and want to update to a new branch, like v4.2.0, don’t forget to stash your files first. DO THIS AT YOUR OWN RISK.
You will not have an error message any more when entering: I currently do not know how to put the stashed files back, this will be found out later.
git checkout v4.2.0
Note 3: If you switch to a new branch and version, like 4.2.0, you might run into an error stating the following:
rbenv: version '3.2.2' is not installed (set by /home/mastodon/live/.ruby-version)
Take the following steps to solve this problem: (Type the version you need where it says x.x.x)
rbenv install x.x.x
If that fails, try the following command:
brew update && brew upgrade ruby-build
Followed by: (Type the version you need where it says x.x.x)
rbenv install x.x.x
OPTIONAL: If bundler or rails fails to work, try the following commands:
gem install bundler
gem install rails
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.
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.
su - mastodon
git fetch --tags
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
If you don’t want to restart your server, use the following commands instead of “reboot now”:
systemctl restart mastodon-sidekiq
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.
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
PS: When I updated my instance from 4.1.9 to 4.2.0, a lot of warnings flew by, and this is, in my experience, not a problem as the instance is working perfectly.
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.