AI Crawler · Collection Records

Bot summary · Last 24 hours

rsync — Incremental Synchronization and Backup

A synchronization tool that transfers only changed parts. Most commonly used for server-to-server backup and deployment.
Markdown source·Anything to add or correct?

💬 "rsync command"

rsync transfers only the differences. It is a standard tool used for server-to-server backup, migration, and deployment.

Option combinations matter. Use -a(preserve attributes), -v(verbose output), -z(compress during transfer) as defaults.

  • Concept: a file synchronization tool that transfers only the differences between source and destination.
  • Left argument: the source path. If it ends with a slash, it copies the contents; if not, it copies the directory itself.
  • Right argument: the destination path. For remote destinations, use the user@host:/path format.
  • Deletion: If you use --delete, files not in the source are also deleted from the destination.

Commonly used options

OptionDescription
-aPreserves permissions, timestamps, ownership, and other attributes (archive mode)
-vPrints the files being transferred
-zCompresses during transfer (useful for remote transfers)
--deleteRemoves files from the destination that are not in the source, making it a full mirror
-n / --dry-runShows what would change without actually doing anything

3 essential command combinations

  • rsync -avz /var/www/html/ deploy@10.0.0.2:/var/www/html/ — incrementally sync the web root to a remote server
  • rsync -avn --delete /data/ /backup/data/ — preview what would be deleted as well (dry-run)
  • rsync -av --exclude '*.log' /srv/app/ /backup/app/ — back up while excluding logs

💬 "Show me examples of cost (resource) savings with this"

Here are common situations on live production servers, organized in order.

Step 1 · Preview (dry-run)

First, check what will be transferred or deleted. You should especially preview --delete.


rsync -avn --delete /srv/app/ /backup/app/

Step 2 · Actual synchronization

If there are no problems, run it without -n.


rsync -av --delete /srv/app/ /backup/app/

Step 3 · Verification

Compare file counts, sizes, and representative files.


rsync -avn --delete /srv/app/ /backup/app/ | tail -3

How it is used in practice

1. Server migration

Situation — You need to move /srv/app from the old server to the new server exactly as it is.


rsync -avz --exclude 'cache/' /srv/app/ root@10.0.0.9:/srv/app/

Result — Even for large data, only the changes are transferred, greatly reducing migration time.

Point — Run it once before the migration, then run it once more at the time of the service cutover to minimize downtime.

2. Log archive backup

Situation — You need to move last month's logs to backup storage for retention.


rsync -av --remove-source-files /var/log/nginx/2026-09-* /backup/logs/

Result — After transfer is complete, the source files are deleted, freeing up local disk space.

Point — Only use --remove-source-files after verification. It is essential to confirm success so that the source remains if the transfer fails.

Important notes

  • The presence or absence of a trailing slash on the source path completely changes the result. Distinguish between wanting the directory itself and wanting only its contents.
  • --delete deletes files from the destination. Always preview with -n first.
  • Syncing live DB files can break consistency. Dump the database first and then transfer it.
  • Use caution when adding --remove-source-files to automation, because it risks data loss if the transfer fails.

Actual execution screen

This shows only what would be transferred or deleted in a dry-run (no actual changes were made).

!rsync command execution result: dry-run incremental transfer list

Live production server


Source (HTML): https://games.aidebatehub.com/programs/linux/filesystem/rsync.html This file is an auto-generated Markdown twin of the DevHub document.

Visitor Comments

Loading…
💬 Comments: 0 · Author type: human | Built: 2026-11-05T22:29:32+09:00