serverModuleCloner

  • community
  • administration
  • by limon
  • Takaro v0.0.29
  • all
Version
View export JSON

Module Importer: Cross-Server Module Configuration Replication


🎥 SETUP TUTORIAL
â–º Watch the Complete Guide
Learn how to replicate module configurations between servers

The Module Importer provides administrators with a powerful tool to replicate module configurations from one server to another. This administrative Takaro module streamlines server setup by copying all installed modules and their exact configurations from a source server, making it ideal for maintaining consistency across multiple game servers or quickly deploying tested configurations.

Key Benefits:

  • Time-Saving Setup: Instantly replicate complex module configurations instead of manual setup
  • Configuration Consistency: Ensure identical module setups across multiple servers
  • Template Server Approach: Use one server as a master template for others
  • Exact Configuration Copying: Preserves both system and user configurations precisely
  • Administrative Control: Manual execution prevents accidental triggers

Features:

  • Manual execution through module builder for controlled deployment
  • Copies all installed modules from specified source server
  • Preserves exact user and system configurations
  • Updates existing modules with source server settings
  • Installs new modules that don't exist on target server
  • Detailed logging of installation, update, and skip operations
  • Source server identification via gameserver ID from dashboard URL
  • Built specifically for administrative use outside of gameplay
  • Progress tracking with comprehensive operation reporting

Important Notes:

  • Best used between servers running the same game type
  • Cross-game compatibility may cause issues with game-specific configurations
  • Requires administrator knowledge of module management
  • Manual trigger recommended for careful timing and control

Configuration 1

Settings you fill in when installing the module on a server.

SettingTypeDefaultDescription
sourceServerId sourceServerId string — The ID of the server to copy modules from
Raw config schema
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "required": [],
  "additionalProperties": false,
  "properties": {
    "sourceServerId": {
      "title": "sourceServerId",
      "description": "The ID of the server to copy modules from\n",
      "type": "string"
    }
  }
}
Raw UI schema
{}

Cron jobs 1

Work the module runs on a schedule.

  • my-cronjob

    Cron job source
    // cronJobs/copyModules.js
    import { takaro, data } from '@takaro/helpers';
    
    async function main() {
        const { gameServerId, module: mod } = data;
    
        // Get source server details from config
        const sourceServerId = mod.userConfig.sourceServerId;
    
        if (!sourceServerId) {
            console.log('Module Copier: Source server ID not configured, skipping.');
            return;
        }
    
        console.log(`Module Copier: Starting module copy from server ${sourceServerId} to server ${gameServerId}...`);
    
        try {
            // Get all modules from source server
            const sourceModulesResponse = await takaro.module.moduleInstallationsControllerGetInstalledModules({
                filters: {
                    gameserverId: [sourceServerId]
                }
            });
    
            // Check if we got any modules back
            if (!sourceModulesResponse.data.data || sourceModulesResponse.data.data.length === 0) {
                console.log(`Module Copier: No modules found on source server ${sourceServerId}. Please check if the server ID is correct.`);
                return;
            }
    
            // Use all modules regardless of enabled status
            const sourceModules = sourceModulesResponse.data.data;
    
            console.log(`Module Copier: Found ${sourceModules.length} modules on source server ${sourceServerId}. Starting to copy...`);
    
            // Get modules installed on target server
            const targetModules = await takaro.module.moduleInstallationsControllerGetInstalledModules({
                filters: { gameserverId: [gameServerId] }
            });
    
            // Create lookup map for faster access
            const existingModuleMap = {};
            if (targetModules.data.data) {
                targetModules.data.data.forEach(module => {
                    existingModuleMap[module.moduleId] = module;
                });
            }
    
            // Track progress
            let installed = 0;
            let updated = 0;
            let skipped = 0;
    
            // Process each module from source server
            for (const sourceModule of sourceModules) {
                try {
                    const { moduleId, versionId, systemConfig, userConfig } = sourceModule;
                    const moduleName = sourceModule.module?.name || "Unknown Module";
    
                    console.log(`Module Copier: Processing module ${moduleName} (${moduleId})`);
    
                    // Check if module already exists on target server
                    if (existingModuleMap[moduleId]) {
                        try {
                            // Only function we know works
                            await takaro.module.moduleInstallationsControllerInstallModule({
                                versionId: versionId,
                                gameServerId: gameServerId,
                                moduleId: moduleId,
                                // Copy configs as JSON strings
                                systemConfig: typeof systemConfig === 'string' ? systemConfig : JSON.stringify(systemConfig || {}),
                                userConfig: typeof userConfig === 'string' ? userConfig : JSON.stringify(userConfig || {})
                            });
    
                            updated++;
                            console.log(`Module Copier: Updated module: ${moduleName}`);
                        } catch (updateError) {
                            console.log(`Module Copier: Error updating module ${moduleName}: ${updateError.message}`);
                            skipped++;
                        }
                    } else {
                        try {
                            // For new installations, don't include moduleId:
                            await takaro.module.moduleInstallationsControllerInstallModule({
                                versionId: versionId,
                                gameServerId: gameServerId,
                                // Remove moduleId parameter
                                systemConfig: typeof systemConfig === 'string' ? systemConfig : JSON.stringify(systemConfig || {}),
                                userConfig: typeof userConfig === 'string' ? userConfig : JSON.stringify(userConfig || {})
                            }); installed++;
                            console.log(`Module Copier: Installed module: ${moduleName}`);
                        } catch (installError) {
                            console.log(`Module Copier: Error installing module ${moduleName}: ${installError.message}`);
                            skipped++;
                        }
                    }
                } catch (error) {
                    skipped++;
                    const moduleName = sourceModule.module?.name || "Unknown Module";
                    console.log(`Module Copier: Error processing module ${moduleName}: ${error.message}`);
                }
            }
    
            console.log(`Module Copier: Module copy completed! Installed: ${installed}, Updated: ${updated}, Skipped: ${skipped}`);
        } catch (error) {
            console.log(`Module Copier: Error copying modules: ${error.message}`);
        }
    }
    
    await main();