Skip to content

bash function to sync to and from a remote host by using rsync and ssh

I quickly created two bash functions to use rsync and ssh for syncing directories from the local host to a remote host and vice versa.

The two methods are available on my shell function repository. The two methods are called net_bazzline_sync_from_host and net_bazzline_sync_to_host. Enjoy it :-).

####

Uses rsync with ssh to copy data from remote to local host

#

@param string $1 - remote user

@param string $2 - remote host

@param string $3 - source path on remote host

@param string $4 - destination path on local host

#

@author stev leibelt artodeto@arcor.de

@since 2013-07-05

#

function netbazzlinesyncfromhost () { if [[ $# -eq 4 ]]; then USER="$1" HOST="$2" SOURCE="$3" DESTINATION="$4" else echo 'invalid number of variables provided' echo 'command user host source destination' fi

rsync -avz -e ssh $USER@$HOST:$SOURCE $DESTINATION

}

#

Uses rsync with ssh to copy data from local to remote host

#

@param string $1 - remote user

@param string $2 - remote host

@param string $3 - source path on local host

@param string $4 - destination path on remote host

#

@author stev leibelt artodeto@arcor.de

@since 2013-07-05

function netbazzlinesynctohost () { if [[ $# -eq 4 ]]; then USER="$1" HOST="$2" SOURCE="$3" DESTINATION="$4" else echo 'invalid number of variables provided' echo 'command user host source destination' fi

rsync -avz -e ssh $SOURCE $USER@$HOST:$DESTINATION

}

Translate to de es fr it pt ja

Trackbacks

No Trackbacks

Comments

Display comments as Linear | Threaded

No comments

Add Comment

Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.
To leave a comment you must approve it via e-mail, which will be sent to your address after submission.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

Markdown format allowed
Form options