Mattermost Peer-to-Peer Forum

[SOLVED] How do I back up a GitLab Mattermost database?


#1

I can’t figure out how to backup the database. Can someone please send me a tutorial or something?

Updated June 28, 2016, here’s the command:

sudo -u mattermost -i bash
/opt/gitlab/embedded/bin/pg_dump -U gitlab_mattermost -h /var/opt/gitlab/postgresql -p 5432 mattermost_production > mattermost_production_backup

Is Mattermost Backup included in GitLab Backup?
#2

Okay, I think I’ve made a bit of progress, but I’m still stuck. I found how to use the pg_dump command, but it’s giving me the following error:

mattermost@git:~$ /opt/gitlab/embedded/bin/pg_dump mattermost_production > mattermost_production.bak
pg_dump: [archiver (db)] connection to database "mattermost_production" failed: could not connect to server: No such file or directory
	Is the server running locally and accepting
	connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

#3

Okay, I think I’m on to something here. I’ve got this:

sudo /opt/gitlab/embedded/bin/pg_dump -U gitlab_mattermost -h /var/opt/gitlab/postgresql -p 5432 mattermost_production > mattermost_production_backup

But that returns

pg_dump: [archiver (db)] connection to database "mattermost_production" failed: FATAL: Peer authentication failed for user "gitlab_mattermost"

Hmm.


Upgrading to GitLab Mattermost in GitLab 8.9
#4

Okay, I’m stuck. Any help would be greatly appreciated.


#5

Got it, here’s what I did:

sudo -u mattermost -i bash
/opt/gitlab/embedded/bin/pg_dump -U gitlab_mattermost -h /var/opt/gitlab/postgresql -p 5432 mattermost_production > mattermost_production_backup

#6

thanks for sharing your solution! it worked for me too.


#7

I was trying to import the database with sudo -u mattermost /opt/gitlab/embedded/bin/psql -U gitlab_mattermost -h /var/opt/gitlab/postgresql -p 5432 mattermost_production < mattermost_production_backup, but there were many errors with relations already existing.

What’s a good way to restore the database?


#8

ackerleytng, did you ever figure out how to import the database?


#9

Figured out a nice semi-onliner for this. Once this runs, you still need to move it out of /tmp/ to wherever you want to store it.

sudo -H -u mattermost bash -c '/opt/gitlab/embedded/bin/pg_dump -U gitlab_mattermost -h /var/opt/gitlab/postgresql -p 5432 mattermost_production > /tmp/mattermost_production.sql'