1 8.3.1 Restore manual restore
Asif Bacchus edited this page 1 year ago

Restoring Backups - manual restore

If you don’t want to use the restore script or cannot use it due to a non-standard set up, here is how you can manually restore your mailcow from the extracted borg archive.

First off, you still have to do all the steps as outlined on pages 8.1 and 8.2.

  1. Switch to your mailcow directory (I will assume the default location for this example) and START MAILCOW. Then ‘source’ your mailcow.conf file so you can use environment variables in the subsequent commands. Wait a minute or two before proceeding to the next step so that mailcow has time to start properly.

    cd /opt/mailcow-dockerized
    docker-compose up -d
    source mailcow.conf
    
  2. Let’s restore the mailcow database first. Remember to change the location of your extracted backup as necessary. You can skip this step if you are not restoring the mailcow settings database.

    SQLBACKUP=$(find /var/mcRestore/tmp -iname "*.sql")
    docker exec -i "$(docker-compose ps -q mysql-mailcow)" mysql -u${DBUSER} -p${DBPASS} ${DBNAME} < "${SQLBACKUP}"
    
  3. Stop all containers.

    docker-compose down
    
  4. Copy our extracted data to the proper volumes. You can skip any of these as per your requirements. Also, remember to change the location of your extracted backups as necessary.

    # copy email
    SRC=$(find /var/mcRestore -iname "*vmail*" -type d)
    TGT=$(docker volume inspect -f '{{.Mountpoint}}' ${COMPOSE_PROJECT_NAME}_vmail-vol-1)
    (cd "$SRC/_data" && tar -cf - .) | (cd "$TGT" && tar xvf -)
    
    # copy encryption key
    SRC=$(find /var/mcRestore -iname "*crypt*" -type d)
    TGT=$(docker volume inspect -f '{{.Mountpoint}}' ${COMPOSE_PROJECT_NAME}_crypt-vol-1)
    (cd "$SRC/_data" && tar -cf - .) | (cd "$TGT" && tar xvf -)
    
    # copy postfix data
    SRC=$(find /var/mcRestore -iname "*postfix*" -type d)
    TGT=$(docker volume inspect -f '{{.Mountpoint}}' ${COMPOSE_PROJECT_NAME}_postfix-vol-1)
    (cd "$SRC/_data" && tar -cf - .) | (cd "$TGT" && tar xvf -)
    
    # copy rspamd data
    SRC=$(find /var/mcRestore -iname "*rspamd*" -type d)
    TGT=$(docker volume inspect -f '{{.Mountpoint}}' ${COMPOSE_PROJECT_NAME}_rspamd-vol-1)
    (cd "$SRC/_data" && tar -cf - .) | (cd "$TGT" && tar xvf -)
    
    # copy redis
    SRC=$(find /var/mcRestore -iname "*redis*" -type d)
    TGT=$(docker volume inspect -f '{{.Mountpoint}}' ${COMPOSE_PROJECT_NAME}_redis-vol-1)
    (cd "$SRC/_data" && tar -cf - .) | (cd "$TGT" && tar xvf -)
    
  5. Restart mailcow and monitor the logs. When you’re done monitoring the real-time log file, press ctrl-c

    docker-compose up -d && docker-compose logs -f
    
  6. Login to the mailcow admin console. Ensure your admin login works properly. Reset Rspamd console password (not restored for some reason).

  7. Test out mailcow, ensure data is restored.

  8. Clean-up extracted borg archive (optional but recommended to save space)

    rm -rf /var/mcRestore
    

That’s it!