Import, export, backup, and restore
Bayesian SSH provides two ways to move data in and out:
- Import and export: Transfer connection configurations and metadata in human-readable formats (JSON, OpenSSH config, or TOML for exports), with optional passphrase encryption.
- Backup and restore: Capture or restore a complete SQLite database snapshot, including session history, usage statistics, aliases, and tags.
Import connections
Section titled “Import connections”Use bssh import to bring existing hosts into your Bayesian SSH database.
Import an OpenSSH configuration file
Section titled “Import an OpenSSH configuration file”By default, bssh import reads your local ~/.ssh/config file (or the path set in your config.json under ssh_config_path):
bssh import✅ Successfully imported 14 connection(s) from SSH configTo specify an alternative configuration file:
bssh import -f ~/.ssh/config.d/workKey behaviors during SSH config import:
- Host attributes: Parses
Host,HostName,User,Port, andIdentityFile. - Automatic tagging: Every imported host receives the
importedtag so you can filter or manage them easily. - Idempotent: If a connection with the same name already exists in your database,
bsshskips it without error and preserves your existing entry. - Ignore bastions: To import hosts as direct connections rather than inheriting the configured default bastion, pass
--no-bastion:
bssh import --no-bastionImport an encrypted JSON backup
Section titled “Import an encrypted JSON backup”If you previously exported connections using bssh export --passphrase, import them by providing the file path and passphrase:
bssh import -f hosts-backup.enc --passphrase "correct horse battery staple"🔓 Decrypting import file with passphrase...✅ Imported 8 connection(s) from JSON backup (2 already existed).Export connections
Section titled “Export connections”Use bssh export to share host lists, generate OpenSSH configs, or create encrypted backups.
# Export all connections as JSON to stdoutbssh export
# Export to a filebssh export -o hosts.jsonExport formats
Section titled “Export formats”Bayesian SSH supports three export formats via the --format flag:
# Export as JSON (default)bssh export --format json -o hosts.json
# Export as TOMLbssh export --format toml -o hosts.toml
# Export as standard OpenSSH configbssh export --format ssh-config -o ~/.ssh/config.d/bssh-hosts| Format | Flag | Description |
|---|---|---|
json |
--format json |
Full JSON array of connection models (default). |
toml |
--format toml |
TOML document containing [[connections]] tables. |
ssh-config |
--format ssh-config |
Standard OpenSSH format (Host, HostName, User, Port, IdentityFile, and ProxyCommand for bastions). |
Filter by tag
Section titled “Filter by tag”To export only hosts matching a specific tag, use -t or --tag:
bssh export -t prod -o prod-hosts.jsonEncrypt exports with a passphrase
Section titled “Encrypt exports with a passphrase”To protect exported connection details, supply -p or --passphrase alongside -o:
bssh export -o hosts-backup.enc --passphrase "correct horse battery staple"🔒 Encrypting export with passphrase...✅ Exported 28 connections to hosts-backup.encCryptographic design
Section titled “Cryptographic design”Encrypted exports use authenticated encryption to ensure both confidentiality and integrity:
- Key derivation: Argon2id with 64 MiB memory, 3 iterations, and 1 lane to derive a 256-bit encryption key from your passphrase.
- Authenticated cipher: AES-256-GCM with a 12-byte random nonce and a 16-byte authentication tag.
- Payload format: A
BSSHmagic header followed by a version byte (0x02), 16-byte salt, 12-byte nonce, and the ciphertext with appended GCM authentication tag. - Safe write: Files are written to a temporary file with strict
0600permissions (-rw-------) and renamed atomically over the destination.
Database backup
Section titled “Database backup”While bssh export serializes connection definitions, bssh backup captures the entire SQLite database, including session history, ranking weights, and aliases.
bssh backup✅ Database successfully backed up to: /home/user/.local/share/bayesian-ssh/backups/backup-2026-10-23-093000.dbBackup destination
Section titled “Backup destination”By default, backups are written to a backups/ subdirectory inside your environment folder, named with a timestamp: backup-YYYY-MM-DD-HHMMSS.db.
To choose a specific destination file:
bssh backup -o ~/backups/bssh-snapshot.dbThe destination file is created with 0600 permissions (-rw-------) and bssh backup refuses to overwrite an existing file.
Database restore
Section titled “Database restore”Use bssh restore to replace your active database with a previously created backup snapshot.
bssh restore ~/backups/bssh-snapshot.db⚠️ WARNING: This will replace your current database with: ~/backups/bssh-snapshot.db Your existing database will be safely backed up first.
Are you sure you want to restore? [y/N] y✅ Database successfully restored from: ~/backups/bssh-snapshot.dbTo skip the confirmation prompt in scripts, pass -f or --force:
bssh restore ~/backups/bssh-snapshot.db -fSafety and validation guarantees
Section titled “Safety and validation guarantees”- Integrity check: Before touching your active database,
bsshverifies that the target file is an intact SQLite database containing the required Bayesian SSH schema tables. - Pre-restore snapshot: If your existing database file exists,
bsshautomatically takes an internal safety backup (VACUUM INTO) before overwriting anything. - Atomic replace: The restore is performed by copying into a temporary
0600file and atomically renaming it into place. - Sidecar cleanup: Stale SQLite write-ahead log files (
-wal,-shm, and-journal) from the old database are cleanly removed so they cannot corrupt the restored file. - Automatic migration: When the restored database is opened,
bsshautomatically runs any pending schema migrations so that backups from older versions are upgraded seamlessly.