Skip to content

Instantly share code, notes, and snippets.

@ppdeassis
Last active December 18, 2015 05:29
Show Gist options
  • Save ppdeassis/5733169 to your computer and use it in GitHub Desktop.
Save ppdeassis/5733169 to your computer and use it in GitHub Desktop.
Synchronizing files with rsync
# Synchronize directories with rsync and ssh:
# -r recursive
# -c skip based on checksum, not mod-time & size
# -h output numbers in a human-readable format
# -a archive mode
# -v verbose mode
# -e define shell used as transport
# -P same as --partial --progress: keeps partial transfered files if interrupted AND shows progress
# --delete to delete extraneous files on dest dir
rsync -rav -e "ssh -l $_USERNAME" --delete $_SOURCE_DIR $_DEST_DIR
# IMPORTANT: DIR must end with a trailing slash, e.g. /Users/pedro/Projects/
# "Hard" (delete extraneous files) synchronize a local directory on a remote directory (like git push)
_USER=<NAME> _SERVER=<NAME> _FROM=<NAME> _TO=<NAME>; rsync -rchavP -e "ssh -l $_USER" --delete "$_FROM" "$_SERVER":"$_TO"
# "Hard" (delete extraneous files) synchronize a remote directory on a local directory (like git pull)
_USER=<NAME> _SERVER=<NAME> _FROM=<NAME> _TO=<NAME>; rsync -rchavP -e "ssh -l $_USER" --delete "$_SERVER":"$_FROM" "$_TO"
# "Soft" (keeps extraneous files) synchronize a local directory on a remote directory (like git push)
_USER=<NAME> _SERVER=<NAME> _FROM=<NAME> _TO=<NAME>; rsync -rchavP -e "ssh -l $_USER" "$_FROM" "$_SERVER":"$_TO"
# "Soft" (keeps extraneous files) synchronize a remote directory on a local directory (like git pull)
_USER=<NAME> _SERVER=<NAME> _FROM=<NAME> _TO=<NAME>; rsync -rchavP -e "ssh -l $_USER" "$_SERVER":"$_FROM" "$_TO"
# Synchronize a local file on a remote directory (like git push)
_USER=<NAME> _SERVER=<NAME> _FROM=<NAME> _TO=<NAME>; rsync -chavP -e "ssh -l $_USER" "$_FROM" "$_SERVER":"$_TO"
# Synchronize a remote file on a local directory (like git pull)
_USER=<NAME> _SERVER=<NAME> _FROM=<NAME> _TO=<NAME>; rsync -chavP -e "ssh -l $_USER" "$_SERVER":"$_FROM" "$_TO"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment