Home » [SOLVED] rsync error: error in rsync protocol data stream (code 12) connection unexpectedly closed
Systems & Servers

[SOLVED] rsync error: error in rsync protocol data stream (code 12) connection unexpectedly closed

✨ Quick Answer

While transferring backups or replicating directory trees over SSH, your transfer abruptly aborts with rsync: connection unexpectedly closed (0 bytes received so far) [sender] followed by rsync error: error in rsync protocol data stream (code 12) at io.c. Exit code 12 signifies that the bidirectional data stream between the local sender and remote receiver process collapsed prematurely.

Quick Diagnostics

Cause
rsync binary is missing or not in $PATH on the destination remote server
Solution
Install rsync on the remote host with sudo apt install rsync
Cause
SSH connection timeout or stateful NAT firewall killing idle TCP pipes
Solution
Configure ServerAliveInterval and leverage -P --partial in rsync commands

Quick Solution (1 Minute):

  1. Verify remote rsync binary availability: ssh user@server "which rsync"
  2. Run transfer with resilient TCP keepalive options: rsync -avzP -e "ssh -o ServerAliveInterval=30" src/ user@server:/dest/

Step-by-Step Solution

  1. 1

    Step 1: Verify and Install rsync on Remote Destination Host

    The most common root cause when rsync fails instantly at 0 bytes transferred is the absence of the rsync executable on the target machine:

    BASH
    # On remote Ubuntu / Debian
    sudo apt update && sudo apt install -y rsync
    
    # On remote RHEL / Rocky Linux / AlmaLinux
    sudo dnf install -y rsync
    
  2. 2

    Step 2: Block Stateful NAT Dropouts with SSH KeepAlive Flags

    When syncing multi-gigabyte ISOs or databases, intermediate firewalls frequently drop connections deemed idle. Enforce active probing packets:

    BASH
    rsync -avzP -e "ssh -o ServerAliveInterval=15 -o ServerAliveCountMax=4" /local/dir/ user@server:/remote/dir/
    
  3. 3

    Step 3: Enable Resumable Partial Transfers (-P)

    Prevent network blips from forcing a complete restart of huge transfers by adding the -P argument (combines --partial and --progress):

    BASH
    rsync -avhP /var/backups/ user@server:/backups/
    

    If a network disconnect occurs, re-running the command resumes transmission from the exact byte where it paused.

Frequently Asked Questions

Why does rsync trigger Out of Memory before code 12 on budget VPSs?

Building recursive in-memory file indexes for millions of files exhausts constrained RAM. Pass --no-inc-recursive or sync partitioned subtrees.

How can I inspect the exact reason for the abrupt termination?

Invoke rsync in hyper-verbose mode combined with SSH debugging: rsync -vvv -e "ssh -vvv" ... to expose the initiating termination signal.

Prevention Advice

Recommended security practices:

  • Add ClientAliveInterval 30 inside remote /etc/ssh/sshd_config to sustain background batch transfers.
  • For enterprise-scale migrations, wrap rsync commands inside detachable sessions using tmux or screen.
Author • Web Designer & App Creator

Rodolfo Castro

Web designer, app developer, and founder of SoporteCero. Specializing in UI/UX architecture, digital products, and modern web environments. Every tutorial and guide on SoporteCero is thoroughly tested and verified in our technical lab to ensure reliable, up-to-date solutions.