2014-09-29

Using rsync over ssh

rsync-ssh-download.bash
-----------------------------------------------------------------------
#! /bin/bash

# SOURCE
SSH_PORT=22
SSH_USER="userA"
SSH_HOST="192.168.0.5"
SSH_PATH="/home/userA/"
# DESTINATION
DST="/home/userB/backup/"
DST_CHOWN="userB"

SRC="${SSH_USER}@${SSH_HOST}:${SSH_PATH}"

CHECK_FAIL=0

    if [ ! -f "/usr/bin/ssh" ]; then
    echo "ssh not found!"
    CHECK_FAIL=1   
    fi

    if [ ! -f "/usr/bin/rsync" ]; then
    echo "rsync not found!"
    CHECK_FAIL=1
    fi
   
    if [ ! -f "/usr/bin/sshpass" ]; then
    echo "sshpass not found!"
    CHECK_FAIL=1
    fi
   
    if [ "$(id -u)" != "0" ]; then
    echo "not root"
    CHECK_FAIL=1
    fi
   
    if [ $CHECK_FAIL -eq 1 ];then
    exit 0
    fi

   
read -s -p "Enter SSH Password: " pswd
echo ""
echo "Connecting..."

/usr/bin/rsync --verbose --recursive --append --links --copy-dirlinks \
--hard-links --perms --executability --times --delete --chown=${DST_USER}:${DST_USER} \
 --rsh="/usr/bin/sshpass -p '${pswd}' ssh -p ${SSH_PORT} -o StrictHostKeyChecking=no -l ${SSH_USER}" $SRC  $DST

du ${DST}  --max-depth=0 --block-size=MB
echo "Complete"

-----------------------------------------------------------------------
rsync-ssh-upload.bash
-----------------------------------------------------------------------
#! /bin/bash

# SOURCE
SRC="/home/userB/backup/"
# DESTINATION
SSH_PORT=22
SSH_USER="userA"
SSH_HOST="192.168.0.5"
SSH_PATH="/home/userA/"
DST_CHOWN="userA"

DST="${SSH_USER}@${SSH_HOST}:${SSH_PATH}"

CHECK_FAIL=0

    if [ ! -f "/usr/bin/ssh" ]; then
    echo "ssh not found!"
    CHECK_FAIL=1   
    fi

    if [ ! -f "/usr/bin/rsync" ]; then
    echo "rsync not found!"
    CHECK_FAIL=1
    fi
   
    if [ ! -f "/usr/bin/sshpass" ]; then
    echo "sshpass not found!"
    CHECK_FAIL=1
    fi
   
    if [ "$(id -u)" != "0" ]; then
    echo "not root"
    CHECK_FAIL=1
    fi
   
    if [ $CHECK_FAIL -eq 1 ];then
    exit 0
    fi

du ${SRC}  --max-depth=0 --block-size=MB
   
read -s -p "Enter SSH Password: " pswd
echo ""
echo "Connecting..."

/usr/bin/rsync --verbose --recursive --append --links --copy-dirlinks \
--hard-links --perms --executability --times --delete --chown=${DST_USER}:${DST_USER} \
 --rsh="/usr/bin/sshpass -p '${pswd}' ssh -p ${SSH_PORT} -o StrictHostKeyChecking=no -l ${SSH_USER}" $SRC  $DST

echo "Complete"


 -----------------------------------------------------------------------




 

No comments:

Post a Comment