Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@02Tea
Last active July 8, 2021 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 02Tea/c77eb828da0b51a92dfaa0bfa332ad3e to your computer and use it in GitHub Desktop.
Save 02Tea/c77eb828da0b51a92dfaa0bfa332ad3e to your computer and use it in GitHub Desktop.
[rsync remote to local vice versa] #rsync #bash #migrate #pv #progress #ssh
# Local to Remote: rsync [OPTION]... -e ssh [SRC]... [USER@]HOST:DEST
# Remote to Local: rsync [OPTION]... -e ssh [USER@]HOST:SRC... [DEST]
# remote -> local
rsync -havz -e ssh user@12.12.12.12:/var/wwww/livesite/ /var/www/localsite/
# local -> remote
rsync -havz -e ssh /var/www/localsite/ user@12.12.12.12:/var/www/livesite/
# dry run
rsync -hanvz -e ssh user@12.12.12.12:/var/wwww/livesite/ /var/www/localsite/
# with key
rsync -hanvz --progress -e "ssh -i ~/.ssh/your_rsa" user@12.12.12.12:/var/wwww/livesite/ /var/www/localsite/
# piped to pv (with progress bar)
# So if you have 42 files in /tmp/software and you would like to copy them to /nas10, enter:
rsync -vrltD --stats --human-readable /tmp/software /nas10 | pv -lep -s 42
# or
rsync -vrltD --stats --human-readable /tmp/software /nas10 | pv -lep -s 42 >/dev/null
# built in progress bar remote -> local transfer
rsync -hav --progress user@12.12.12.12:/path/to/your/file.gz .
# rsync interprets a directory with no trailing slash as copy this directory, and a directory with a trailing slash as copy the contents of this directory. @source https://stackoverflow.com/questions/20300971/rsync-copy-directory-contents-but-not-directory-itself
# copies contents of foo/
rsync -av ~/foo/ user@remote.com:/var/www/bar/
# copies the foo directory
rsync -av ~/foo user@remote.com:/var/www/bar/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment