Rsync usage in linux
rsync stands for "remote synchronization." It is a powerful and versatile command-line utility used for synchronizing files and directories between two locations, either on the same system or between different systems over a network. rsync is commonly used for backup and data transfer tasks, especially when you want to efficiently synchronize large amounts of data while minimizing the amount of data transferred.
Rsync installation
sudo apt-get update
sudo apt-get install rsync
the example without ssh key pair and port default 22
rsync -chavzP -e "ssh" root@165.11.1.168:/odoo/custom/addons /home/kashif/files
Below example is getting data from a server that has ssh key and ssh port 2222
rsync -chavzP -e "ssh -i /home/ssh/id_rsa -p 2222" root@135.181.10.106:/odoo/odoo-server/odoo-dir/filestore /home/destination_dir
The -e option in rsync is used to specify the remote shell that rsync should use when connecting to a remote server for synchronization. It allows you to choose a different remote shell than the default, which is typically SSH (ssh).
Between two server data migration
from source server to destination server without ssh key
rsync -av -e ssh /home/uhd/test/* ubntu4@62.201.235.204:/home/ubntu4/test
if your destination server has ssh key then
Copy Public Key to Source Server
ssh-copy-id -i ~/.ssh/id_rsa.pub username@source_server_ip
Copy Public Key to Destination Server:
ssh-copy-id -i ~/.ssh/id_rsa.pub username@destination_server_ip
Use the private key from your local machine's ~/.ssh/ directory when accessing the destination server using SSH. You do not need to copy the private key to any remote server.
rsync -chavzP-e "ssh -i /path/to/your/private/key -p ssh_port" /path/to/source/directory username@destination_server_ip:/path/to/destination/directory
if both server has different ssh port too
rsync -chavzP -e "ssh -i /path/to/your/private/key -p source_ssh_port" /path/to/source/directory username@destination_server_ip -e "ssh -p destination_ssh_port":/path/to/destination/directory