rcp_tools_rcp/lib.rs
1//! Fast file operations tools - `rcp` (copy) and `rcpd` (remote copy daemon)
2//!
3//! This crate provides high-performance file copying tools that are significantly faster than
4//! traditional tools like `cp` when dealing with large numbers of files.
5//!
6//! # Tools
7//!
8//! ## rcp - File Copy Tool
9//!
10//! The `rcp` tool provides both **local** and **remote** file copying with exceptional performance.
11//!
12//! ### Local Copying
13//!
14//! Basic local file copying, similar to `cp` but optimized for large filesets:
15//!
16//! ```bash
17//! # Basic copy
18//! rcp /source/path /dest/path --progress --summary
19//!
20//! # Copy with metadata preservation
21//! rcp /source /dest --preserve --progress
22//!
23//! # Overwrite existing files
24//! rcp /source /dest --overwrite --progress
25//! ```
26//!
27//! ### Remote Copying
28//!
29//! Copy files between remote hosts using `host:/path` syntax (similar to `scp`):
30//!
31//! ```bash
32//! # Copy from remote to local
33//! rcp user@host:/remote/path /local/path --progress
34//!
35//! # Copy from local to remote
36//! rcp /local/path user@host:/remote/path --progress --preserve
37//!
38//! # Copy between two remote hosts
39//! rcp user@host1:/path1 user@host2:/path2 --progress --summary
40//! ```
41//!
42//! When using remote paths, `rcp` automatically:
43//! - Starts `rcpd` daemons on remote hosts via SSH
44//! - Uses QUIC protocol for efficient data transfer
45//! - Transfers data directly between source and destination (not through the master)
46//!
47//! **Requirements for remote copying:**
48//! - SSH access to remote hosts (uses your SSH config and keys)
49//! - `rcpd` binary available in the same directory as `rcp` on remote hosts
50//!
51//! ## rcpd - Remote Copy Daemon
52//!
53//! The `rcpd` daemon is automatically launched by `rcp` when using remote paths.
54//! It should generally not be invoked directly by users.
55//!
56//! The daemon operates in two modes:
57//! - **Source mode**: Reads files from the source host
58//! - **Destination mode**: Writes files to the destination host
59//!
60//! # Key Features
61//!
62//! ## Performance
63//!
64//! - **Parallel operations**: Uses async I/O and worker threads for maximum throughput
65//! - **Optimized for large filesets**: Much faster than `cp` when dealing with many files
66//! - **QUIC protocol**: Efficient network transport for remote operations
67//!
68//! ## Copy Semantics
69//!
70//! Unlike `cp`, `rcp` uses unambiguous path semantics:
71//!
72//! - **Without trailing slash**: Path is treated as the final destination name
73//! - `rcp A/B C/D` → creates `C/D` (fails if exists)
74//! - **With trailing slash**: Path is treated as a directory to copy into
75//! - `rcp A/B C/D/` → creates `C/D/B` (fails if exists)
76//!
77//! Use `--overwrite` to allow overwriting existing destinations.
78//!
79//! ## Metadata Preservation
80//!
81//! - `--preserve`: Preserve all metadata (owner, group, mode, timestamps)
82//! - `--preserve-settings`: Fine-grained control over what to preserve
83//!
84//! ## Error Handling
85//!
86//! - By default: Log errors and continue processing
87//! - `--fail-early`: Stop on first error
88//!
89//! ## Progress & Logging
90//!
91//! - `--progress`: Show progress (auto-detects terminal type)
92//! - `--summary`: Print summary statistics at the end
93//! - `-v/-vv/-vvv`: Control log verbosity (INFO/DEBUG/TRACE)
94//! - Progress goes to stderr, logs to stdout (allows piping logs while viewing progress)
95//!
96//! ## Throttling & Resource Control
97//!
98//! - `--ops-throttle`: Limit operations per second
99//! - `--iops-throttle`: Limit I/O operations per second
100//! - `--max-open-files`: Control maximum open file descriptors
101//! - `--max-workers`: Control number of worker threads
102//!
103//! ## Remote Copy Configuration
104//!
105//! - `--quic-port-ranges`: Restrict QUIC to specific port ranges (e.g., "8000-8999")
106//! - `--remote-copy-conn-timeout-sec`: Connection timeout in seconds (default: 15)
107//!
108//! # Architecture
109//!
110//! ## Local Copy Architecture
111//!
112//! Local copying uses async I/O with multiple worker threads to maximize throughput
113//! when dealing with large numbers of files.
114//!
115//! ## Remote Copy Architecture
116//!
117//! Remote copying uses a three-node architecture:
118//!
119//! ```text
120//! Master (rcp)
121//! ├── SSH → Source Host (rcpd in source mode)
122//! │ └── QUIC → Master
123//! │ └── QUIC Server (waits for Destination)
124//! └── SSH → Destination Host (rcpd in destination mode)
125//! └── QUIC → Master
126//! └── QUIC Client → Source
127//! ```
128//!
129//! **Connection flow:**
130//! 1. Master starts `rcpd` processes on both hosts via SSH
131//! 2. Both `rcpd` processes connect back to Master via QUIC
132//! 3. Source `rcpd` starts a QUIC server and sends its address to Master
133//! 4. Master forwards the address to Destination `rcpd`
134//! 5. Destination connects directly to Source
135//! 6. Data flows directly from Source to Destination (not through Master)
136//!
137//! This architecture ensures efficient data transfer while allowing the Master to
138//! coordinate the operation and monitor progress.
139//!
140//! For detailed network connectivity and troubleshooting information, see the
141//! `docs/network_connectivity.md` file in the repository.
142//!
143//! # Examples
144//!
145//! ## Local Copy Examples
146//!
147//! ```bash
148//! # Basic copy with progress
149//! rcp /source /dest --progress --summary
150//!
151//! # Copy preserving all metadata
152//! rcp /source /dest --preserve --progress
153//!
154//! # Copy multiple sources into a directory
155//! rcp file1 file2 dir3 /dest/ --progress
156//! ```
157//!
158//! ## Remote Copy Examples
159//!
160//! ```bash
161//! # Copy from remote host to local
162//! rcp server:/data/files /local/backup --progress --preserve
163//!
164//! # Copy to remote host
165//! rcp /local/data server:/backup/ --progress --summary
166//!
167//! # Copy between remote hosts with custom port ranges
168//! rcp host1:/path1 host2:/path2 --quic-port-ranges "8000-8999" --progress
169//! ```
170//!
171//! # Library Usage
172//!
173//! This crate also provides library functions for integrating remote copy functionality
174//! into other Rust applications. See the module documentation for details.
175
176// Library for shared code between rcp and rcpd binaries
177pub mod destination;
178pub mod directory_tracker;
179pub mod path;
180pub mod source;