How to restore Mattermost from S3 backup file?

From PheonixSolutions
Jump to navigation Jump to search

Please follow the below steps to restore the Mattermost website from the s3 backup file.

Step1:

First, install AWS-CLI on the centos server with the below command. We are using centos.

yum install aws-cli

Step2:

Run aws configure and give the access-key and secret access key. This will give access to s3 for getting(downloading) the file from s3. Please find the screenshot

Step3:

Use the below commands to copy the backup files from s3.aws s3 cp s3://vm4mattermost/dbbackup_0303220000.sql .

 aws s3 cp s3://vm4mattermost/ngnixbackup_0303220000.tar .
 aws s3 cp s3://vm4mattermost/sitebackup_0303220000.tar .

Step4:

Extract the file sitebackup_0303220000.tar to the /opt as the mattermost default path is /opt using the tar command. Please find the screenshot.

 tar -xvf sitebackup_0303220000.tar

Step5: Install mysql with the following commands

 wget http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
 sudo yum localinstall mysql57-community-release-el7-9.noarch.rpm
 sudo yum install mysql-community-server
 sudo systemctl start mysqld.service

Step6:

Obtain the root password that was generated when you started MySQL for the first time. Please use the below command.

sudo grep 'temporary password' /var/log/mysqld.log

Step7

Change the root password. Login with the password that you obtained from the previous step

 mysql -u root -p

Step8:

Change the password. At the mysql prompt, type the following command. Be sure to replace Password42! with the password that you want to use.

ALTER USER 'root'@'localhost' IDENTIFIED BY 'Password42!';

Step9:

Set MySQL to start automatically when the machine starts.

sudo systemctl enable mysqld

Step10:

Create the Mattermost user ‘mmuser’.

 create user 'mmuser'@'%' identified by 'mmuser-password';

Step11: Create the Mattermost database.

 create database mattermost;

'Step12:Grant access privileges to the user ‘mmuser’.

grant all privileges on mattermost.* to 'mmuser'@'%';

Step13:

Log out of MySQL with exit command and restore the database with the below command. In the step2, you have already copied the sql backup file from s3. Got that path and execute the below command.

 mysql -u root -p mattermost < dbbackup_0303220000.sql

Step14:

Set up a system user and group called mattermost that will run this service, and set the ownership and permissions.

 sudo useradd --system --user-group mattermost
 sudo chown -R mattermost:mattermost /opt/mattermost
 sudo chmod -R g+w /opt/mattermost

Step15:

Goto /opt/mattermost/config/config.json and check for the below things

  1. DriverName" should be "mysql"
  2. Set "DataSource" to the following value, replacing <mmuser-password> and <host-name-or-IP> with the appropriate values. Also make sure that the database name is mattermost instead of mattermost_test:
 "mmuser:<mmuser-password>@tcp(<host-name-or-IP>:3306)/mattermost?charset=utf8mb4,utf8&writeTimeout=30s"
  1. Should be the full base URL of the site (e.g. "https://mattermost.example.com").

Note:


As we have copied from the backup file the above things will already exist. Just cross check and change the old Ip to new Ip in "mmuser:<mmuser-password>@tcp(<host-name-or-IP>:3306)/mattermost?charset=utf8mb4,utf8&writeTimeout=30s"

Step16: After that goto cd /opt/mattermost and start the mattermost server with the below command. Make sure that 3306 port is open.

 sudo -u mattermost ./bin/mattermost

When the server starts, it shows some log information and the text Server is listening on :8065. You can stop the server by pressing CTRL+C in the terminal window.

Set up Mattermost to use the systemd init daemon which handles supervision of the Mattermost process.

Step17:Create the Mattermost configuration file:

 sudo touch /etc/systemd/system/mattermost.service

Step18Open the configuration file in your favorite text editor, and copy the following lines into the file:


Description=Mattermost
After=syslog.target network.target postgresql-9.4.service
[Service]
Type=notify
WorkingDirectory=/opt/mattermost
User=mattermost
ExecStart=/opt/mattermost/bin/mattermost
PIDFile=/var/spool/mattermost/pid/master.pid
TimeoutStartSec=3600
KillMode=mixed
LimitNOFILE=49152
[Install]
WantedBy=multi-user.target

Step19:

Set the service file permissions.

 sudo chmod 644 /etc/systemd/system/mattermost.service

Step20

Reload the systemd services.

  sudo systemctl daemon-reload

Step21

Set Mattermost to start on boot.

 sudo systemctl enable mattermost

Step22:

Start the Mattermost server.

 sudo systemctl start mattermost

Step23

Verify that Mattermost is running.

 curl http://localhost:8065

Step24

You can also goto browser and check with your Ip like below. You will able to login with the old credentials like in the screenshot.

After this verify the below things which are in the screenshot. They will be already exist just need to verify accordingly. If any change is required then please change accordingly.

Please follow the below link for NGINX and SSL setup

https://docs.mattermost.com/install/install-rhel-7.html