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
| Name | Required | Description | Default |
|---|---|---|---|
| server | Yes | Server name | |
| backupId | Yes | Backup ID to restore | |
| database | No | Target database name (for db restores) | |
| dbUser | No | Database user | |
| dbPassword | No | Database password | |
| dbHost | No | Database host (default: localhost) | |
| dbPort | No | Database port | |
| targetPath | No | Target path for files restore (default: /) | |
| backupDir | No | Backup directory (default: /var/backups/ssh-manager) |
Implementation Reference
- src/tool-registry.js:40-46 (registration)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' ],
- src/backup-manager.js:207-355 (helper)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; }