I was working on a project that involves moving data from one point to other, it involves a verity of commands. I am listing some useful tricks.
1. This script is a tiny script to compress, generate md5 and transfer any directory.
tar cvJf $1.tar.xz $2;
md5sum $1.tar.xz > $1.md5sum
scp -i<private key> -P<port> $1.md5sumĀ <user>@<hostname>:<path>
scp -i<private key> -P<port> $1.tar.xz <user>@<hostname>:<path>
copy this code to a file zipnmove.sh and make it executable with the command
chmod +x zipnmove.sh
and then run the command
zipnmove.sh foldername`date +%d%m%Y` foldername
remove the date part if you don’t want the current date to be part of the filename.
few things to be taken care before you run this command public key of the local system must be already added to remote system.
2. find out public key from private key
ssh-keygen -y -f ~/.ssh/<private key>
3. Another method is using rsync
Before using this command make sure public key is already added to remote system.
rsync -av --progress --rsh="ssh -i <private key> -p <port>" <file or directory to push> <remote system>
drop –rsh if the keys have default names and are in default location same with port. using ‘z’ in rsync will compress the data while sending, us it if needed.