Innovate | Connect | Transform
ContactService statusUSD $

GICT knowledge base

Use rsync on Linux: Preview Copies and Understand Deletion

Published

Linux and Commands

rsync copies files locally or between authorized systems. It can avoid retransferring unchanged data, but its behavior depends on transport, options and the workload. A synchronized directory is not automatically a versioned backup: overwrites and deletions can remove the only usable earlier copy.

Practice locally before using a remote path

Run this Bash example in one session. It creates synthetic files under a new private directory, previews a copy and then performs it.

umask 077
lab=$(mktemp -d)
cd "$lab" || exit 1
mkdir source destination
printf 'example\n' > source/file.txt
printf 'hidden\n' > source/.settings
rsync -anvi source/ destination/
rsync -avi source/ destination/
cmp source/file.txt destination/file.txt
cmp source/.settings destination/.settings

-n is the dry run; -i itemizes changes and does not itself prevent writes. -v adds detail. Check the preview again after changing operands or options.

The trailing slash changes the destination layout

source/ means its contents go into the destination. Using the directory name without that trailing slash normally copies the directory itself beneath an existing destination. Confirm the result in a harmless fixture instead of guessing on a live web root.

mkdir nested
rsync -a source nested/
cmp source/file.txt nested/source/file.txt
printf 'destination-only\n' > destination/old.txt
rsync -anvi --delete source/ destination/
test -f destination/old.txt

The last operation is only a deletion preview: old.txt remains. An actual --delete run removes destination entries absent from the selected source. A wrong source, missing mount or mistaken slash can therefore destroy useful destination data. Do not turn a preview into a scheduled destructive mirror without independent versions, path guards and recovery checks.

Choose metadata and transfer options deliberately

  • -a is archive mode, including recursion and several common metadata attributes. It does not include all ACLs, extended attributes or hard-link relationships; review -A, -X and -H and destination support separately.
  • Owner/group restoration depends on privileges and identity mapping. A successful ordinary-user copy is not proof of complete system metadata recovery.
  • -P combines partial-file retention and progress. Partial files are not completed backups, and resume modes need their documented content assumptions.
  • -z may help compressible network traffic but can waste CPU on already-compressed data. Local copies commonly use whole-file transfers rather than a network delta algorithm.
  • Quote paths and exclusions, and test what is included. Live databases need a consistent export or application-aware capture.

Copy through SSH

rsync -anvi -e 'ssh -p 2222 -i /home/localuser/.ssh/transfer_ed25519' ./source/ user@server.example:/upload/

This is a template and a dry run, not a real host. Both ends need a compatible rsync executable and permitted remote command execution; an SFTP-only account is insufficient. Verify the SSH host key independently, use the right account and preview exactly the eventual command. Avoid plaintext rsync-daemon exposure for sensitive data unless an approved protective transport is provided.

Check rsync’s exit status and logs, then validate representative restored content. Do not hide failures behind an unconditional “backup succeeded” message or treat file modification time as proof of recovery health.

Reference: upstream rsync manual.

Reviewed October 15, 2026. Both local practice blocks were executed with synthetic files. The SSH command is an illustrative template, not a customer transfer or benchmark.

Related guides

Account services are unavailable until the production backend is configured.