Skip to content

Instantly share code, notes, and snippets.

@rhiskey
Last active October 1, 2021 09:21
Show Gist options
  • Save rhiskey/565bda02229d1d5dfbed621024e7964b to your computer and use it in GitHub Desktop.
Save rhiskey/565bda02229d1d5dfbed621024e7964b to your computer and use it in GitHub Desktop.
Upgrade Mattermost Server
  1. In a terminal window on the server that hosts Mattermost, change to your home directory. Delete any files and directories that might still exist from a previous download.
cd /tmp
  1. Download the latest version of Mattermost Server. In the following command, replace X.X.X with the version that you want to download:
wget https://releases.mattermost.com/X.X.X/mattermost-X.X.X-linux-amd64.tar.gz

3.Confirm no other Mattermost zip folders exist in your /tmp directory. If another version’s zip file does exist, delete or rename the file.

ls -- mattermost*.gz

If anything except the new release is returned above, rename this file or delete it completely.

  1. Extract the Mattermost Server files.
tar -xf mattermost*.gz --transform='s,^[^/]\+,\0-upgrade,'

The transform option adds a suffix to the topmost extracted directory so it does not conflict with the usual install directory.

  1. Stop your Mattermost server.
sudo systemctl stop mattermost
  1. Back up your data and application.

a. Back up your database using your organization’s standard procedures for backing up MySQL or PostgreSQL.

b. Back up your application by copying into an archive folder (e.g. mattermost-back-YYYY-MM-DD-HH-mm).

sudo cp -ra /opt/mattermost/ mattermost-back-$(date +'%F-%H-%M')/
  1. Remove all files except data and custom directories from within the current mattermost directory.

What’s preserved on upgrade?

By default, your data directories will be preserved with the following commands:config, logs, plugins, client/plugins, and data (unless you have a different value configured for local storage). Custom directories are any directories that you’ve added to Mattermost and are not preserved by default. Generally, these are TLS keys or other custom information.

Run ls on your Mattermost install directory to identify what default folders exist.

A default Mattermost installation has the following files and directories:

$ ls /opt/
ENTERPRISE-EDITION-LICENSE.txt README.md  client  data   i18n  manifest.txt  prepackaged_plugins
NOTICE.txt                      bin        config  fonts  logs  plugins       templates

[b] Clear the Mattermost folder [/b]

Dry-run the following command to delete the contents of the mattermost folder, preserving only the specified directories and their contents:

cd /opt/mattermost
sudo find mattermost/ mattermost/client/ -mindepth 1 -maxdepth 1 \! \( -type d \( -path mattermost/client -o -path mattermost/client/plugins -o -path mattermost/config -o -path mattermost/logs -o -path mattermost/plugins -o -path mattermost/data \) -prune \) | sort

When you’re ready to execute the command, append xargs rm -r to the command above to delete the files. Note that the following example includes -o -path mattermost/yourFolderHere:

sudo find mattermost/ mattermost/client/ -mindepth 1 -maxdepth 1 \! \( -type d \( -path mattermost/client -o -path mattermost/client/plugins -o -path mattermost/config -o -path mattermost/logs -o -path mattermost/plugins -o -path mattermost/data -o -path  mattermost/yourFolderHere \) -prune \) | sort | sudo xargs rm -r

  1. Copy the new files to your install directory and remove the temporary files.
sudo cp -an /tmp/mattermost-upgrade/. mattermost/
sudo rm -r /tmp/mattermost-upgrade/
sudo rm -i /tmp/mattermost*.gz
  1. Change ownership of the new files after copying them. For example:
sudo chown -R mattermost:mattermost /opt/mattermost

  1. Start your Mattermost server.
sudo systemctl start mattermost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment