Have a Question?

<All Topics
Print

Rocket.Chat – Migrando da versão 3.18 para a versão 4.0

Migrating MongoDB from MMAPv1 to WiredTiger

Initial installations of Rocket.Chat via docker, came standard with the storage engine (Storage Engine) MMAPv1.

This mechanism, however, has been discontinued and, in order to update Rocket.Chat from older versions like 3.x to 4.x, it is necessary to migrate MongoDB storage to WiredTiger.

This step-by-step has been tested when migrating from a Rocket.Chat 3.18.x environment to 4.0 and it is possible that it will be used for other versions.

First, edit the docker-compose.yml file, creating two new volumes in the mongodb service or container, as below. We put the added excerpt in red:

version: '3.4'

services:    
  rocketchat:

    image: rocketchat/rocket.chat:latest
    command: "node main.js"
    environment:
      - PORT=3000
      - ROOT_URL=http://localhost:3000
      - MONGO_URL=mongodb://mongo:27017/rocketchat
      - MONGO_OPLOG_URL=mongodb://mongo:27017/local
      - ADMIN_USERNAME=admin
      - ADMIN_PASS=admin
    ports:
      - 3000:3000

  mongo:
    image: mongo:4.0
    restart: unless-stopped
    volumes:
      - mongo-data-rz:/data/db
      - mongo-data-backup-volume:/data/backup
      - mongo-data-dump:/data/dump
    command: mongod --smallfiles --oplogSize 128 --replSet rs0 --storageEngine=mmapv1

  mongo-init-replica:
    image: mongo:4.0
    command: >
      bash -c
        "for i in `seq 1 30`; do
          mongo mongo/rocketchat --eval \"
            rs.initiate({
              _id: 'rs0',
              members: [ { _id: 0, host: 'localhost:27017' } ]})\" &&
          s=$$? && break || s=$$?;
          echo \"Tried $$i times. Waiting 5 secs...\";
          sleep 5;
        done; (exit $$s)"    labels:
      - "traefik.enable=false"
    depends_on:
      - mongo

volumes:
  mongo-data-rz:
    driver: local             
  mongo-data-backup-volume:
    driver: local             
  mongo-data-dump:
    driver: local

Start or update the mongo service or container with the following command:

docker-compose up -d mongo

Now access the mongo container:

docker-compose exec mongo bash

And run the following commands to make a backup of the original files and also generate a dump that allows importing into the new storage engine:

cp /data/db /data/backup/ -r mongodump --archive=/data/dump/mmap --gzip

Now that we have the backup and dump, let's delete the database:

rm -rf /data/db/*

Now we need to make a new adjustment to Mongo's startup command so that it uses the WiredTiger engine. See the line we modified below, in red:

version: '3.4'

services:    
  rocketchat:

    image: rocketchat/rocket.chat:latest
    command: "node main.js"
    environment:
      - PORT=3000
      - ROOT_URL=http://localhost:3000
      - MONGO_URL=mongodb://mongo:27017/rocketchat
      - MONGO_OPLOG_URL=mongodb://mongo:27017/local
      - ADMIN_USERNAME=admin
      - ADMIN_PASS=admin
    ports:
      - 3000:3000

  mongo:
    image: mongo:4.0
    restart: unless-stopped
    volumes:
      - mongo-data-rz:/data/db
      - mongo-data-backup-volume:/data/backup
      - mongo-data-dump:/data/dump
    command: mongod --oplogSize 128 --replSet rs0 --storageEngine=wiredTiger --bind_ip_all

  mongo-init-replica:
    image: mongo:4.0
    command: >
      bash -c
        "for i in `seq 1 30`; do
          mongo mongo/rocketchat --eval \"
            rs.initiate({
              _id: 'rs0',
              members: [ { _id: 0, host: 'localhost:27017' } ]})\" &&
          s=$$? && break || s=$$?;
          echo \"Tried $$i times. Waiting 5 secs...\";
          sleep 5;
        done; (exit $$s)"    labels:
      - "traefik.enable=false"
    depends_on:
      - mongo

volumes:
  mongo-data-rz:
    driver: local             
  mongo-data-backup-volume:
    driver: local             
  mongo-data-dump:
    driver: local

Update the stack by running the command below:

docker-compose up -d mongo

Access the mongo container again:

docker-compose exec mongo bash

Now let's restore the Rocket.Chat bank inside Mongo:

mongorestore --drop --archive=/data/dump/mmap --gzip --noIndexRestore mongo --eval 'db.repairDatabase()'

Ready! Now just update Rocket.Chat and MongoDB version in docker-compose.yml:

version: '3.4'

services:    
  rocketchat:

    image: rocketchat/rocket.chat:4.0.0
    command: "node main.js"
    environment:
      - PORT=3000
      - ROOT_URL=http://localhost:3000
      - MONGO_URL=mongodb://mongo:27017/rocketchat
      - MONGO_OPLOG_URL=mongodb://mongo:27017/local
      - ADMIN_USERNAME=admin
      - ADMIN_PASS=admin
    ports:
      - 3000:3000

  mongo:
    image: mongo:4.2
    restart: unless-stopped
    volumes:
      - mongo-data-rz:/data/db
      #  Comentar ou remover:
      # - mongo-data-backup-volume:/data/backup
      # - mongo-data-dump:/data/dump
    command: mongod --oplogSize 128 --replSet rs0 --storageEngine=wiredTiger --bind_ip_all

  mongo-init-replica:
    image: mongo:4.2
    command: >
      bash -c
        "for i in `seq 1 30`; do
          mongo mongo/rocketchat --eval \"
            rs.initiate({
              _id: 'rs0',
              members: [ { _id: 0, host: 'localhost:27017' } ]})\" &&
          s=$$? && break || s=$$?;
          echo \"Tried $$i times. Waiting 5 secs...\";
          sleep 5;
        done; (exit $$s)"    labels:
      - "traefik.enable=false"
    depends_on:
      - mongo

volumes:
  mongo-data-rz:
    driver: local             
#  Comentar ou remover:
#  mongo-data-backup-volume:
#    driver: local             
#  mongo-data-dump:
#    driver: local

Leave a Reply

Your email address will not be published. Required fields are marked *

summary