Skip to main content

Overview

The import command allows you to import an existing blockchain database file into your Ubu-Block instance. This is useful for:
  • Migrating blockchain data between systems
  • Restoring from backups
  • Joining a network by importing a synced database
  • Development and testing with pre-populated data
The import command is currently in development. The command exists in the CLI but the full import functionality is not yet implemented.

Syntax

ubu-block --config <CONFIG_FILE> import <DATABASE_PATH>

Parameters

path
string
required
Path to the SQLite database file to import. Must be a valid Ubu-Block blockchain database.Example: ./backups/blockchain-2024-03-01.db or /data/imported-chain.db

Current Implementation

As of the current version, the import command displays the path being imported:
ubu-block --config config.toml import ./backup/blockchain.db
Output:
Importing from: ./backup/blockchain.db

Planned Functionality

The full import feature will include:
  • Verify the imported database has the correct schema
  • Check for required tables (blockchain, results, pubkeys, etc.)
  • Validate block integrity and chain continuity
  • Copy blocks from the imported database to your local database
  • Preserve all cryptographic signatures and hashes
  • Maintain block ordering and chain linkage
  • Handle cases where local database already has blocks
  • Option to merge or replace existing data
  • Detect and resolve chain forks
  • Display import progress (blocks imported / total blocks)
  • Show validation status for each block
  • Estimate time remaining

Alternative: Manual Database Copy

Until the import command is fully implemented, you can manually copy blockchain databases:
1

Stop all Ubu-Block processes

Ensure no processes are accessing the database files:
# Stop any running nodes
pkill ubu-block
2

Backup existing database

Create a backup of your current database:
cp data/blockchain.db data/blockchain.db.backup
3

Copy the new database

Replace with the imported database:
cp /path/to/imported/blockchain.db data/blockchain.db
4

Validate the imported chain

Verify the imported database is valid:
ubu-block --config config.toml validate
You should see: Blockchain is valid!
Manual database replacement can lead to data loss if not done carefully. Always create backups before replacing database files.

Use Cases

Joining a Network

Import a synchronized database from a trusted peer:
# Download database from a trusted node
scp trusted-node:/data/blockchain.db ./synced-chain.db

# Import it (once implemented)
ubu-block --config config.toml import ./synced-chain.db

Disaster Recovery

Restore from a backup after system failure:
# Restore from backup
ubu-block --config config.toml import /backups/blockchain-2024-03-01.db

Development

Import test data for development:
# Import test database with sample election data
ubu-block --config config.toml import ./test-data/sample-elections.db

init

Initialize a new blockchain instead of importing

validate

Validate an imported blockchain

query

Query imported blockchain data

Troubleshooting

Error: File not found or path is inaccessibleSolution: Verify the database file exists and you have read permissions:
ls -l /path/to/database.db
Error: Database is not a valid SQLite fileSolution: Verify the file is a valid SQLite database:
sqlite3 /path/to/database.db "SELECT COUNT(*) FROM blockchain;"
Error: Imported database has wrong schema versionSolution: Ensure the database was created by a compatible version of Ubu-Block. Check for migration scripts.

Development Status

Track the implementation of the import command:
  • Current: Command accepts path parameter and displays message
  • Next: Database validation and schema verification
  • Future: Full data migration and conflict resolution
See the GitHub repository for the latest development status.

Build docs developers (and LLMs) love