Replica of database and Metabase - BI

Replica of database

A database replica is basically a copy of your original database.

Purpose:

  • High availability / failover: If the main database goes down, the replica can take over.
  • Load balancing: Queries (especially reporting or analytical queries) can be run on the replica so the main database isn’t overloaded.
  • Backup & disaster recovery: Replica can serve as a near real-time backup.

Metadata Instance (BI)

  • Metadata instance is like a separate environment where the BI system stores all its definitions and configurations.
    • Example: In SAP BI, you might have a “metadata instance” that tells the system how to read the replicated database and how to transform it into reports.
  • Purpose:
    • You can test BI reports without touching the main production system.
    • You maintain consistency of your BI definitions (calculations, dashboards) across environments.
    • When combined with a database replica, you get a full BI-ready copy of the production environment for safe testing or analytics.
# Metabase Setup

## Step 1: Create Digital Ocean Droplet

1. Go to **Digital Ocean**
2. Navigate to **Droplets**
3. Click **Create Droplet**
4. Configure droplet settings:
   - **Region**: New York
   - **Operating System**: Ubuntu
   - **CPU/RAM**: 2GB RAM
   - **Authentication method**: SSH

## 2. Setup SSH Key
- Click "New SSH Key"
- Open terminal and run: `ssh-keygen`
- Give file name when prompted
- File generates in local directory
- Open the `.pub` file and copy the key
- Paste key in SSH key content section
- Click "Add SSH Key" button with name
- Click Next button and create the VM

## 3. Access Console
- Open console

## 4. Setup Metabase in VM

### Update System
```bash
sudo apt update && sudo apt upgrade -y

Install Docker

curl -fsSL <https://get.docker.com> -o get-docker.sh
sudo sh get-docker.sh

Verify Docker Installation

docker run --rm hello-world

Create Metabase Directories & Set Permissions

sudo mkdir -p /opt/metabase/data
sudo chown $USER:$USER /opt/metabase -R
cd /opt/metabase

Create Docker Compose File

Create docker-compose.yml:

version: "3.8"
services:
  metabase:
    image: metabase/metabase:latest
    container_name: metabase
    restart: unless-stopped
    ports:
      - "3000:3000"
    volumes:
      - /opt/metabase/data:/metabase-data
    environment:
      - MB_DB_FILE=/metabase-data/metabase.db
      - MB_JETTY_HOST=0.0.0.0
      # optionally set site URL (use your IP or domain)
      # - MB_SITE_URL=http://YOUR_IP_OR_DOMAIN:3000

Start Metabase

# if 'docker compose' plugin is available:
docker compose up -d

# if you only have docker-compose:
# docker-compose up -d

Check Status

docker ps
docker logs -f metabase     # follow logs during startup

Access Metabase

  • Open browser: http://YOUR_DROPLET_IP:3000
  • You should see Metabase setup screen
  • Create admin account on Metabase

5. Firewall Configuration (Optional but Recommended)

If ufw is enabled:

sudo ufw allow 3000/tcp
# or if you use nginx reverse proxy on 80/443, you won't expose 3000 publicly

6. Backup/Restore the H2 App DB

Because we store H2 on host under /opt/metabase/data, backups are simple.

Backup (Recommended Regularly)

# Stop Metabase to ensure file is stable
docker compose down

# Create a dated tar.gz backup
sudo tar -czf /root/metabase-backup-$(date +%F).tar.gz -C /opt/metabase data

# Restart
docker compose up -d