Importing Secrets
The import command restores encrypted secrets from an export archive. This is useful for disaster recovery, setting up new machines, or migrating projects.
Prerequisites
Section titled “Prerequisites”Before importing, ensure you have:
- An export archive created with
kanuka secrets export - Your private key available (required to decrypt after import)
- Write access to the project directory
Importing an archive
Section titled “Importing an archive”To import secrets from an archive:
kanuka secrets import kanuka-secrets-2024-01-15.tar.gzIf the project already has a .kanuka directory, you’ll be prompted to choose
how to handle conflicts:
Importing secrets...
Found existing .kanuka directory. How do you want to proceed? [m] Merge - Add new files, keep existing [r] Replace - Delete existing, use backup [c] Cancel
Choice:Merge vs Replace
Section titled “Merge vs Replace”Merge mode
Section titled “Merge mode”Merge mode adds files from the archive that don’t exist locally, while keeping existing files intact:
kanuka secrets import backup.tar.gz --mergeUse merge when:
- You want to add missing files from a backup
- You have local changes you want to preserve
- You’re combining secrets from multiple sources
Example output:
Importing files: .kanuka/config.toml (skipped - exists) .kanuka/public_keys/user1-uuid.pub (skipped - exists) .kanuka/public_keys/user3-uuid.pub (added) .env.kanuka (skipped - exists) config/.env.production.kanuka (added)
Summary: 2 files added 3 files skipped (already exist)Replace mode
Section titled “Replace mode”Replace mode deletes all existing encrypted files and replaces them with the archive contents:
kanuka secrets import backup.tar.gz --replaceUse replace when:
- You want to fully restore from backup
- Your local state is corrupted or inconsistent
- You’re setting up a clean environment
Previewing import
Section titled “Previewing import”Use the --dry-run flag to see what would happen without making changes:
kanuka secrets import backup.tar.gz --dry-runThis shows:
- Which files would be added
- Which files would be skipped (in merge mode)
- Which files would be deleted (in replace mode)
Import examples
Section titled “Import examples”# Import with interactive prompt for merge/replacekanuka secrets import backup.tar.gz
# Merge new files, keep existingkanuka secrets import backup.tar.gz --merge
# Replace all with backup contentskanuka secrets import backup.tar.gz --replace
# Preview import without making changeskanuka secrets import backup.tar.gz --dry-run
# Preview replace modekanuka secrets import backup.tar.gz --replace --dry-runAfter importing
Section titled “After importing”After a successful import:
- Verify the import - Check that expected files are present
- Decrypt to test - Run
kanuka secrets decryptto verify you have access - Commit if needed - If import added files, commit them
# Verify files were importedkanuka secrets status
# Test decryptionkanuka secrets decrypt
# Commit new files if any were addedgit add .kanuka/ *.kanukagit commit -m "Restore secrets from backup"Disaster recovery workflow
Section titled “Disaster recovery workflow”Complete workflow for restoring from backup:
# 1. Clone fresh repositorygit clone https://github.com/org/project.gitcd project
# 2. Import backupkanuka secrets import /backups/kanuka-secrets-2024-01-15.tar.gz --replace
# 3. Ensure private key is available# (Copy from secure backup or another machine)cp /backup/private-key.pem ~/.kanuka/keys/<project-uuid>.pemchmod 600 ~/.kanuka/keys/<project-uuid>.pem
# 4. Decrypt and verifykanuka secrets decrypt
# 5. Commit restored filesgit add .git commit -m "Restore project secrets from backup"Archive validation
Section titled “Archive validation”Before importing, Kānuka validates the archive structure to ensure it contains the expected files:
- Must contain
.kanuka/config.toml - Must be a valid gzip-compressed tar archive
If validation fails, the import is aborted with an error message.
Next steps
Section titled “Next steps”- Export guide - Create backup archives
- Status command - Verify encryption status
- Doctor command - Check project health after import