What does the Rsync Command Generator & Transfer Builder do?
The Rsync Command Generator creates syntax-checked rsync commands for local backups and remote server transfers over SSH. It constructs -e "ssh ..." flags for non-standard ports and identity keys, applies glob exclude rules, generates a -n dry-run simulation command, and highlights whether the source path trailing slash copies directory contents or the folder itself.
Core Concepts
Understanding key rsync behaviors prevents data loss and accidental duplicate nesting:
- The Trailing Slash Rule: A trailing slash on the source directory (
/var/www/html/) instructs rsync to copy the contents of the folder into the destination. Omitting the trailing slash (/var/www/html) instructs rsync to copy the folder itself as a sub-directory inside the destination. - Delta-Transfer Algorithm: Unlike traditional
cporscp, rsync calculates checksum differences and transfers only modified byte chunks, significantly reducing bandwidth and transfer times. - Resumable Partial Transfers (
-P/--partial --progress): Keeps partially transferred files if a connection drops, enabling seamless resume of multi-gigabyte transfers without restarting from byte zero.
How to use the tool?
- Enter Source and Destination Paths: Specify local directory paths (e.g.
/var/www/html/) or remote SSH targets inuser@hostname:/remote/path/format. - Configure Remote SSH Settings:
- SSH Port: Specify non-standard SSH ports (e.g.,
2222). The generator automatically formats-e "ssh -p 2222". - SSH Identity Key: Provide the absolute or relative path to your private key file (e.g.
~/.ssh/id_rsaor~/.ssh/deploy_key.pem).
- SSH Port: Specify non-standard SSH ports (e.g.,
- Select Transfer Flags & Options:
-a(Archive mode): Preserves file permissions, symlinks, timestamps, ownership, and recurses into subdirectories.-v(Verbose) &-h(Human-readable): Prints transferred file names and human-friendly sizes (KB, MB, GB).-z(Compress): Compresses network data in transit over WAN or slow connections.-P(Progress & Partial): Displays real-time transfer progress and retains partially downloaded files.--delete: Deletes destination files that no longer exist in the source directory (creating an exact mirror).- Exclude Patterns: Enter file and folder patterns (one per line, e.g.
node_modules/,.git/,*.log) to exclude from transfer.
- Copy Dry-Run Command First: Always run the generated dry-run command (
-n) first in your terminal to verify which files will be copied or removed before executing the production command.
Related Developer Utilities
If you are managing Linux servers, deployments, or SSH access, explore these complementary Blueutils developer utilities:
- Crontab to Systemd Timer Generator: Convert legacy 5-field cron jobs into modern Systemd
OnCalendartimer and.serviceunit files. - Linux Logrotate Config Generator: Generate
/etc/logrotate.d/configurations withcopytruncateto prevent disk full outages. - SSH Key Fingerprint Generator: Calculate SHA-256 and MD5 fingerprints from public SSH keys.
REST API Integration
Blueutils provides a free REST API endpoint (POST https://blueutils.com/api/linux/rsync-generator) to programmatically build optimized rsync command lines with automatic dry-run (-n) safety flags, SSH keys/ports, and exclusions.
API Request Parameters
| Name | Type | Description | Example |
|---|---|---|---|
sourcePath |
String | Source local or remote directory/file path. | "/var/www/html/" |
destPath |
String | Target destination directory or remote endpoint. | "ubuntu@54.161.226.140:/var/www/backup/" |
archive |
Boolean | Whether to enable archive mode (-a). Defaults to true. |
true |
verbose |
Boolean | Whether to enable verbose file transfer output (-v). |
true |
humanReadable |
Boolean | Whether to format numbers in human-readable units (-h). |
true |
compress |
Boolean | Whether to compress stream data during network transfer (-z). |
true |
progress |
Boolean | Whether to show progress and enable partial transfer resume (-P). |
true |
delete |
Boolean | Whether to delete extraneous files from destination (--delete). |
false |
sshPort |
Number/String | Custom remote SSH port number (e.g. 2222). |
22 |
sshKey |
String | Path to private SSH key identity file (-i). |
"~/.ssh/id_rsa" |
bwlimit |
String | I/O bandwidth rate limit (e.g. 10M or 5000). |
"10M" |
excludes |
Array/String | Excluded file glob patterns or multiline text. | ["node_modules", ".git"] |
API Request Payload Examples
cURL
curl -X POST https://blueutils.com/api/linux/rsync-generator \
-H "Content-Type: application/json" \
-d '{
"sourcePath": "/var/www/html/",
"destPath": "ubuntu@54.161.226.140:/var/www/backup/",
"archive": true,
"verbose": true,
"compress": true,
"delete": true,
"sshPort": 22
}'Python
import requests
url = "https://blueutils.com/api/linux/rsync-generator"
payload = {
"sourcePath": "/var/www/html/",
"destPath": "ubuntu@54.161.226.140:/var/www/backup/",
"archive": True,
"verbose": True,
"compress": True,
"delete": True,
"sshPort": 22
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.json())Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
String jsonPayload = """
{
"sourcePath": "/var/www/html/",
"destPath": "ubuntu@54.161.226.140:/var/www/backup/",
"archive": true,
"verbose": true,
"compress": true,
"delete": true,
"sshPort": 22
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://blueutils.com/api/linux/rsync-generator"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}API Response Parameters
| Name | Type | Description | Example |
|---|---|---|---|
isValid |
Boolean | Indicates whether command generation succeeded. | true |
prodCommand |
String | The fully compiled production rsync command. |
"rsync -avhz --delete /src/ /dest/" |
dryRunCommand |
String | Safe simulation command with dry-run (-n) enabled. |
"rsync -avhzn --delete /src/ /dest/" |
trailingSlashNote |
String | Explanation of trailing slash behavior for source path. | "Source has trailing slash..." |
flagDescriptions |
Array | Structured list of individual flags and their meanings. | [{"flag": "-a", "desc": "..."}] |
API Response Payload Examples
Success Response (HTTP 200 OK)
{
"isValid": true,
"prodCommand": "rsync -avhz --delete /var/www/html/ ubuntu@54.161.226.140:/var/www/backup/",
"dryRunCommand": "rsync -avhzn --delete /var/www/html/ ubuntu@54.161.226.140:/var/www/backup/",
"trailingSlashNote": "Source has trailing slash: rsync will copy the CONTENTS of the directory into destination.",
"flagDescriptions": [
{ "flag": "-a", "desc": "Archive mode (preserves permissions, timestamps, owner, symlinks, and recurses directories)" },
{ "flag": "-v", "desc": "Verbose output detailing transferred files" },
{ "flag": "-h", "desc": "Output numbers in human-readable format (e.g. KB, MB, GB)" },
{ "flag": "-z", "desc": "Compress file data during transfer over network" },
{ "flag": "--delete", "desc": "Delete extraneous files from destination that do not exist in source" }
]
}Validation Failure Response (HTTP 400 Bad Request)
{
"isValid": false,
"error": "Source path cannot be empty."
}Rate Limit Exceeded Response (HTTP 429 Too Many Requests)
{
"error": "API rate limit exceeded. Please wait or contact support@blueutils.com."
}Why use an API to generate Rsync commands?
Integrating the Rsync Generator API into CI/CD pipelines, DevOps scripts, or automated agent workflows provides several practical advantages:
- Rapid Script Validation: Enables developers and infrastructure engineers to programmatically generate and verify complex transfer command lines across diverse deployment environments without manual syntax checking.
- Optimized Token Efficiency for AI Agents: Offloading command formatting to an external API significantly cuts prompt and completion token consumption for autonomous agents.
- Deterministic Accuracy Without Hallucinations: Language models can occasionally misformat subtle CLI flags (such as trailing slashes, nested SSH identity key arguments, or exclude glob escaping). Delegating generation to a deterministic API guarantees 100% syntactically correct commands every time without token overhead.
Native Usage
How to perform file synchronizations and directory mirroring locally and natively without external dependencies:
Windows (CMD / PowerShell / Robocopy)
On Windows, native robocopy provides mirror and delta synchronization functionality equivalent to rsync:
# Preview mirror synchronization (Dry-Run / List Only)
robocopy "C:\Source" "D:\Destination" /E /MIR /L /NP
# Execute mirror synchronization (copies changes, deletes destination orphans)
robocopy "C:\Source" "D:\Destination" /E /MIR /NP /R:2 /W:5Linux / Unix (Bash / Rsync)
# 1. Preview transfer in dry-run mode (no files modified)
rsync -avhzn --progress --delete /var/www/html/ user@remote-host:/var/www/backup/
# 2. Execute live synchronization over custom SSH port with key
rsync -avhzP --delete -e "ssh -p 2222 -i ~/.ssh/id_ed25519" /var/www/html/ user@remote-host:/var/www/backup/Python
Using Python's standard library subprocess or shutil for directory mirroring:
import subprocess
def run_rsync(source, dest, dry_run=True):
cmd = ["rsync", "-avhzP", "--delete"]
if dry_run:
cmd.append("-n")
cmd.extend([source, dest])
result = subprocess.run(cmd, capture_output=True, text=True)
print("STDOUT:", result.stdout)
if result.stderr:
print("STDERR:", result.stderr)
# Dry run test
run_rsync("/var/www/html/", "/backup/html/", dry_run=True)Java
Using Java ProcessBuilder to execute native rsync transfers safely:
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class RsyncRunner {
public static void main(String[] args) {
ProcessBuilder pb = new ProcessBuilder(
"rsync", "-avhzPn", "--delete", "/var/www/html/", "/backup/html/"
);
pb.redirectErrorStream(true);
try {
Process process = pb.start();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
}
int exitCode = process.waitFor();
System.out.println("Exit code: " + exitCode);
} catch (Exception e) {
e.printStackTrace();
}
}
}