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 
# @since 2013-07-05
####
function net_bazzline_sync_from_host ()
{
    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 
# @since 2013-07-05
function net_bazzline_sync_to_host ()
{
    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
}

Trackbacks

Keine Trackbacks

Kommentare

Ansicht der Kommentare: Linear | Verschachtelt

Noch keine Kommentare

Kommentar schreiben

Die angegebene E-Mail-Adresse wird nicht dargestellt, sondern nur für eventuelle Benachrichtigungen verwendet.
Um einen Kommentar hinterlassen zu können, erhalten Sie nach dem Kommentieren eine E-Mail mit Aktivierungslink an ihre angegebene Adresse.

Um maschinelle und automatische Übertragung von Spamkommentaren zu verhindern, bitte die Zeichenfolge im dargestellten Bild in der Eingabemaske eintragen. Nur wenn die Zeichenfolge richtig eingegeben wurde, kann der Kommentar angenommen werden. Bitte beachten Sie, dass Ihr Browser Cookies unterstützen muss, um dieses Verfahren anzuwenden.
CAPTCHA

Markdown-Formatierung erlaubt
Formular-Optionen