{"id":344,"date":"2021-03-10T00:59:28","date_gmt":"2021-03-09T23:59:28","guid":{"rendered":"https:\/\/vdna.be\/blog\/?p=344"},"modified":"2021-06-22T16:58:57","modified_gmt":"2021-06-22T15:58:57","slug":"upgrading-a-mastodon-instance","status":"publish","type":"post","link":"https:\/\/vdna.be\/site\/index.php\/2021\/03\/upgrading-a-mastodon-instance\/","title":{"rendered":"Upgrading your mastodon instance"},"content":{"rendered":"\n<p>As mastodon v3.3.0 has been released for over two months now, I figured it was time to upgrade my family instance from v3.2.1 to v3.3.0 (thereby skipping v3.2.2). <\/p>\n\n\n\n<p>I wrote about hosting your own instance, via <code>docker-compose<\/code>, in a <a href=\"https:\/\/vdna.be\/blog\/index.php\/2020\/11\/hosting-your-own-mastodon-instance-via-docker-compose\/\" data-type=\"post\" data-id=\"327\">previous post<\/a>. The past week I&#8217;ve been tinkering with mastodon development. <a href=\"https:\/\/github.com\/tootsuite\/mastodon\/issues\/15863\">Considering what a pain it has been to setup a local development environment<\/a>, I remain convinced that a containerized setup is the way to go for hosting mastodon. Let&#8217;s get started!<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">Documentation<\/h2>\n\n\n\n<p>Before starting the upgrade, I would suggest going through the documentation on &#8216;<a href=\"https:\/\/docs.joinmastodon.org\/admin\/upgrading\/\">Upgrading to a new release<\/a>&#8216; and through the <a href=\"https:\/\/github.com\/tootsuite\/mastodon\/releases\/tag\/v3.3.0\">v3.3.0 release notes<\/a>. Together with the notes here, you should be all set for a  successful upgrade.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Database backup<\/h2>\n\n\n\n<p>Prior to attempting an upgrade, you should ensure you have a recent backup of the mastodon database.  I used <code>pg_dumpall<\/code> inside the running postgres container (whose <code>docker-compose<\/code> service is named db) as follows: <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ndocker-compose exec db \/bin\/bash\npg_dumpall -U mastodon -f mastodon_db_pg_dumpall_output_20210309.sql\ntail mastodon_db_pg_dumpall_output_20210309.sql\n<\/pre><\/div>\n\n\n<p>If the backup was successful, tail should output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">--\n-- PostgreSQL database dump complete\n--\n-- PostgreSQL database cluster dump complete<\/pre>\n\n\n\n<p>Make sure you store the resulting sql file in a location that is persisted on the host system, so that the file isn&#8217;t lost when the container is shutdown and removed. In the container, I moved the backup file to <code>\/var\/lib\/postgresql\/data<\/code>, which is mounted on the host at <code>\/home\/mastodon\/mastodon\/postgres<\/code>. On the host I moved the file to <code>\/home\/mastodon<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Backup public\/system folder<\/h2>\n\n\n\n<p>While not necessary, you might want to backup the files under <code>mastodon\/public\/system<\/code>, e.g. excluding the cache folder  via<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ntar --exclude=public\/system\/cache -zcf mastodon_system_backup_20210309.tar.gz public\/system\/\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">Upgrading to new release<\/h2>\n\n\n\n<p>After completing the database backup, the steps necessary to upgrade to a new version are roughly as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Update your local copy of mastodon to  the latest release<\/li><li>Rebuild the container images<\/li><li>Apply pre-install  migrations of the mastodon database<\/li><li>Shutdown containers running old release of mastodon<\/li><li>Clear mastodon cache and finish DB migration<\/li><li>Start newly built containers<\/li><li>Prune old containers<\/li><\/ul>\n\n\n\n<p>In shell commands, make sure you point your working directory to the root folder of the mastodon repo:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ngit fetch --tags  # fetch all tags from the remote, leaving the working directory intact\ngit stash # stash any changes made to the working directory (typically only docker-compose.yml file)\ngit checkout v3.3.0  # checkout working directory to the v3.3.0 release\ngit stash pop # restore any changes you made to the working directory (i.e. passwords in docker-compose.yml files, verify via git diff)\ndocker-compose build  # build the web, streaming and sidekiq services, they all share the same container image. This may take a while.\ndocker images  # you should see the freshly build image at the top, something like: tootsuite\/mastodon   latest              aa82ba57a3f4        About a minute ago   1.98GB\ndocker-compose run --rm -e SKIP_POST_DEPLOYMENT_MIGRATIONS=true web rails db:migrate  # Run the pre-deployment database migrations\n# You can check the return code via echo $?, if the rc is zero than the migration was successful\ndocker-compose down # shutdown all docker-compose services\ndocker-compose run --rm web bin\/tootctl cache clear # clear cache\ndocker-compose run --rm web rails db:migrate # Run post-deployment database migrations, again verify that it succeeded via echo $?. 0 means success\ndocker-compose up -d  # create and start containers, detaching from their stdout\ndocker system prune -a # remove unused docker data (images, containers, volumes)\n<\/pre><\/div>\n\n\n<p>Verify that the containers are up and running via <code>docker-compose ps<\/code> and <code>docker ps<\/code>. You should see something like:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&#x5B;mastodon@sarch mastodon]$ docker-compose ps\n        Name                      Command                  State                     Ports               \n---------------------------------------------------------------------------------------------------------\nmastodon_db_1          docker-entrypoint.sh postgres    Up (healthy)                                     \nmastodon_redis_1       docker-entrypoint.sh redis ...   Up (healthy)                                     \nmastodon_sidekiq_1     \/tini -- bundle exec sidekiq     Up             3000\/tcp, 4000\/tcp                \nmastodon_streaming_1   \/tini -- node .\/streaming        Up (healthy)   3000\/tcp, 127.0.0.1:4000-&gt;4000\/tcp\nmastodon_web_1         \/tini -- bash -c rm -f \/ma ...   Up (healthy)   127.0.0.1:3000-&gt;3000\/tcp, 4000\/tcp\n&#x5B;mastodon@sarch mastodon]$ docker ps\nCONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS                   PORTS                                NAMES\n3f7ea048f4f7        tootsuite\/mastodon    &quot;\/tini -- bash -c &#039;r\u2026&quot;   4 minutes ago       Up 4 minutes (healthy)   127.0.0.1:3000-&gt;3000\/tcp, 4000\/tcp   mastodon_web_1\nc673502e6afa        tootsuite\/mastodon    &quot;\/tini -- node .\/str\u2026&quot;   4 minutes ago       Up 4 minutes (healthy)   3000\/tcp, 127.0.0.1:4000-&gt;4000\/tcp   mastodon_streaming_1\n1bba8a9e1934        tootsuite\/mastodon    &quot;\/tini -- bundle exe\u2026&quot;   4 minutes ago       Up 4 minutes             3000\/tcp, 4000\/tcp                   mastodon_sidekiq_1\n6c623213428d        redis:6.0-alpine      &quot;docker-entrypoint.s\u2026&quot;   7 minutes ago       Up 7 minutes (healthy)                                        mastodon_redis_1\nf65c1f822600        postgres:9.6-alpine   &quot;docker-entrypoint.s\u2026&quot;   7 minutes ago       Up 7 minutes (healthy)                                        mastodon_db_1\n<\/pre><\/div>\n\n\n<p>In case a container fails to start, you can troubleshoot using its logs via <code>docker-compose logs -ft &lt;service-name&gt;<\/code>. <\/p>\n\n\n\n<p>Finally, point your browser to your mastodon instance and rejoice! It should be listing  3.3.0 in the footer. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"286\" height=\"79\" src=\"https:\/\/vdna.be\/blog\/wp-content\/uploads\/2021\/03\/Screenshot-from-2021-03-10-00-56-27.png\" alt=\"\" class=\"wp-image-359\"\/><figcaption>Great success!<\/figcaption><\/figure><\/div>\n\n\n\n<p>As for new features in the 3.3.0 release, I hope to be exploring these in the coming weeks. Many thanks to everyone that contributed to the release!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As mastodon v3.3.0 has been released for over two months now, I figured it was time to upgrade my family instance from v3.2.1 to v3.3.0 (thereby skipping v3.2.2). I wrote about hosting your own instance, via docker-compose, in a previous post. The past week I&#8217;ve been tinkering with mastodon development. Considering what a pain it&hellip; <a class=\"more-link\" href=\"https:\/\/vdna.be\/site\/index.php\/2021\/03\/upgrading-a-mastodon-instance\/\">Continue reading <span class=\"screen-reader-text\">Upgrading your mastodon instance<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,4],"tags":[12,13],"class_list":["post-344","post","type-post","status-publish","format-standard","hentry","category-linux","category-software","tag-linux","tag-software","entry"],"_links":{"self":[{"href":"https:\/\/vdna.be\/site\/index.php\/wp-json\/wp\/v2\/posts\/344","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vdna.be\/site\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vdna.be\/site\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vdna.be\/site\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vdna.be\/site\/index.php\/wp-json\/wp\/v2\/comments?post=344"}],"version-history":[{"count":20,"href":"https:\/\/vdna.be\/site\/index.php\/wp-json\/wp\/v2\/posts\/344\/revisions"}],"predecessor-version":[{"id":472,"href":"https:\/\/vdna.be\/site\/index.php\/wp-json\/wp\/v2\/posts\/344\/revisions\/472"}],"wp:attachment":[{"href":"https:\/\/vdna.be\/site\/index.php\/wp-json\/wp\/v2\/media?parent=344"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vdna.be\/site\/index.php\/wp-json\/wp\/v2\/categories?post=344"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vdna.be\/site\/index.php\/wp-json\/wp\/v2\/tags?post=344"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}