Skip to main content
Glama

ssh_backup_restore

Restore server backups via SSH to recover databases or files using specified backup IDs and connection parameters.

Instructions

Restore from a backup on remote server

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
serverYesServer name
backupIdYesBackup ID to restore
databaseNoTarget database name (for db restores)
dbUserNoDatabase user
dbPasswordNoDatabase password
dbHostNoDatabase host (default: localhost)
dbPortNoDatabase port
targetPathNoTarget path for files restore (default: /)
backupDirNoBackup directory (default: /var/backups/ssh-manager)

Implementation Reference

  • Registration of the 'ssh_backup_restore' tool in the 'backup' tool group in the central tool registry used for configuration and validation.
    // Backup group (4 tools) - Backup and restore operations backup: [ 'ssh_backup_create', 'ssh_backup_list', 'ssh_backup_restore', 'ssh_backup_schedule' ],
  • Core helper functions for building restore commands for different backup types (MySQL, PostgreSQL, MongoDB, files). These functions generate the shell commands executed remotely via SSH for the ssh_backup_restore tool implementation.
    */ export function buildRestoreCommand(backupType, backupFile, options = {}) { switch (backupType) { case BACKUP_TYPES.MYSQL: return buildMySQLRestoreCommand(backupFile, options); case BACKUP_TYPES.POSTGRESQL: return buildPostgreSQLRestoreCommand(backupFile, options); case BACKUP_TYPES.MONGODB: return buildMongoDBRestoreCommand(backupFile, options); case BACKUP_TYPES.FILES: return buildFilesRestoreCommand(backupFile, options); default: throw new Error(`Unknown backup type: ${backupType}`); } } /** * Build MySQL restore command */ function buildMySQLRestoreCommand(backupFile, options) { const { database, user, password, host = 'localhost', port = 3306 } = options; let command = ''; // Decompress if needed if (backupFile.endsWith('.gz')) { command = `gunzip -c "${backupFile}" | `; } else { command = `cat "${backupFile}" | `; } command += 'mysql'; // Connection parameters if (user) command += ` -u${user}`; if (password) command += ` -p'${password}'`; if (host) command += ` -h ${host}`; if (port) command += ` -P ${port}`; if (database) command += ` ${database}`; return command; } /** * Build PostgreSQL restore command */ function buildPostgreSQLRestoreCommand(backupFile, options) { const { database, user, password, host = 'localhost', port = 5432 } = options; let command = ''; if (password) { command = `PGPASSWORD='${password}' `; } command += 'pg_restore'; // Connection parameters if (user) command += ` -U ${user}`; if (host) command += ` -h ${host}`; if (port) command += ` -p ${port}`; if (database) command += ` -d ${database}`; // Restore options command += ' --clean --if-exists'; // Handle compressed files if (backupFile.endsWith('.gz')) { command = `gunzip -c "${backupFile}" | ${command}`; } else { command += ` "${backupFile}"`; } return command; } /** * Build MongoDB restore command */ function buildMongoDBRestoreCommand(backupFile, options) { const { database, user, password, host = 'localhost', port = 27017, drop = true } = options; let command = ''; // Extract if compressed if (backupFile.endsWith('.tar.gz')) { const extractDir = backupFile.replace('.tar.gz', ''); command = `tar -xzf "${backupFile}" -C "$(dirname ${backupFile})" && `; command += 'mongorestore'; if (drop) command += ' --drop'; if (host) command += ` --host ${host}`; if (port) command += ` --port ${port}`; if (user) command += ` --username ${user}`; if (password) command += ` --password '${password}'`; command += ` "${extractDir}"`; command += ` && rm -rf "${extractDir}"`; } else { command = 'mongorestore'; if (drop) command += ' --drop'; if (host) command += ` --host ${host}`; if (port) command += ` --port ${port}`; if (user) command += ` --username ${user}`; if (password) command += ` --password '${password}'`; command += ` "${backupFile}"`; } return command; } /** * Build files restore command */ function buildFilesRestoreCommand(backupFile, options) { const { targetPath = '/' } = options; let command = 'tar'; // Auto-detect compression if (backupFile.endsWith('.gz') || backupFile.endsWith('.tgz')) { command += ' -xzf'; } else { command += ' -xf'; } command += ` "${backupFile}"`; command += ` -C "${targetPath}"`; return command; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/bvisible/mcp-ssh-manager'

If you have feedback or need assistance with the MCP directory API, please join our Discord server