Using Remote Sync (rsync)

Posted Sunday, March 13, 2022 by Sri.Tagged MEMO
EDIT STATUS:new

What is rsync?

The unix-y command rsync will "synchronize" the contents of one directory to another, by copying (and optionally deleting) the files and directories. It works both locally and for "remote" hosts that have rsync enabled.

How does it work?

This is a command-line utility that you enter into your terminal shell using syntax like rsync [options] src dst:

  rsync -a dir1/ user@remote_host:dir2
  rsync -a user@remote_host:/home/user/dir1 /path-to-sync

The following examples are from digital ocean

BASIC IN-SYSTEM

src is always first argument, destination is always second

rsync -a dir1/ dir2 sync dir1/* to dir2/[files]

The slashes are important! If you leave it off the src it will *MOVE* dir1 to dir2

BASIC REMOTE

  rsync -a dir1/ user@remote_host:dir2
  rsync -a user@remote_host:/home/user/dir1 /path-to-sync

COMMON OPTIONS

  -a archive recursive sync, preserving symlinks, etc
  -r
  -v verbose
  -n dry run (try -anv)
  -z compress
  -P combination of --progress and --partial (resume)
  --delete allow rsync to delete stuff from remote for TRUE SYNC

OTHER OPTIONS

  -r recurse into directories
  --exclude=  pattern to exclude (pattern-separated list)
  --include   pattern to include (pattern-separated list)
  --backup    specify a location to store backups in addition to source and dest

RSYNC DAEMONS

(needs expansion) typically running on TCP port 873 can connect directly to it