storage-transfer-lib
A Rust library for copying objects from one S3-compatible bucket to another using Apache OpenDAL. It preserves object keys, streams data in bounded chunks, and verifies the destination with SHA-256 and supported metadata before counting an object as copied.
The engine recursively lists file objects into a bounded queue. Copy workers share one HTTP concurrency limit across source and destination, including listing, reads, multipart writes, verification, and retries.
Setup
Requires Rust 1.91 or newer and a Tokio runtime. Add these dependencies to your application's Cargo.toml:
[]
= "0.1.1"
= { = "0.59.5", = false, = ["services-s3", "http-transport-reqwest-rustls", "executors-tokio"] }
= { = "1.53.3", = ["macros", "rt", "signal"] }
Copy a bucket on OCI
Use existing source and destination buckets. The credentials need permission to list/read the source and read/write the destination, including multipart operations. Destination reads are required for verification.
For OCI, use a Customer Secret Key access-key/secret-key pair and the namespace's S3 compatibility endpoint. See Oracle's S3 compatibility setup.
Set these environment variables in your application environment:
The following src/main.rs copies all file objects to the same keys in the destination. Both operators cover the bucket root in this example. This example uses the same region and credentials for both buckets; operators can also be built separately for different endpoints or credentials.
use ;
use ;
use ;
async
Run your application with cargo run --release. transfer.jsonl must not already exist. Use a new report path for each run. For a transfer without a report, call engine.run(&cancellation).await instead.
Ctrl+C requests cancellation and waits for the engine to finish its best-effort cleanup. Completed objects remain in place. Active write/close operations can take time to finish under the configured timeout and retry policy. Cleanup errors are ignored and the first task error is returned. Dropping the transfer future or terminating the process cannot guarantee cleanup of unfinished multipart uploads.
Configuration
Create a configuration with TransferConfig::default() and override the fields you need:
| Setting | Default | Meaning |
|---|---|---|
limits.max_queued_objects() |
1024 | Waiting object descriptors; excludes objects being copied and the current listing page |
limits.max_ongoing_http_requests() |
32 | Shared HTTP request limit across both operators in one engine |
operation_timeout |
30 seconds | Timeout for each operation attempt, such as stat or opening a reader/writer |
io_timeout |
30 seconds | Timeout for each I/O attempt, such as reading, writing, closing, or aborting |
max_retries |
2 | Additional attempts after the first attempt; 0 disables retries |
retry_delay |
100 milliseconds | Initial exponential retry delay |
max_retry_delay |
1 second | Maximum retry delay |
Set both concurrency limits with TransferLimits::new(queue_capacity, http_concurrency). Limits must be positive. Durations must be positive and representable as deadlines; max_retry_delay must be at least retry_delay.
The engine installs OpenDAL timeout and retry layers on both operators. HTTP capacity is held through the response body and released before retry backoff. Worker count is derived as min(http_concurrency, 32). Multiple engine instances have separate limits.
Progress and reports
Call engine.subscribe() before starting a run to obtain a tokio::sync::watch::Receiver<TransferProgress>. Use changed().await to observe updates and borrow_and_update() to read the latest counters. Watch receivers retain the latest snapshot rather than every update. Release the borrowed snapshot before awaiting again.
Progress includes listed_objects, copied_objects, and copied_bytes. Copied counters advance only after destination verification succeeds. A successful run returns the final TransferProgress; after an error, the receiver still exposes partial progress.
run_with_report writes JSONL records incrementally for attempted objects, followed by a final progress/error record when the run returns. For example:
{"type":"object","path":"nested/example.bin","bytes":17,"status":"copied","error":null}
{"type":"finished","progress":{"listed_objects":1,"copied_objects":1,"copied_bytes":17},"error":null}
Object statuses are copied, failed, or cancelled. A failed run can leave listed objects unattempted; the report is not a complete bucket inventory or a resume database. Process termination can leave a partial report without a finished record.
Directory-scoped transfers
Set the source and destination S3 operator roots independently:
use S3;
let source = S3default.root;
let destination = S3default.root;
Configure each builder's bucket, endpoint, region and credentials as in the OCI
example, then pass the operators to TransferEngine::new as usual.
input/raw/nested/a.csv maps to brightdata/nested/a.csv: the source directory
is stripped and the destination directory is prepended. Listing is constrained
to input/raw/, so input/raw-other/ is outside the transfer. Empty prefixes
select bucket roots. Directory roots use OpenDAL's normal root normalization;
this library adds no filesystem-style prefix validation.
The caller chooses the source and destination buckets. The library does not infer
bucket identity from operator names or compare directory overlap. Create-only
writes, conditional source reads, cancellation and destination verification also
apply to scoped transfers. Report path stays relative to the configured source root;
new source_path and destination_path fields contain complete bucket-relative
keys for auditing.