init

Function init 

Source
pub async fn init(
    source_url: &str,
    target_url: &str,
    skip_confirmation: bool,
    filter: ReplicationFilter,
    drop_existing: bool,
    enable_sync: bool,
    allow_resume: bool,
    force_local: bool,
) -> Result<()>
Expand description

Initial replication command for snapshot schema and data copy

Performs a full database dump and restore from source to target in steps:

  1. Estimates database sizes and replication times
  2. Prompts for confirmation (unless skip_confirmation is true)
  3. Dumps global objects (roles, tablespaces) from source
  4. Restores global objects to target
  5. Discovers all user databases on source
  6. Replicates each database (schema and data)
  7. Optionally sets up continuous logical replication (if enable_sync is true)

Uses temporary directory for dump files, which is automatically cleaned up.

§Arguments

  • source_url - PostgreSQL connection string for source (Neon) database
  • target_url - PostgreSQL connection string for target (Seren) database
  • skip_confirmation - Skip the size estimation and confirmation prompt
  • filter - Database and table filtering rules
  • drop_existing - Drop existing databases on target before copying
  • enable_sync - Set up continuous logical replication after snapshot (default: true)
  • allow_resume - Resume from checkpoint if available (default: true)
  • force_local - If true, –local was explicitly set (fail instead of fallback to remote)

§Returns

Returns Ok(()) if replication completes successfully.

§Errors

This function will return an error if:

  • Cannot create temporary directory
  • Global objects dump/restore fails
  • Cannot connect to source database
  • Database discovery fails
  • Any database replication fails
  • User declines confirmation prompt
  • Logical replication setup fails (if enable_sync is true)

§Examples

// With confirmation prompt and automatic sync (default)
init(
    "postgresql://user:pass@neon.tech/sourcedb",
    "postgresql://user:pass@seren.example.com/targetdb",
    false,
    ReplicationFilter::empty(),
    false,
    true,   // Enable continuous replication
    true,   // Allow resume
    false,  // Not forcing local execution
).await?;

// Snapshot only (no continuous replication)
init(
    "postgresql://user:pass@neon.tech/sourcedb",
    "postgresql://user:pass@seren.example.com/targetdb",
    true,
    ReplicationFilter::empty(),
    false,
    false,  // Disable continuous replication
    true,   // Allow resume
    true,   // Force local execution (--local flag)
).await?;