Migration Guide

Moving from another Kuzzle host to FiveHost — keep all your server data intact.

If you'd prefer us to handle the migration for you, we offer a managed migration service for a one-off fee of £15. Contact us on Discord to arrange it.

Before you start

You'll need:

Do this migration during a server downtime window. Do not run your FiveM server while migrating — it may write new data to the old instance mid-migration.

Step 1 — Export your data from the old instance

Create a file called export.js on your computer and paste the following:

const https = require('https');
const fs = require('fs');

// ── CONFIGURE THESE ──────────────────────────────────────
const OLD_ENDPOINT = 'your-old-kuzzle-host.com';  // without https://
const OLD_API_KEY  = 'your-old-api-key';
const OLD_INDEX    = 'prod';  // your old prod index name
// ─────────────────────────────────────────────────────────

function request(hostname, path, method, body, token) {
  return new Promise((resolve, reject) => {
    const data = body ? JSON.stringify(body) : null;
    const headers = { 'Content-Type': 'application/json' };
    if (token) headers['Authorization'] = 'Bearer ' + token;
    if (data) headers['Content-Length'] = Buffer.byteLength(data);
    const req = https.request({ hostname, port: 443, path, method, headers }, res => {
      let raw = '';
      res.on('data', c => raw += c);
      res.on('end', () => resolve(JSON.parse(raw)));
    });
    req.on('error', reject);
    if (data) req.write(data);
    req.end();
  });
}

async function main() {
  console.log('Fetching collections...');
  const collectionsResult = await request(OLD_ENDPOINT, '/' + OLD_INDEX + '/_list', 'GET', null, OLD_API_KEY);
  const collections = collectionsResult.result.collections;
  console.log('Found ' + collections.length + ' collections');

  const exportData = {};

  for (const collection of collections) {
    console.log('Exporting ' + collection + '...');
    const result = await request(OLD_ENDPOINT, '/' + OLD_INDEX + '/' + collection + '/_search', 'POST', {
      size: 10000
    }, OLD_API_KEY);

    if (result.result && result.result.hits) {
      exportData[collection] = result.result.hits.map(hit => ({
        _id: hit._id,
        ...hit._source
      }));
      console.log('  Exported ' + exportData[collection].length + ' documents');
    }
  }

  fs.writeFileSync('kuzzle-export.json', JSON.stringify(exportData, null, 2));
  console.log('\nExport complete. Saved to kuzzle-export.json');
}

main().catch(console.error);

Fill in your old Kuzzle endpoint, API key and index name at the top, then run:

node export.js

This will create a kuzzle-export.json file containing all your data.

Step 2 — Import your data into FiveHost

Create a file called import.js and paste the following:

const https = require('https');
const fs = require('fs');

// ── CONFIGURE THESE ──────────────────────────────────────
const NEW_API_KEY = 'your-fivehost-api-key';   // from your welcome email
const NEW_INDEX   = 'yourname-prod';            // your FiveHost prod index
// ─────────────────────────────────────────────────────────

const ENDPOINT = 'kuzzle.fivehost.co.uk';

function request(path, method, body) {
  return new Promise((resolve, reject) => {
    const data = body ? JSON.stringify(body) : null;
    const headers = {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer ' + NEW_API_KEY,
    };
    if (data) headers['Content-Length'] = Buffer.byteLength(data);
    const req = https.request({ hostname: ENDPOINT, port: 443, path, method, headers }, res => {
      let raw = '';
      res.on('data', c => raw += c);
      res.on('end', () => resolve(JSON.parse(raw)));
    });
    req.on('error', reject);
    if (data) req.write(data);
    req.end();
  });
}

async function main() {
  const exportData = JSON.parse(fs.readFileSync('kuzzle-export.json', 'utf8'));
  const collections = Object.keys(exportData);

  console.log('Importing ' + collections.length + ' collections into ' + NEW_INDEX + '...\n');

  for (const collection of collections) {
    const documents = exportData[collection];
    if (documents.length === 0) {
      console.log(collection + ': no documents, skipping');
      continue;
    }

    console.log(collection + ': importing ' + documents.length + ' documents...');

    const bulkBody = documents.flatMap(doc => {
      const { _id, ...body } = doc;
      return [{ index: { _id } }, body];
    });

    const result = await request(
      '/' + NEW_INDEX + '/' + collection + '/_bulk',
      'POST',
      { bulkData: bulkBody }
    );

    const imported = result.result ? (result.result.successes || []).length : 0;
    const errors = result.result ? (result.result.errors || []).length : 0;
    console.log('  Done — ' + imported + ' imported, ' + errors + ' errors');
  }

  console.log('\nImport complete.');
}

main().catch(console.error);

Fill in your FiveHost API key and prod index name from your welcome email, then run:

node import.js

Step 3 — Verify your data

Log into your FiveHost Dashboard using your credentials and check that your collections contain the expected number of documents.

Step 4 — Update your FiveM server config

Update your server's Kuzzle config with your new FiveHost connection details:

Restart your FiveM server and you're live on FiveHost.

Need help?

If you run into any issues during migration, join our Discord and we'll help you out. For a fully managed migration where we handle everything, contact us for the £15 managed migration service.