How to Use rsync for Command-Line Backups on Fedora

Use rsync with -avz flags to create efficient, incremental backups on Fedora that preserve file attributes and compress data during transfer.

The trailing slash that breaks backups

You just finished a long dnf upgrade and your laptop battery dies mid-transfer. Or you cloned a project directory and accidentally deleted the original. You need a reliable way to copy files that survives network drops, skips unchanged data, and keeps permissions intact. rsync is the standard tool for this on Fedora. It does not just copy files. It calculates what changed and moves only the differences.

Run rsync from a backup VM or a secondary drive first if you are touching production data. A misplaced flag can wipe a destination directory faster than you can type Ctrl+C.

What rsync actually does under the hood

Standard copy commands like cp or scp treat files as opaque blobs. They read the entire source file and write it to the destination. If you modify a single line in a 200-megabyte log file, the entire file transfers again. rsync uses a delta-transfer algorithm. It splits files into fixed-size blocks, calculates checksums for each block, and compares them against the destination. Only the blocks that differ get sent over the network.

Think of it like a librarian comparing two editions of a book. Instead of photocopying the entire volume, the librarian marks the changed pages and sends only those. The rest of the file stays untouched on the target machine. This approach saves bandwidth, reduces disk I/O, and makes interrupted transfers safe to resume.

The -a flag enables archive mode. It is not a single feature. It is a shorthand for a set of preservation flags that keep the source and destination identical in structure. It preserves symbolic links, file permissions, ownership, modification times, and group information. Without it, rsync behaves like a basic copy tool and strips metadata.

Add -v for verbose output so you can see exactly which files are moving. Add -z to compress data during transit. Compression matters on slow links or when transferring many small files. The SSH transport layer already encrypts the stream, so -z reduces the payload size without adding a separate encryption step.

Always test the command locally before pointing it at a remote server. Local runs fail fast and leave no remote state to clean up.

The baseline backup command

Here is how to copy a directory tree to a remote Fedora machine while preserving metadata and cleaning up orphaned files.

rsync -avz --delete /home/user/documents/ user@192.168.1.50:/backup/documents/
# -a preserves permissions, timestamps, symlinks, and ownership
# -v prints each file as it transfers so you can track progress
# -z compresses the data stream to save bandwidth
# --delete removes files from the destination that no longer exist in the source
# The trailing slash on the source copies the contents of the directory
# The missing trailing slash on the destination creates the directory if it does not exist

The trailing slash on the source path controls exactly what gets copied. /path/to/source/ copies the contents inside the directory. /path/to/source copies the directory itself as a subdirectory inside the destination. This is the most common cause of nested backup folders like /backup/documents/documents/documents/. Verify your paths before running.

Fedora ships with openssh-server disabled by default. If you are pushing to a remote machine, you need SSH access. Configure key-based authentication before automating backups. Password prompts will hang unattended scripts and break cron jobs.

Run the command with --dry-run first. It simulates the transfer without touching any files. The output shows exactly what would happen.

rsync -avz --delete --dry-run /home/user/documents/ user@192.168.1.50:/backup/documents/
# --dry-run prints the action plan without modifying source or destination
# Review the output for unexpected deletions or permission changes
# Remove --dry-run only after the plan matches your intent

Check the dry-run output line by line. If you see files you did not expect to delete, stop. Fix the source path or adjust the --exclude patterns before proceeding.

Verify the transfer

Trust the package manager. Manual file edits drift, snapshots stay. The same principle applies to backups. Never assume a silent exit means success. Verify the state after the run.

Run a second dry-run immediately after the actual transfer. If the transfer completed correctly, the second run should show zero changes.

rsync -avz --delete --dry-run /home/user/documents/ user@192.168.1.50:/backup/documents/
# A clean run produces no output or only header lines
# Any listed files indicate a mismatch between source and destination
# Investigate permission issues or interrupted transfers if files appear

You can also compare directory trees locally using diff. It walks both paths and reports structural differences.

diff -r /home/user/documents/ /mnt/external/backup/documents/
# -r recursively compares directories and reports missing or differing files
# An empty output means the trees are identical
# Non-zero exit code indicates at least one mismatch

Check file counts and total sizes if you need a quick sanity check. find combined with wc gives you an exact file count without parsing human-readable output.

find /home/user/documents/ -type f | wc -l
# Counts regular files recursively, ignoring directories and symlinks
# Compare this number against the destination count to catch silent skips
# Mismatches usually point to permission denials or excluded paths

Reboot before you debug. Half the time the symptom is gone. In backup workflows, the equivalent is running a fresh dry-run after a system update. Package upgrades can change default permissions or SELinux contexts, which breaks subsequent syncs.

Common pitfalls and error patterns

The rsync command will refuse to proceed and print rsync: [sender] write failed: No space left on device (28). The destination partition is full. Check available space with df -h before running large transfers. Do not ignore this error. Forcing the transfer will corrupt files and leave the destination in an inconsistent state.

If you see rsync: link_stat "/backup/documents/" failed: Permission denied (13), your SSH user lacks write access to the target directory. Verify ownership with ls -ld /backup/documents/ on the remote host. Fix permissions before retrying. Never run rsync as root unless you are backing up system directories.

SELinux denials show up in journalctl -t setroubleshoot with a one-line summary. Read those before disabling SELinux. If you are syncing to a directory with a custom context, rsync may fail to write files. Use restorecon -Rv /backup/documents/ to reset contexts, or add --no-perms if you are syncing to a non-system partition.

The --delete flag is destructive. It removes files from the destination that are missing in the source. If you accidentally point the source at an empty directory, rsync will wipe the destination. Always run --dry-run with --delete enabled. Verify the deletion list matches your intent.

Network interruptions are normal. rsync resumes automatically on the next run. It does not restart from zero. It picks up where the checksum comparison left off. Do not interrupt a running transfer unless the source system is unresponsive. Killing the process mid-transfer leaves partial files that the next run will overwrite anyway.

Run journalctl -xe first. Read the actual error before guessing. SSH failures, firewall drops, and DNS timeouts all produce different log lines. Match the error to the cause before changing flags.

When to use rsync versus alternatives

Use rsync when you need a straightforward, file-level mirror that preserves permissions and resumes after interruptions. Use tar when you are archiving a directory into a single compressed file for long-term storage or transport. Use borg when you require deduplication, encryption, and versioned snapshots across multiple machines. Use restic when you want cloud-native backup targets and cross-platform compatibility. Stay on rsync if you only need to keep two directories in sync without managing a repository.

Where to go next