Skip to content

Rsync (SSH) โ€‹

Store backups on any remote server using rsync's efficient delta-transfer algorithm over SSH.

Overview โ€‹

Rsync is a fast, versatile file synchronization tool that uses SSH for secure transfer. Benefits:

  • โšก Delta transfers โ€” only changed blocks are sent
  • ๐Ÿ”’ Encrypted transfer (SSH)
  • ๐Ÿ—œ๏ธ Built-in transfer compression
  • ๐Ÿ–ฅ๏ธ Works with any Linux/macOS server
  • ๐Ÿ”‘ Multiple authentication methods (Password, SSH Key, SSH Agent)
  • โš™๏ธ Customizable with additional rsync flags

Prerequisites โ€‹

System Requirements

The Rsync adapter requires the following CLI tools on the DBackup host:

  • rsync โ€” File synchronization (pre-installed on most systems)
  • openssh-client โ€” SSH connectivity
  • sshpass โ€” Only needed for password authentication

These are pre-installed in the official Docker image. For local development on macOS, see the setup section below.

Configuration โ€‹

FieldDescriptionDefault
NameFriendly nameRequired
HostServer hostname or IPRequired
PortSSH port22
UsernameSSH usernameRequired
Auth TypeAuthentication methodpassword
PasswordSSH passwordConditional
Private KeySSH key (PEM format)Conditional
PassphraseKey passphraseOptional
Path PrefixRemote directory for backupsRequired
OptionsAdditional rsync flagsOptional

Authentication Methods โ€‹

Password Authentication โ€‹

Simplest setup โ€” requires sshpass on the host:

  1. Select Auth Type: password
  2. Enter username and password

Security

Passwords are never passed as command-line arguments. DBackup uses the SSHPASS environment variable exclusively, preventing exposure in process listings.

SSH Key Authentication โ€‹

More secure, recommended for production:

  1. Select Auth Type: privateKey
  2. Paste your private key (PEM format)
  3. Enter passphrase if key is encrypted

Supported key formats:

-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jdHI...
-----END OPENSSH PRIVATE KEY-----
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEA...
-----END RSA PRIVATE KEY-----

SSH Agent โ€‹

For environments with SSH agent forwarding:

  1. Select Auth Type: agent
  2. Mount SSH socket in Docker:
yaml
services:
  dbackup:
    volumes:
      - ${SSH_AUTH_SOCK}:/ssh-agent:ro
    environment:
      - SSH_AUTH_SOCK=/ssh-agent

Server Setup โ€‹

Create Backup User โ€‹

bash
# Create user
sudo useradd -m -s /bin/bash backupuser

# Create backup directory
sudo mkdir -p /backups/rsync
sudo chown backupuser:backupuser /backups/rsync

# Set password (if using password auth)
sudo passwd backupuser

SSH Key Setup โ€‹

bash
# Generate key pair (on your machine)
ssh-keygen -t ed25519 -f ~/.ssh/dbackup_rsync_key

# Copy public key to server
ssh-copy-id -i ~/.ssh/dbackup_rsync_key.pub backupuser@server

Install rsync on Target Server โ€‹

Most Linux distributions include rsync, but verify:

bash
# Debian/Ubuntu
sudo apt install rsync

# RHEL/CentOS/Fedora
sudo dnf install rsync

# Alpine
apk add rsync

Path Prefix โ€‹

The Path Prefix defines the base directory on the remote server where all backups are stored. The user must have write permissions to this directory.

Permission Denied

If you see "Permission denied: Cannot create directory", the SSH user does not have write access to the specified path. Use a path within the user's home directory:

  • โœ… /home/backupuser/backups
  • โœ… ~/backups
  • โŒ /backups (requires root or explicit permissions)

Additional Options โ€‹

The Options field allows passing extra rsync flags:

OptionDescription
--bwlimit=5000Limit bandwidth to 5000 KB/s
--timeout=300Set I/O timeout to 300 seconds
--exclude=*.tmpExclude files matching pattern
--compress-level=9Maximum compression level

Example: --bwlimit=10000 --timeout=600

Directory Structure โ€‹

After backups, your server will have:

/home/backupuser/backups/
โ”œโ”€โ”€ mysql-daily/
โ”‚   โ”œโ”€โ”€ backup_2026-02-14T12-00-00.sql.gz
โ”‚   โ”œโ”€โ”€ backup_2026-02-14T12-00-00.sql.gz.meta.json
โ”‚   โ””โ”€โ”€ ...
โ””โ”€โ”€ postgres-weekly/
    โ””โ”€โ”€ ...

Docker Configuration โ€‹

The official Docker image includes all required tools. No additional configuration needed:

yaml
services:
  dbackup:
    image: skyfay/dbackup:latest
    # rsync, sshpass, openssh-client are pre-installed

For SSH Agent forwarding in Docker:

yaml
services:
  dbackup:
    image: skyfay/dbackup:latest
    volumes:
      - ${SSH_AUTH_SOCK}:/ssh-agent:ro
    environment:
      - SSH_AUTH_SOCK=/ssh-agent

macOS Development Setup โ€‹

For local development, install the required tools:

bash
# rsync (macOS ships with an older version)
brew install rsync

# sshpass (only needed for password auth)
brew install hudochenkov/sshpass/sshpass

Rsync vs SFTP โ€‹

Both use SSH for transfer, but rsync has unique advantages:

FeatureRsyncSFTP
Delta transfersโœ… Only changed blocksโŒ Full file transfer
Transfer compressionโœ… Built-inโŒ Via DBackup only
Bandwidth limitingโœ… --bwlimit flagโŒ Not supported
CLI dependencyโœ… Required on both endsโŒ Uses npm package
Custom optionsโœ… ExtensiveโŒ Limited
Resume interruptedโœ… --partial flagโŒ Restart required

Use Rsync when: You need efficient incremental transfers, bandwidth control, or are syncing large backup files repeatedly.

Use SFTP when: You want zero CLI dependencies, or the target server doesn't have rsync installed.

Troubleshooting โ€‹

Connection Refused โ€‹

connect ECONNREFUSED

Solutions:

  1. Verify SSH is running: systemctl status sshd
  2. Check firewall allows the SSH port
  3. Verify hostname/IP is correct

Too Many Authentication Failures โ€‹

Too many authentication failures

Solutions:

  1. Ensure you're using Password auth type (not Agent)
  2. DBackup automatically disables public key auth for password connections
  3. Check that SSH agent isn't loaded with many keys

Permission Denied โ€‹

Permission denied: Cannot create directory

Solutions:

  1. Use a path the user owns (e.g., /home/user/backups)
  2. Create the directory manually and set ownership:
    bash
    sudo mkdir -p /backups && sudo chown user:user /backups
  3. Check SELinux/AppArmor policies

sshpass Not Found โ€‹

Password authentication requires 'sshpass' to be installed

Solutions:

  1. Use the official Docker image (includes sshpass)
  2. Install manually:
    • Debian/Ubuntu: sudo apt install sshpass
    • macOS: brew install hudochenkov/sshpass/sshpass
    • Alpine: apk add sshpass
  3. Or switch to SSH Key / Agent authentication

rsync Not Found on Remote โ€‹

rsync: command not found

Solution: Install rsync on the target server:

bash
sudo apt install rsync    # Debian/Ubuntu
sudo dnf install rsync    # RHEL/Fedora
apk add rsync             # Alpine

Security Best Practices โ€‹

  1. Use SSH keys instead of passwords
  2. Disable root login via SSH
  3. Restrict backup user permissions to the backup directory only
  4. Use non-standard SSH port (security by obscurity)
  5. Enable fail2ban for brute-force protection
  6. Limit bandwidth with --bwlimit to avoid saturating the network
  7. Firewall rules to limit source IPs

Comparison with Other Destinations โ€‹

FeatureRsyncSFTPS3Local
Setup complexityMediumMediumEasyEasiest
Self-hostedโœ…โœ…โŒโœ…
Delta transfersโœ…โŒโŒN/A
Encryption in transitโœ…โœ…โœ…N/A
Bandwidth controlโœ…โŒโŒN/A
ScalabilityLimitedLimitedHighLimited
CLI dependencyYesNoNoNo
CostServer costServer costPay-per-useFree

Next Steps โ€‹

Released under the GNU General Public License. | Privacy ยท Legal Notice