mcp-ssh-manager 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/.claude/settings.local.json +87 -0
  2. package/.flake8 +15 -0
  3. package/.hooks-config.json +131 -0
  4. package/.pre-commit-config.yaml +105 -0
  5. package/CHANGELOG.md +137 -0
  6. package/CLAUDE.md +190 -0
  7. package/CONTRIBUTING.md +114 -0
  8. package/DESCRIPTION +1 -0
  9. package/INSTALLATION.md +180 -0
  10. package/LICENSE +21 -0
  11. package/QUICKSTART.md +77 -0
  12. package/README.md +718 -0
  13. package/cli/README.md +286 -0
  14. package/cli/build.sh +199 -0
  15. package/cli/commands/server.sh +284 -0
  16. package/cli/demo.sh +107 -0
  17. package/cli/install.sh +164 -0
  18. package/cli/lib/colors.sh +174 -0
  19. package/cli/lib/config.sh +284 -0
  20. package/cli/lib/menu.sh +430 -0
  21. package/cli/migrate.sh +168 -0
  22. package/cli/ssh-manager +525 -0
  23. package/docs/ALIASES_AND_HOOKS.md +285 -0
  24. package/docs/BACKUP_GUIDE.md +500 -0
  25. package/docs/DEPLOYMENT_GUIDE.md +241 -0
  26. package/docs/SEO.md +257 -0
  27. package/examples/backup-workflow.js +481 -0
  28. package/examples/claude-code-config.example.json +40 -0
  29. package/examples/codex-ssh-config.example.toml +71 -0
  30. package/examples/deploy-workflow.py +183 -0
  31. package/glama.json +6 -0
  32. package/package.json +85 -0
  33. package/profiles/README.md +40 -0
  34. package/profiles/default.json +52 -0
  35. package/profiles/docker.json +62 -0
  36. package/profiles/frappe.json +107 -0
  37. package/profiles/nodejs.json +63 -0
  38. package/pyproject.toml +17 -0
  39. package/scripts/setup-hooks.sh +60 -0
  40. package/scripts/validate.sh +76 -0
  41. package/src/backup-manager.js +469 -0
  42. package/src/command-aliases.js +151 -0
  43. package/src/config-loader.js +281 -0
  44. package/src/database-manager.js +555 -0
  45. package/src/deploy-helper.js +176 -0
  46. package/src/health-monitor.js +428 -0
  47. package/src/hooks-system.js +327 -0
  48. package/src/index.js +4499 -0
  49. package/src/logger.js +276 -0
  50. package/src/profile-loader.js +187 -0
  51. package/src/server-aliases.js +150 -0
  52. package/src/server-groups.js +409 -0
  53. package/src/session-manager.js +410 -0
  54. package/src/ssh-key-manager.js +378 -0
  55. package/src/ssh-manager.js +435 -0
  56. package/src/tunnel-manager.js +576 -0
@@ -0,0 +1,500 @@
1
+ # Backup & Restore Guide
2
+
3
+ Complete guide for using the MCP SSH Manager backup and restore system.
4
+
5
+ ## 🎯 Overview
6
+
7
+ The backup system provides automated backup and restore capabilities for:
8
+ - **MySQL** databases
9
+ - **PostgreSQL** databases
10
+ - **MongoDB** databases
11
+ - **Files and directories**
12
+ - **Scheduled automatic backups**
13
+
14
+ All backups are compressed by default, include metadata for easy management, and support automatic retention policies.
15
+
16
+ ## 📋 Available Tools
17
+
18
+ ### 1. `ssh_backup_create` - Create Backup
19
+
20
+ Create a one-time backup of a database or files.
21
+
22
+ **Parameters:**
23
+ - `server` (string, required) - Server name
24
+ - `type` (enum, required) - Backup type: `mysql`, `postgresql`, `mongodb`, `files`
25
+ - `name` (string, required) - Backup name (e.g., "production", "app-data")
26
+ - `database` (string, optional*) - Database name (*required for db types)
27
+ - `dbUser` (string, optional) - Database username
28
+ - `dbPassword` (string, optional) - Database password
29
+ - `dbHost` (string, optional) - Database host (default: localhost)
30
+ - `dbPort` (number, optional) - Database port
31
+ - `paths` (array, optional*) - File paths to backup (*required for files type)
32
+ - `exclude` (array, optional) - Patterns to exclude from backup
33
+ - `backupDir` (string, optional) - Backup directory (default: `/var/backups/ssh-manager`)
34
+ - `retention` (number, optional) - Retention period in days (default: 7)
35
+ - `compress` (boolean, optional) - Compress backup (default: true)
36
+
37
+ **Returns:**
38
+ ```json
39
+ {
40
+ "success": true,
41
+ "backup_id": "mysql_production_2025-10-01T10-30-45-000Z_abc123de",
42
+ "type": "mysql",
43
+ "size": 52428800,
44
+ "size_human": "50.00 MB",
45
+ "location": "/var/backups/ssh-manager/mysql_production_2025-10-01T10-30-45-000Z_abc123de.gz",
46
+ "metadata_path": "/var/backups/ssh-manager/mysql_production_2025-10-01T10-30-45-000Z_abc123de.meta.json",
47
+ "created_at": "2025-10-01T10:30:45.000Z",
48
+ "retention_days": 7
49
+ }
50
+ ```
51
+
52
+ ### 2. `ssh_backup_list` - List Backups
53
+
54
+ List all available backups on a server.
55
+
56
+ **Parameters:**
57
+ - `server` (string, required) - Server name
58
+ - `type` (enum, optional) - Filter by type: `mysql`, `postgresql`, `mongodb`, `files`
59
+ - `backupDir` (string, optional) - Backup directory (default: `/var/backups/ssh-manager`)
60
+
61
+ **Returns:**
62
+ ```json
63
+ {
64
+ "success": true,
65
+ "count": 3,
66
+ "backups": [
67
+ {
68
+ "id": "mysql_production_2025-10-01T10-30-45-000Z_abc123de",
69
+ "type": "mysql",
70
+ "created_at": "2025-10-01T10:30:45.000Z",
71
+ "database": "myapp_prod",
72
+ "paths": [],
73
+ "size": 52428800,
74
+ "size_human": "50.00 MB",
75
+ "compressed": true,
76
+ "retention_days": 7,
77
+ "status": "completed"
78
+ }
79
+ ]
80
+ }
81
+ ```
82
+
83
+ ### 3. `ssh_backup_restore` - Restore Backup
84
+
85
+ Restore from a previous backup.
86
+
87
+ **Parameters:**
88
+ - `server` (string, required) - Server name
89
+ - `backupId` (string, required) - Backup ID to restore
90
+ - `database` (string, optional) - Target database name (overrides original)
91
+ - `dbUser` (string, optional) - Database username
92
+ - `dbPassword` (string, optional) - Database password
93
+ - `dbHost` (string, optional) - Database host
94
+ - `dbPort` (number, optional) - Database port
95
+ - `targetPath` (string, optional) - Target path for files restore (default: /)
96
+ - `backupDir` (string, optional) - Backup directory
97
+
98
+ **Returns:**
99
+ ```json
100
+ {
101
+ "success": true,
102
+ "backup_id": "mysql_production_2025-10-01T10-30-45-000Z_abc123de",
103
+ "type": "mysql",
104
+ "restored_at": "2025-10-01T14:15:30.000Z",
105
+ "original_created": "2025-10-01T10:30:45.000Z",
106
+ "database": "myapp_prod",
107
+ "paths": []
108
+ }
109
+ ```
110
+
111
+ ### 4. `ssh_backup_schedule` - Schedule Automatic Backups
112
+
113
+ Schedule recurring backups using cron.
114
+
115
+ **Parameters:**
116
+ - `server` (string, required) - Server name
117
+ - `schedule` (string, required) - Cron schedule (e.g., `"0 2 * * *"` for daily at 2 AM)
118
+ - `type` (enum, required) - Backup type
119
+ - `name` (string, required) - Backup name
120
+ - `database` (string, optional) - Database name (for db types)
121
+ - `paths` (array, optional) - Paths to backup (for files type)
122
+ - `retention` (number, optional) - Retention in days (default: 7)
123
+
124
+ **Returns:**
125
+ ```json
126
+ {
127
+ "success": true,
128
+ "name": "production",
129
+ "schedule": "0 2 * * *",
130
+ "type": "mysql",
131
+ "database": "myapp_prod",
132
+ "paths": [],
133
+ "retention_days": 7,
134
+ "script_path": "/usr/local/bin/ssh-manager-backup-production.sh",
135
+ "next_run": "Use crontab -l to see next run time"
136
+ }
137
+ ```
138
+
139
+ ## 💡 Usage Examples
140
+
141
+ ### MySQL Backup
142
+
143
+ ```
144
+ "Create a MySQL backup of the production database"
145
+ ```
146
+
147
+ The AI will use:
148
+ ```json
149
+ {
150
+ "server": "production",
151
+ "type": "mysql",
152
+ "name": "prod-db",
153
+ "database": "myapp_prod",
154
+ "dbUser": "backup_user",
155
+ "dbPassword": "secure_password"
156
+ }
157
+ ```
158
+
159
+ ### PostgreSQL Backup with Custom Retention
160
+
161
+ ```
162
+ "Backup PostgreSQL database and keep it for 30 days"
163
+ ```
164
+
165
+ ```json
166
+ {
167
+ "server": "staging",
168
+ "type": "postgresql",
169
+ "name": "staging-db",
170
+ "database": "myapp_staging",
171
+ "retention": 30
172
+ }
173
+ ```
174
+
175
+ ### Files Backup
176
+
177
+ ```
178
+ "Backup the /var/www/html directory, excluding cache and logs"
179
+ ```
180
+
181
+ ```json
182
+ {
183
+ "server": "web01",
184
+ "type": "files",
185
+ "name": "website-files",
186
+ "paths": ["/var/www/html"],
187
+ "exclude": ["cache/*", "*.log"]
188
+ }
189
+ ```
190
+
191
+ ### List All MySQL Backups
192
+
193
+ ```
194
+ "List all MySQL backups on production server"
195
+ ```
196
+
197
+ ```json
198
+ {
199
+ "server": "production",
200
+ "type": "mysql"
201
+ }
202
+ ```
203
+
204
+ ### Restore Specific Backup
205
+
206
+ ```
207
+ "Restore backup mysql_production_2025-10-01T10-30-45-000Z_abc123de"
208
+ ```
209
+
210
+ ```json
211
+ {
212
+ "server": "production",
213
+ "backupId": "mysql_production_2025-10-01T10-30-45-000Z_abc123de"
214
+ }
215
+ ```
216
+
217
+ ### Schedule Daily Backup at 2 AM
218
+
219
+ ```
220
+ "Schedule daily MySQL backup of production database at 2 AM"
221
+ ```
222
+
223
+ ```json
224
+ {
225
+ "server": "production",
226
+ "schedule": "0 2 * * *",
227
+ "type": "mysql",
228
+ "name": "daily-prod",
229
+ "database": "myapp_prod",
230
+ "retention": 7
231
+ }
232
+ ```
233
+
234
+ ## 🔧 Cron Schedule Format
235
+
236
+ Common cron schedule examples:
237
+
238
+ | Schedule | Description |
239
+ |----------|-------------|
240
+ | `0 2 * * *` | Daily at 2:00 AM |
241
+ | `0 */6 * * *` | Every 6 hours |
242
+ | `0 0 * * 0` | Weekly on Sunday at midnight |
243
+ | `0 3 1 * *` | Monthly on the 1st at 3:00 AM |
244
+ | `0 1 * * 1-5` | Weekdays at 1:00 AM |
245
+ | `*/30 * * * *` | Every 30 minutes |
246
+
247
+ ## 🗄️ Database-Specific Notes
248
+
249
+ ### MySQL
250
+
251
+ - Uses `mysqldump` with `--single-transaction` for consistent backups
252
+ - Includes routines and triggers
253
+ - No table locking for InnoDB tables
254
+ - Compressed with gzip
255
+
256
+ **Connection options:**
257
+ - Default host: `localhost`
258
+ - Default port: `3306`
259
+ - Supports password-based auth (not recommended for production)
260
+ - Tip: Use SSH keys for secure automation
261
+
262
+ ### PostgreSQL
263
+
264
+ - Uses `pg_dump` with custom format
265
+ - Includes `--clean` and `--if-exists` for safe restores
266
+ - Compressed with gzip
267
+ - Uses `PGPASSWORD` environment variable
268
+
269
+ **Connection options:**
270
+ - Default host: `localhost`
271
+ - Default port: `5432`
272
+ - Use `.pgpass` file for passwordless automation
273
+
274
+ ### MongoDB
275
+
276
+ - Uses `mongodump` for database dumps
277
+ - Creates directory structure, then archives with tar
278
+ - Compressed with gzip
279
+ - Supports authentication
280
+
281
+ **Connection options:**
282
+ - Default host: `localhost`
283
+ - Default port: `27017`
284
+ - Tip: Use `--authenticationDatabase` if needed
285
+
286
+ ## 📁 File Backup Notes
287
+
288
+ - Uses `tar` with gzip compression
289
+ - Supports multiple paths in single backup
290
+ - Exclude patterns use tar's `--exclude` syntax
291
+ - Preserves permissions and ownership
292
+ - Follows symlinks by default
293
+
294
+ **Exclude pattern examples:**
295
+ - `*.log` - All log files
296
+ - `cache/*` - Everything in cache directories
297
+ - `node_modules/` - Node modules directory
298
+ - `*.tmp` - All temporary files
299
+
300
+ ## 🔄 Hooks Integration
301
+
302
+ The backup system integrates with the hooks system:
303
+
304
+ ### Available Hooks
305
+
306
+ 1. **pre-backup** - Before backup starts
307
+ ```javascript
308
+ // Context: { server, type, database, paths }
309
+ ```
310
+
311
+ 2. **post-backup** - After backup completes
312
+ ```javascript
313
+ // Context: { server, backupId, type, size, success, error }
314
+ ```
315
+
316
+ 3. **pre-restore** - Before restore starts
317
+ ```javascript
318
+ // Context: { server, backupId, type, database }
319
+ ```
320
+
321
+ 4. **post-restore** - After restore completes
322
+ ```javascript
323
+ // Context: { server, backupId, type, success, error }
324
+ ```
325
+
326
+ ### Example Hook: Slack Notification
327
+
328
+ Create `.ssh-manager/hooks/post-backup.sh`:
329
+
330
+ ```bash
331
+ #!/bin/bash
332
+ # Send Slack notification after backup
333
+
334
+ if [ "$HOOK_success" = "true" ]; then
335
+ curl -X POST -H 'Content-type: application/json' \
336
+ --data "{\"text\":\"✅ Backup completed: $HOOK_backupId ($HOOK_size_human)\"}" \
337
+ https://hooks.slack.com/services/YOUR/WEBHOOK/URL
338
+ fi
339
+ ```
340
+
341
+ ## ⚙️ Best Practices
342
+
343
+ ### 1. Security
344
+
345
+ - **Never store passwords in code** - Use environment variables or `.env` files
346
+ - **Use SSH keys** for automated backups instead of passwords
347
+ - **Restrict backup directory permissions**: `chmod 700 /var/backups/ssh-manager`
348
+ - **Encrypt sensitive backups** - Add GPG encryption for critical data
349
+
350
+ ### 2. Retention
351
+
352
+ - **Development**: 3-7 days retention
353
+ - **Staging**: 7-14 days retention
354
+ - **Production**: 30+ days retention
355
+ - **Compliance**: Consider regulatory requirements (GDPR, HIPAA, etc.)
356
+
357
+ ### 3. Testing
358
+
359
+ - **Test restores regularly** - Monthly restore tests minimum
360
+ - **Verify backup integrity** - Check file sizes and metadata
361
+ - **Document restore procedures** - Keep runbooks updated
362
+ - **Monitor backup success** - Set up alerts for failures
363
+
364
+ ### 4. Storage
365
+
366
+ - **Monitor disk space** - Ensure adequate space for retention period
367
+ - **Use compression** - Saves 60-80% space typically
368
+ - **Consider remote storage** - Sync backups to S3/cloud storage
369
+ - **Implement 3-2-1 rule** - 3 copies, 2 different media, 1 offsite
370
+
371
+ ### 5. Scheduling
372
+
373
+ - **Avoid peak hours** - Schedule during low-traffic periods
374
+ - **Stagger backups** - Don't backup all servers simultaneously
375
+ - **Consider backup windows** - Large databases may take hours
376
+ - **Monitor backup duration** - Track and optimize slow backups
377
+
378
+ ## 🚨 Troubleshooting
379
+
380
+ ### Backup Fails with "Permission Denied"
381
+
382
+ **Solution:** Ensure backup directory exists and is writable
383
+
384
+ ```bash
385
+ sudo mkdir -p /var/backups/ssh-manager
386
+ sudo chown $(whoami):$(whoami) /var/backups/ssh-manager
387
+ sudo chmod 700 /var/backups/ssh-manager
388
+ ```
389
+
390
+ ### MySQL Backup Shows "Access Denied"
391
+
392
+ **Solution:** Check user permissions
393
+
394
+ ```sql
395
+ GRANT SELECT, LOCK TABLES, SHOW VIEW ON myapp_prod.* TO 'backup_user'@'localhost';
396
+ FLUSH PRIVILEGES;
397
+ ```
398
+
399
+ ### Restore Fails with "Database Does Not Exist"
400
+
401
+ **Solution:** Create target database first
402
+
403
+ ```sql
404
+ CREATE DATABASE myapp_restored CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
405
+ ```
406
+
407
+ ### Scheduled Backup Not Running
408
+
409
+ **Solution:** Check cron logs and permissions
410
+
411
+ ```bash
412
+ # View cron logs
413
+ sudo tail -f /var/log/syslog | grep CRON
414
+
415
+ # Check if script is executable
416
+ ls -la /usr/local/bin/ssh-manager-backup-*.sh
417
+
418
+ # Test script manually
419
+ sudo /usr/local/bin/ssh-manager-backup-production.sh
420
+ ```
421
+
422
+ ### Backup Size Too Large
423
+
424
+ **Solutions:**
425
+ - Verify compression is enabled (`compress: true`)
426
+ - Exclude unnecessary tables or files
427
+ - Consider incremental backups (manual implementation)
428
+ - Archive old data before backup
429
+
430
+ ## 📊 Monitoring
431
+
432
+ ### Check Backup Status
433
+
434
+ ```
435
+ "List all backups on production server"
436
+ ```
437
+
438
+ ### View Cron Jobs
439
+
440
+ ```
441
+ "Execute 'crontab -l' on production"
442
+ ```
443
+
444
+ ### Check Disk Space
445
+
446
+ ```
447
+ "Execute 'df -h /var/backups' on production"
448
+ ```
449
+
450
+ ### Calculate Total Backup Size
451
+
452
+ ```
453
+ "Execute 'du -sh /var/backups/ssh-manager' on production"
454
+ ```
455
+
456
+ ## 🔗 Related Documentation
457
+
458
+ - [Deployment Guide](DEPLOYMENT_GUIDE.md) - Deployment workflows
459
+ - [Aliases & Hooks](ALIASES_AND_HOOKS.md) - Automation and hooks
460
+ - [Main README](../README.md) - Getting started
461
+
462
+ ## ⚡ Quick Reference
463
+
464
+ ### Daily Backup Workflow
465
+
466
+ 1. **Create backup before deployment:**
467
+ ```
468
+ "Backup production MySQL database before deployment"
469
+ ```
470
+
471
+ 2. **Deploy changes:**
472
+ ```
473
+ "Deploy latest code to production"
474
+ ```
475
+
476
+ 3. **If rollback needed:**
477
+ ```
478
+ "List MySQL backups and restore the latest one"
479
+ ```
480
+
481
+ ### Disaster Recovery
482
+
483
+ 1. **List available backups:**
484
+ ```
485
+ "List all backups on production server"
486
+ ```
487
+
488
+ 2. **Restore most recent backup:**
489
+ ```
490
+ "Restore backup [backup-id-here]"
491
+ ```
492
+
493
+ 3. **Verify restoration:**
494
+ ```
495
+ "Run database integrity check on production"
496
+ ```
497
+
498
+ ---
499
+
500
+ **Need help?** Open an issue on [GitHub](https://github.com/bvisible/mcp-ssh-manager/issues)