View Categories

Back up and restore the MikroWizard server

Free Pro

A MikroWizard server keeps its data in two places: the PostgreSQL database (inside the MikroWizard-postgre container) and files on the host, mostly under /opt/mikrowizard. A complete backup needs both.

What to back up #

WhatWhere (default)WhyNeeded?
DatabaseMikroWizard-postgre container, database MikroWizardDBDevices, users, groups, permissions, settings, tasks, logs, vault entries, PAM policies, customer dataYes
server-conf.json/opt/mikrowizard/server-conf.jsonThe encryption keys PYSRV_CRYPT_KEY and PYSRV_KEK, plus the addon tokens. Without these keys, the device passwords and vault entries in the database can’t be decrypted.Yes
Router configuration backupsThe backup folder chosen at install (/opt/mikrowizard/backup, older installs /opt/mikrowizard/backups)Every backup file and configuration version. The database only points to these files.Yes
Session recordings (Pro)/opt/mikrowizard/terminal_recordings, /opt/mikrowizard/webfig_recordingsReplays of SSH, RDP, VNC, WebBox and WebFig sessionsYes, if you keep recordings for audits
SSL certificates/opt/mikrowizard/ssl, nginx-ssl-server.conf, nginx-ssl-redirect.confLet’s Encrypt account and certificates, or your own certificateYes, if you use HTTPS
Terminal Gateway (Pro)/opt/mikrowizard/terminal-gateway/gateway.envGateway settings and its API tokenYes, if installed on this server
WireGuard addon (Pro)/opt/mikrowizard/wireguardThe server’s private key, the addon token and peer state. With a new key, every peer’s configuration has to be replaced.Yes, if installed
MikroSpeed addon/opt/mikrowizard/speedtestThe addon tokenYes, if installed
Firmware filesThe firmware folder chosen at install (/opt/mikrowizard/firmwares)Downloaded RouterOS packagesOptional: they can be downloaded again

Not needed: drives (temporary per-session drives of the Terminal Gateway), logs (service log files), wireguard-addon (addon program files, reinstalled by its installer), recreate-ssl.sh (created again by MikroWizard), front-update-last-check, crontab and old *.bak / -b copies. The Redis container holds only temporary data such as sign-in sessions, queues and the state of running jobs.

Check your folders #

Your backup and firmware folders may not be the defaults. Show the folders the backend container uses:

sudo docker inspect -f '{{range .Mounts}}{{.Source}} -> {{.Destination}}{{println}}{{end}}' mikroman

The folder mounted on /backups holds the router backups, the one on /firms the firmware files.

Show the database user and name:

sudo grep -E '"PYSRV_DATABASE_(USER|NAME)"' /opt/mikrowizard/server-conf.json

Back up #

Run on the MikroWizard server. Replace DBUSER with the database user shown above and MikroWizardDb with database DATABASE_NAME . If your backup folder is outside /opt/mikrowizard, add it at the end of the tar command.

sudo mkdir -p /root/mw-backup
sudo sh -c 'docker exec MikroWizard-postgre pg_dump -U DBUSER -Fc MikroWizardDB > /root/mw-backup/MikroWizardDB.dump'
sudo tar czf /root/mw-backup/mikrowizard-files.tgz   --exclude=/opt/mikrowizard/drives --exclude=/opt/mikrowizard/logs   /opt/mikrowizard

To leave out firmware files, add --exclude=/opt/mikrowizard/firmwares.

Check the result with sudo ls -lh /root/mw-backup. A dump of only a few kilobytes means it failed.

Copy /root/mw-backup to another machine and keep it safe: it contains the encryption keys and device credentials.

Restore #

Restore onto the same MikroWizard version. A new installation installs the latest version, so upgrade the old server to the latest version before you take the backup.

  1. Install MikroWizard on the target server: see Install MikroWizard. Use the same backup and firmware folders as before.
  2. Copy the backup to /root/mw-backup on the target server and stop the backend:
sudo docker stop mikroman
  1. Keep a copy of the new configuration file, then restore the files:
sudo cp /opt/mikrowizard/server-conf.json /root/server-conf.new.json
sudo tar xzpf /root/mw-backup/mikrowizard-files.tgz --numeric-owner -C /
  1. The restored server-conf.json has the old keys, which you need, but also the old database and Redis passwords. Put the new installation’s database user and passwords back into it:
sudo python3 -c '
import json
p = "/opt/mikrowizard/server-conf.json"
new = json.load(open("/root/server-conf.new.json"))
conf = json.load(open(p))
for k in ("PYSRV_DATABASE_USER", "PYSRV_DATABASE_PASSWORD", "PYSRV_REDIS_PASSWORD"):
    conf[k] = new[k]
json.dump(conf, open(p, "w"), indent=4)
'
sudo chmod 600 /opt/mikrowizard/server-conf.json
  1. Restore the database. Replace DBUSER with the database user of the new installation and MikroWizardDb with database DATABASE_NAME :
sudo sh -c 'docker exec -i MikroWizard-postgre pg_restore -U DBUSER -d MikroWizardDB --clean --if-exists --no-owner --no-acl < /root/mw-backup/MikroWizardDB.dump'
  1. Start MikroWizard again:
sudo docker restart mikrofront
sudo docker start mikroman
  1. Addons: run the installer of each addon you used: Terminal Gateway, WireGuard, MikroSpeed. They use their restored folders and write their settings into server-conf.json. The WireGuard addon keeps the restored private key, so peers keep working.
  2. Schedules: open each scheduled task in the Task Planner and save it again. Do the same for the Password Vault settings and for Sync & Clone profiles that run on a schedule. These schedules are kept inside the backend container, not in the database, so a new container doesn’t have them until they are saved again.
  3. Sign in and check: devices come online, Password Vault › Reveal shows a password (this proves the keys match), backups and recordings open.

Common problems #

ProblemCause and fix
The backend doesn’t start after the restoreWrong database or Redis password in server-conf.json. Repeat step 4.
Devices fail with authentication errors, vault passwords can’t be revealedserver-conf.json is not the one from the backup, so the keys don’t match the database.
Backups are listed but don’t openThe router backup folder wasn’t restored, or the backend uses another folder. Check with docker inspect as above.
Scheduled tasks don’t runSave each task again (step 8).
pg_restore reports an unsupported versionThe dump is from a newer PostgreSQL than the target. Use the same or a newer PostgreSQL image on the target.

Next step #