Restore from backup

What I did: upgraded my Mattermost docker container from Mattermost-docker to the new image. Including Postgres, & Mattermost upgrade.

What happened I lost all my data :frowning:

How Can I restore my backup that was stored as files in the Mattermost-docker/backup directory?

Hi Stiffbeard,

can you describe how you did run the upgrade? If the upgrade you ran also included a new postgresql container version, the data is not being migrated and as long as the container is still there, the data should be there too.

Can you run docker ps -a to verify that the old container is still there and has not been removed as of yet?
Also can you show the contents of your mattemost-docker/backup directory? By default, Mattermost does not take backups so you probably have set up a backup on your own and in order to know how to restore it, we need to see what’s there.

Basically followed the workflow of this script here: docker/ at main · mattermost/docker · GitHub

The original container is gone from docker. See image for contents of backup folder.

The backup was just a CP like so:

cp -ra “$PATH_TO_MATTERMOST_DOCKER”/volumes/app/mattermost/ “$PATH_TO_MATTERMOST_DOCKER”/backups/mattermost-backup-“$DATE”/

cp -ra “$PATH_TO_MATTERMOST_DOCKER”/volumes/db/ “$PATH_TO_MATTERMOST_DOCKER”/backups/database-backup-“$DATE”/

Wondering can I just copy the files back over the same location? Or would I have to copy them into the container?

This is not a database consistent backup if being run while the database is running. Using this command on a running database server will most likely result in not all files being copied properly due to locks and (depending on the queries running) also result in half applied transactions or other database corruption. Anyways, if that’s all you got, you can indeed try to just copy over the contents of the db directory to the new container (which should also expose the db folder to the host). Make sure to remove the data in there first, the files should not be merged and check the filesystem structure which should also be the same.
There might be PostgreSQL version numbers used for folder names which also need to be changed then. The source code of the script you linked talks about some of these problems and also tells you what files need to be modified to adjust to the new paths and versions (postgresql.conf, pg_hba.conf, …). Hard to tell what your current situation is now and therefore it’s also impossible to provide tailored remediation steps for you now.

The PostgreSQL database format is tied to the version running, so if you have a copy of the data directory from PostgreSQL 10.1 f.ex., you cannot just copy it over on a 13.1 installation. It will need to be upgraded using the pg_upgrade command which the script you linked does, so I can only suggest to go through the script which contains the recipe for a working upgrade and find out what went wrong on your end.

It was not running. The docker container was “down”. I will consider your suggestions here. Thank you for your time.

Q: What is the recommended method for mattermost backup then?

I’d suggest to dump the database using pg_dump or any other logical database backup tool that supports working with containerized databases as well as a full copy of your data directory (could be a tar.gz f.ex.).