pub struct SqliteReplicatorConfig {
pub db_path: PathBuf,
pub s3_bucket: String,
pub s3_prefix: String,
pub cache_dir: PathBuf,
pub max_cache_size: u64,
pub auto_restore: bool,
pub snapshot_interval_secs: u64,
}Expand description
Configuration for SQLite WAL-based replication to S3
This configuration controls how the SQLite replicator monitors database changes
and syncs them to S3 for persistence and disaster recovery.
§Example
use zlayer_storage::config::SqliteReplicatorConfig;
use std::path::PathBuf;
let config = SqliteReplicatorConfig {
db_path: PathBuf::from("/var/lib/myapp/data.db"),
s3_bucket: "my-bucket".to_string(),
s3_prefix: "sqlite-backups/myapp/".to_string(),
cache_dir: PathBuf::from("/tmp/zlayer-replicator/cache"),
max_cache_size: 100 * 1024 * 1024, // 100MB
auto_restore: true,
snapshot_interval_secs: 3600,
};Fields§
§db_path: PathBufPath to the SQLite database file to replicate
s3_bucket: StringS3 bucket for storing backups
s3_prefix: StringS3 key prefix for this database’s backups
The replicator will create the following structure under this prefix:
{prefix}/snapshots/- Full database snapshots{prefix}/wal/- WAL segments{prefix}/metadata.json- Replication metadata
cache_dir: PathBufLocal directory for caching WAL segments before upload
This provides network tolerance - if S3 is temporarily unavailable, WAL segments are cached here and uploaded when connectivity returns.
max_cache_size: u64Maximum size of the local cache in bytes
When the cache exceeds this size, the oldest entries will be evicted (and lost if not yet uploaded). Default: 100MB
auto_restore: boolWhether to automatically restore from S3 on startup if local DB is missing
When enabled, the replicator will download and restore the database from S3 if the local file doesn’t exist. Default: true
snapshot_interval_secs: u64Interval between full database snapshots in seconds
Snapshots provide a restore point and allow cleanup of old WAL segments. Default: 3600 (1 hour)
Implementations§
Source§impl SqliteReplicatorConfig
impl SqliteReplicatorConfig
Sourcepub fn new(
db_path: impl Into<PathBuf>,
s3_bucket: impl Into<String>,
s3_prefix: impl Into<String>,
) -> Self
pub fn new( db_path: impl Into<PathBuf>, s3_bucket: impl Into<String>, s3_prefix: impl Into<String>, ) -> Self
Create a new config with the required fields
Sourcepub fn with_cache_dir(self, cache_dir: impl Into<PathBuf>) -> Self
pub fn with_cache_dir(self, cache_dir: impl Into<PathBuf>) -> Self
Set the cache directory
Sourcepub fn with_max_cache_size(self, size: u64) -> Self
pub fn with_max_cache_size(self, size: u64) -> Self
Set the maximum cache size
Sourcepub fn with_auto_restore(self, auto_restore: bool) -> Self
pub fn with_auto_restore(self, auto_restore: bool) -> Self
Set whether to auto-restore on startup
Sourcepub fn with_snapshot_interval(self, interval_secs: u64) -> Self
pub fn with_snapshot_interval(self, interval_secs: u64) -> Self
Set the snapshot interval
Trait Implementations§
Source§impl Clone for SqliteReplicatorConfig
impl Clone for SqliteReplicatorConfig
Source§fn clone(&self) -> SqliteReplicatorConfig
fn clone(&self) -> SqliteReplicatorConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SqliteReplicatorConfig
impl Debug for SqliteReplicatorConfig
Source§impl Default for SqliteReplicatorConfig
impl Default for SqliteReplicatorConfig
Source§impl<'de> Deserialize<'de> for SqliteReplicatorConfig
impl<'de> Deserialize<'de> for SqliteReplicatorConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for SqliteReplicatorConfig
impl RefUnwindSafe for SqliteReplicatorConfig
impl Send for SqliteReplicatorConfig
impl Sync for SqliteReplicatorConfig
impl Unpin for SqliteReplicatorConfig
impl UnsafeUnpin for SqliteReplicatorConfig
impl UnwindSafe for SqliteReplicatorConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more