rsync
A fast, versatile, remote (and local) file-copying tool.
Table of Contents
- Provides more functions than simple
scp/cp
commands. - Also used for local directory syncing.
Basic usage
rsync \[OPTIONS\] \$SRC \$DST
Advanced usage
Rsync used to sync large source codes.
Include/Exclude patterns on command line:
rsync -zamvh \
--include "*/" \
--include="*.cpp" \
--include="*.c" \
--include="*.h" \
--include="*.am" \
--include="*.cfg" \
--exclude="build/*" \
--exclude=".git/*" \
$SRC $DST
rsync options used above:
-z, --compress, compress file data during the transfer\
-a, --archive, archive mode; equals -rlptgoD (no -H,-A,-X)\
-m, --prune-empty-dirs, prune empty directory chains from file-list\
-v, --verbose, increase verbosity\
-h, --human-readable, output numbers in a human-readable format\
-l, --links, copy symlinks as symlinks\
-L, --copy-links, transform symlink into referent file/dir
Include/Exclude patterns from text file:
rsync -zauvh \
--include-from=rsync_include_patterns.txt \
--exclude-from=rsync_exclude_patterns.txt \
$SRC $DST
Common rsync include/exclude patterns:
$ cat rsync_include_patterns.txt
*/
*.h
*.hh
*.hxx
*.c
*.cc
*.cpp
*.cxx
*.am
*.sh
*.py
configure.ac
CMakeLists.txt
CMakeLists.txt.in
$ cat rsync_exclude_patterns.txt
.git
CVS
*
Aliases
Create rsync aliases for long rsync commands
$ export RSYNC_PATTERNS_DIR=<path-to-rsync-inc-exc-pat-files>
$ alias rsync-m="rsync -zamvh --no-l \
--include-from=$RSYNC_PATTERNS_DIR/rsync_include_patterns.txt \
--exclude-from=$RSYNC_PATTERNS_DIR/rsync_exclude_patterns.txt"
$ alias rsync-n="rsync -n -zamvh --no-l \
--include-from=$RSYNC_PATTERNS_DIR/rsync_include_patterns.txt \
--exclude-from=$RSYNC_PATTERNS_DIR/rsync_exclude_patterns.txt"
$ alias rsync-lm="rsync -zamvh --no-l -L \
--include-from=$RSYNC_PATTERNS_DIR/rsync_include_patterns.txt \
--exclude-from=$RSYNC_PATTERNS_DIR/rsync_exclude_patterns.txt"
$ alias rsync-ln="rsync -n -zamvh --no-l -L \
--include-from=$RSYNC_PATTERNS_DIR/rsync_include_patterns.txt \
--exclude-from=$RSYNC_PATTERNS_DIR/rsync_exclude_patterns.txt"
$ alias rsync-lmw="rsync -zamvh --no-l -L \
--exclude=$EXCLUDE_PATTERN \
--include-from=$RSYNC_PATTERNS_DIR/rsync_include_patterns.txt \
--exclude-from=$RSYNC_PATTERNS_DIR/rsync_exclude_patterns.txt"
$ alias rsync-lnw="rsync -n -zamvh --no-l -L \
--exclude=$EXCLUDE_PATTERN \
--include-from=$RSYNC_PATTERNS_DIR/rsync_include_patterns.txt \
--exclude-from=$RSYNC_PATTERNS_DIR/rsync_exclude_patterns.txt"
Examples
cd ~/workspace
rsync-lm remote:~/remote-repos/repo_1/ repo_1/
Fast copy over ssh
refer:
rsync -Pzv -e "ssh -i $SSH_KEY -p $SSH_PORT -T -x -o Compression=no" \
<local-files> <remote-files>