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:
- Estimates database sizes and replication times
- Prompts for confirmation (unless skip_confirmation is true)
- Dumps global objects (roles, tablespaces) from source
- Restores global objects to target
- Discovers all user databases on source
- Replicates each database (schema and data)
- 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) databasetarget_url- PostgreSQL connection string for target (Seren) databaseskip_confirmation- Skip the size estimation and confirmation promptfilter- Database and table filtering rulesdrop_existing- Drop existing databases on target before copyingenable_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?;