To simplify this I have made a script to automate each step. The only requirement is to have SSH keys set up from the source server to the target server. This is a god method to transfer large amounts of data or lots of files, it is overkill for simple operations.
#--- START ---
#!/usr/bin/ksh
echo "
Unrestricted SCP.
"
cmd_check() {
x=0
for cmd in $@
do
which ${cmd} 2>&1 > /dev/null
if [ $? -ne 0 ]
then
echo "${cmd} Not Found. Either install command or add path location to the PATH variable"
x=$(( ${x} + 1 ))
fi
done
if [ ${x} -ne 0 ]
then
exit ${x}
fi
}
cmd_check pax mkfifo ssh rm echo cat
if [ $# != 4 ]
then
echo "--------------------------------------------------------------------------------"
echo "- This script will copy a directory and all the folders and files. -"
echo "- Unlike SCP / tar and gzip there are no file restrictions. -"
echo "- All transfers / and extracts are done on the go, so there is no space -"
echo "- requirements to land the data -"
echo "--------------------------------------------------------------------------------"
echo " "
echo "Usage: firo_scp.ksh "
echo " "
exit 1
fi
DIR=${1}
DIRNAME=`echo ${DIR} | sed 's/.*\///g'`
USERNAME=${2}
SERVER=${3}
RPATH=${4}
FIFO=./FSCP.$$
echo "Making a fifo file"
mkfifo -m 644 ${FIFO}
echo "Initiating pax to ${FIFO} fifo for ${DIR}"
pax -wf ${FIFO} -x pax ${DIR} &
echo "Making remote fifo file: Authentication Successful should be displayed"
ssh ${USERNAME}@${SERVER} "mkfifo ${RPATH}/${DIRNAME}.ar"
echo "catting the local ${FIFO} fifo into remote fifo file: Authentication Successful should be displayed"
cat ${FIFO} | ssh ${USERNAME}@${SERVER} "cat > ${RPATH}/${DIRNAME}.ar" &
echo "Initiating remote extract on fifo file: Authentication Successful should be displayed"
ssh ${USERNAME}@${SERVER} "cat ${RPATH}/${DIRNAME}.ar | pax -rxpax"
echo "Removing remote fifo file: Authentication Successful should be displayed"
ssh ${USERNAME}@${SERVER} "rm ${RPATH}/${DIRNAME}.ar"
echo "Removing local ${FIFO} fifo"
rm ${FIFO}
#--- END ----
http://pastie.org/614963

No comments:
Post a Comment