Upgrading/data migration from mm 5.07 to supported version

Hi,

I inherited a VM (Turnkey Linux 15.2, Postgres 9.6, Mattermost 5.07) and I need to find a way of migrating to a newer version of mattermost I can keep updated. I read that I need to upgrade to at least 5.37.9 of mattermost to ensure compatability with later versions, only I can’t because the postgres version is 9.6, it seems that postgres 10 is required for mattermost 5.37.9.

Could I export the data from version 5.07 and import it into a later mattermost version using the JSON export? I would be very grateful for any recommendations of the simplest way of gaining a system which can be updated in the future.

Many thanks,
Daniel

Hi Daniel and welcome to the Mattermost forums,

I would suggest to migrate it using a DB dump and rsync for the files, I’ve already had a user following this approach with success in the community chat (see this thread).
Basically, if you do not have access there or don’t want to create an account, it boils down to this:

  1. Set up a new virtual machine with the desired operating system and PostgreSQL version

  2. Create the necessary environment there (mattermost system user, systemd unit file, nginx reverse proxy, empty database + user account, SSL certificates, etc.)

  3. Zip the data (files + DB) on the source server

tar czf /opt/mattermost.tgz /opt/mattermost
pg_dump mattermost > /opt/mattermost.sql
  1. Copy the data to the new server
scp /opt/mattermost.tgz /opt/mattermost.sql username@newserver:/opt
  1. Connect to the new server and extract the data there
ssh username@newserver
cd /opt
tar xf mattermost.tgz
pg_restore -d mattermost mattermost.sql
  1. Adjust config/config.json for the new connection strings and domain names (if you chose to change them)

  2. Try to start the old Mattermost version on your new server

If that works, you have an (outdated) copy of the system on a new server and can now play around with it.
The next step would then be to run the in-place upgrade on the new system to 5.37.9 by following the normal upgrade instructions and from there on, you can upgrade to 7.2.0 directly.

If your Mattermost data directory is huge and you do not have the space and time for creating a zip, you can also use rsync to sync the data on-the-fly to the new server. rsync can be used directly over SSH and with it you can also run deltasyncs, so the first sync of your data will take some time (depending on the size of your mattermost directory) and then you can run the command again and again in order to sync up the changes and you will see that it takes less time the more frequent you run it.
When you then finally decide to do the migration, stop your Mattermost server on the source, dump the database again, run rsync on the difference and start it on the destination and run the upgrades there, then.

That’s basically it, there are (of course) a lot of things to consider, depending on your exact configuration options and if you’ve never worked with rsync or database dumps, we might also need to dig deeper into these topics, so let me know what you think about the options I proposed here and if you know what to do now or if you need additional help and if so, please specify at which topic I should go a bit deeper into.

Hi Alexander.

I really appreciate your help. Based on your proposal, I thought I would be able to use the Turnkey 17.1 Mattermost vm based on Debian 11, postgres 13 to get started quickly. Mattermost 6.51 is already preconfigured on this image so I dropped the mattermost database, deleted the mattermost files and copied the database and files from the previous server I am trying to migrate.

Now the mattermost service won’t start and I don’t understand how it can tell 6.5.1 was installed after I have replaced the files and the database. This is the error message I got:

tail mattermost.log
{"level":"info","ts":1662332674.1102011,"caller":"sqlstore/supplier.go:207","msg":"Pinging SQL master database"}
{"level":"error","ts":1662332674.134881,"caller":"sqlstore/upgrade.go:110","msg":"Database schema version 6.5.1 is no longer supported. This Mattermost server supports automatic upgrades from schema version 3.0.0 through schema version 5.7.0. Downgrades are not supported. Please manually upgrade to at least version 3.0.0 before continuing"}
{"level":"info","ts":1662332685.6083713,"caller":"utils/i18n.go:78","msg":"Loaded system translations for 'en' from '/opt/mattermost/i18n/en.json'"}


journalctrl -u mattermost.service

Sep 04 21:58:02 mattermost mattermost[21332]: {"level":"info","ts":1662328682.235007,"caller":"utils/i18n.go:78","msg":"Loaded system translations for 'en' >
Sep 04 21:58:02 mattermost mattermost[21332]: {"level":"info","ts":1662328682.2356794,"caller":"app/app.go:143","msg":"Server is initializing..."}
Sep 04 21:58:02 mattermost mattermost[21332]: {"level":"info","ts":1662328682.2369804,"caller":"sqlstore/supplier.go:207","msg":"Pinging SQL master database>
Sep 04 21:58:02 mattermost mattermost[21332]: {"level":"error","ts":1662328682.2742257,"caller":"sqlstore/upgrade.go:110","msg":"Database schema version 6.5>
Sep 04 21:58:03 mattermost systemd[1]: mattermost.service: Main process exited, code=exited, status=234/n/a
Sep 04 21:58:03 mattermost systemd[1]: mattermost.service: Failed with result 'exit-code'.
Sep 04 21:58:03 mattermost systemd[1]: Failed to start Mattermost.
Sep 04 21:58:13 mattermost systemd[1]: mattermost.service: Scheduled restart job, restart counter is at 2.
Sep 04 21:58:13 mattermost systemd[1]: Stopped Mattermost.

At first I thought maybe some config files were loading from elsewhere, I found config.json in /etc/mattermost and overwrote it but that didn’t seem to help.

I’m not sure where else to look to work out what’s happening. Are you able to point me in the right direction? Was my approach flawed in thinking I could use a preconfigured image and just replace the files and database?

Many thanks,
Daniel

Phew, good question - maybe Mattermost is not where it seems to be or they installed two instances or something like that.
You did use this download, right?
I’ll see if I can try to reproduce that this week, but I’m not sure how soon I can get to it.

When you’re logged in there via SSH, make sure nothing with regards to Mattermost is running:

ps ax | grep -i [m]atter

According to the documentation, Mattermost should be installed in /opt/mattermost. When you copied over your files, did you make sure to overwrite everything that’s there or did you remove the files first?
I think it’s the best to move the current installation away and unpack the files you carried over from the old system into a freshly created directory:

cd /opt
mv mattermost mattermost.preinstalled
tar xf /pat/to/your/archive.tgz 

Ideally, this should give you a new mattermost directory (depending on the directory name in the archive, if it doesn’t match, rename it with mv).
The ownerships might also differ, usually, you will assign ownership of the files to a mattermost user:

chown -R mattermost: /opt/mattermost

If the user is not known, check the previous directory for a hint on how this user should be named.

The error message you’re seeing is definitely telling us that the database version is too new, so there must be some remrants of the old database available, so with all Mattermost-related service stopped, switch to the PostgreSQL user and drop the DB again:

su - postgres
dropdb mattermost
createdb mattermost -O mattermost

(But I’m not 100% sure what the username for the Mattermost user is, here it might also have a different name, you can check that by logging into the PostgreSQL console:

su - postgres
psql
\du

I think /etc/mattermost is probably just a symlink to the configuration, but to see what we’re dealing with, can you share the output of the following commands?

ls -lR /etc/mattermost
ls -lR /opt/mattermost
systemctl status mattermost
su - postgres
psql
\du
\l

Thanks!

Hi Alexander,

Thanks for walking me through this. The turnkey appliance was fine, evidently something went wrong importing the database dump. After dropping it and trying again all went well and I was finally able to get this system updated and back online today.

Thank you so much! Your instructions were really helpful and clear.

Best wishes,
Daniel

Awesome, glad to hear that :slight_smile: Please mark my most appropriate answer as solution so others can find the solution to similar questions quickly.