# Setup Guide
## S3-Compatible Object Storage Configuration
This library ships SQLite WAL frames to any S3-compatible object store. Below are setup instructions for common providers.
### Environment Variables
| `AWS_ACCESS_KEY_ID` | Yes* | Access key for S3 API |
| `AWS_SECRET_ACCESS_KEY` | Yes* | Secret key for S3 API |
| `AWS_REGION` | No | Region (default: `us-east-1`) |
| `AWS_ENDPOINT_URL` | No | Custom endpoint for non-AWS providers |
| `AWS_ALLOW_HTTP` | No | Set to `"1"` for HTTP (non-TLS) endpoints |
\* Not required when using IAM instance profiles or OIDC roles (see below).
### Using `build_s3_store_from_env()`
```rust
use wal_backup::{Config, DurabilityLayer, ObjectStoreBucket, build_s3_store_from_env};
use std::sync::Arc;
use std::time::Duration;
let store = build_s3_store_from_env("my-bucket")?;
let bucket = Arc::new(ObjectStoreBucket::new(Arc::new(store), "my-db".into())?);
let config = Config::new("/data/mydb.db")
.with_poll_interval(Duration::from_millis(100))
.with_snapshot_threshold(50 * 1024 * 1024);
let layer = DurabilityLayer::open(config, bucket).await?;
```
### AWS S3
```bash
export AWS_ACCESS_KEY_ID="AKIA..."
export AWS_SECRET_ACCESS_KEY="wJalrXU..."
export AWS_REGION="us-east-1"
```
Minimal IAM policy:
```json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::my-bucket",
"arn:aws:s3:::my-bucket/*"
]
}
]
}
```
#### IAM Instance Profile (EC2)
No credentials needed. Assign an IAM role to your EC2 instance with the policy above. The default credential chain automatically picks up instance metadata.
#### IAM Roles for Service Accounts (EKS)
Annotate your pod's service account:
```yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: my-app
annotations:
eks.amazonaws.com/role-arn: arn:aws:iam::123456789012:role/my-db-backup
```
### MinIO
```bash
export AWS_ACCESS_KEY_ID="minioadmin"
export AWS_SECRET_ACCESS_KEY="minioadmin"
export AWS_ENDPOINT_URL="http://localhost:9000"
export AWS_ALLOW_HTTP="1"
export AWS_REGION="us-east-1"
```
### Hetzner Object Storage
```bash
export AWS_ACCESS_KEY_ID="YOUR_HETZNER_KEY"
export AWS_SECRET_ACCESS_KEY="YOUR_HETZNER_SECRET"
export AWS_ENDPOINT_URL="https://fsn1.your-objectstorage.com"
export AWS_REGION="eu-central"
```
Hetzner does not bill per request, so `SyncMode::Immediate` (the default) is recommended.
### OVH Object Storage
```bash
export AWS_ACCESS_KEY_ID="YOUR_OVH_KEY"
export AWS_SECRET_ACCESS_KEY="YOUR_OVH_SECRET"
export AWS_ENDPOINT_URL="https://s3.gra.io.cloud.ovh.net"
export AWS_REGION="gra"
```
OVH does not bill per request either; `SyncMode::Immediate` works well.
### Running E2E Tests Against OVH
The E2E tests perform a real end-to-end roundtrip: write data → sync → snapshot → delete local → restore → verify.
**Setup:**
1. Copy the example env file and fill in your credentials:
```bash
cp .env.e2e.example .env.e2e
```
2. Run the E2E tests (sequential to avoid OVH write conflicts):
```bash
source .env.e2e && cargo test --test e2e_tests -- --ignored --test-threads=1
```
Or via the npm script:
```bash
pnpm test:e2e
```
Or via the shell script:
```bash
./scripts/e2e-test.sh
```
**Required env vars (`.env.e2e`):**
| `AWS_ENDPOINT_URL` | OVH endpoint (e.g., `https://s3.uk.io.cloud.ovh.net`) |
| `AWS_REGION` | OVH region (e.g., `uk`) |
| `AWS_ACCESS_KEY_ID` | Your OVH S3 access key |
| `AWS_SECRET_ACCESS_KEY` | Your OVH S3 secret key |
| `E2E_BUCKET_NAME` | Bucket name (e.g., `dracon-master`) |
**Note:** The `.env.e2e` file is in `.gitignore` and never committed. The example template (`.env.e2e.example`) is committed with placeholder values.
### Google Cloud Storage
Use S3-compatible interop:
```bash
export AWS_ACCESS_KEY_ID="GOOG..."
export AWS_SECRET_ACCESS_KEY="..."
export AWS_ENDPOINT_URL="https://storage.googleapis.com"
export AWS_REGION="auto"
```
GCS bills per request. Use `SyncMode::Lazy`:
```rust
let config = Config::new("/data/mydb.db")
.with_sync_mode(SyncMode::Lazy)
.with_poll_interval(Duration::from_secs(5));
```
### DigitalOcean Spaces
```bash
export AWS_ACCESS_KEY_ID="DO..."
export AWS_SECRET_ACCESS_KEY="..."
export AWS_ENDPOINT_URL="https://nyc3.digitaloceanspaces.com"
export AWS_REGION="us-east-1"
```
## Configuration Reference
| `poll_interval` | 100ms | WAL check interval (Lazy mode); fallback wait (Immediate) |
| `snapshot_threshold` | 50 MB | WAL size that triggers a snapshot |
| `snapshot_interval` | 3600s | Minimum time between snapshots |
| `max_frames_per_segment` | 1000 | Max WAL frames per uploaded segment |
| `sync_mode` | Immediate | `Immediate` = ship on write; `Lazy` = periodic |
| `restore_behavior` | UploadLocalIfNewer | Conflict resolution on startup |
| `health_timeout` | 30s | Max time since last sync before `is_healthy()` returns false |
| `immediate_poll_interval` | 50ms | File-change detection interval in Immediate mode (clamped 10–500ms) |
| `sync_timeout` | 10s | Max time `sync_now()` waits for confirmation |
## Restore Behaviors
- **UploadLocalIfNewer**: If local DB is newer than bucket, upload local as snapshot. Otherwise restore from bucket.
- **AlwaysRestoreFromBucket**: Always overwrite local from bucket.
- **ErrorIfConflict**: Return error if local is newer than bucket.
- **Recoverable**: Restore from bucket but proceed even if snapshot checksum fails (e.g., due to bitrot or partial upload). Logs a warning instead of failing. **Use with caution — data corruption may go undetected.**
## Feature Flags
| `encryption` | Yes | AES-256-GCM encryption at rest via `EncryptedBucketStore` |
| `compression` | Yes | Gzip compression via `CompressedBucketStore` |
Both features are enabled by default. To disable them:
```toml
[dependencies]
sqlite-embedded-continuous-wal-backup-to-object-storage = { version = "...", default-features = false }
```
Or selectively re-enable:
```toml
[dependencies]
sqlite-embedded-continuous-wal-backup-to-object-storage = { version = "...", default-features = false, features = ["encryption"] }
```
See [Production Guide](PRODUCTION.md) for usage details and key rotation.