This was a task I had to do in order to have Drupal working better behind a load balancer. Anyhow, it can be used in a number of ways, I’ll let it to your imagination and use cases.
Install RSYNC
To install RSYNC on Ubuntu systems:
sudo apt install rsync
rsync specific case KB
These are some articles I read in order to understand how to connect to another server to sync folders:
- https://linuxize.com/post/how-to-use-rsync-for-local-and-remote-data-transfer-and-synchronization/
- https://www.digitalocean.com/community/tutorials/how-to-use-rsync-to-sync-local-and-remote-directories#how-to-use-rsync-to-sync-with-a-remote-system
- https://bobcares.com/blog/rsync-host-key-verification-failed/
- https://linuxize.com/post/how-to-setup-passwordless-ssh-login/
Rsync absolute paths:
rsync -a --relative /home/bcntest/public_html/web/sites/default/files
The rsync command with all the parameters
A brief description of the command:
- it connects using a certificate
- it executes the local AND remote command with sudo
- executes the ssh connection quietly (-q)
- syncs the ‘files/’ (don’t forget to put the “/” at the end of the path) folder from instance 1 to instance 2
sudo rsync -Pav -e "ssh -q -i /home/user/.ssh/privatekey_private.pem" --rsync-path="sudo rsync" /home/user/public_html/web/sites/default/files/ ubuntu@10.0.1.3:/home/user/public_html/web/sites/default/files/
sudo rsync -Pav -e "ssh -q -i /home/user/.ssh/privatekey_private.pem" --rsync-path="sudo rsync" /home/user/public_html/private_files/webform/ ubuntu@10.0.1.3:/home/user/public_html/private_files/webform/
Below is the SSH command alone, you can use it to test if the connection is working:
ssh -q -f -i /home/user/.ssh/privatekey_private.pem ubuntu@10.0.1.3 -tt
ssh -i /home/user/.ssh/privatekey_private.pem ubuntu@10.0.1.38 -tt
Some extra content
I tried to enable certificate logins with webmin and usermin to no success, if anyone knows how to do it please leave a comment.
SSH via webmin: http://doxfer.webmin.com/Webmin/SSH_Server