Let’s say your first VM instance is WEB1 and the second VM instance is WEB2. In the WEB1 VM instance, there is one folder called “uploads” at /var/www/html/wp-content/ and you want to transfer all the files and folders inside it to WEB2 at /var/www/html/wp-content so for that you can use the rsync command.
First, check if the rsync is installed in the WEB1 VM instance by running
Then check who you are, by running the command
Let’s say the output is WHOAMIOUTPUT. Now view the content of the public key
If no key is set then add the SSH key in the WEB1 VM instance just by running the following command:
Run the following command to see the SSH public key
Copy the output, it starts with ssh-rsa ….
and add it to the Metadata of the Google Cloud.
Go to Google Cloud>> Select the project >> Compute Engine>> Metadata >> SSH KEYS tab edit it and enter the SSH public key that you copy from above at the end. If your WEB2 VM instance is in a different project then you need to select a different project.
Now find the IP of the WEB2 VM instance by going to Project >> Compute Engine >> VM instance and get the IP address of WEB2 VM, let’s say the IP is 188.8.131.52, then your command will be like below:
sudo rsync -e "ssh -i /home/WHOAMIOUTPUT/.ssh/id_rsa" -avzh /FROM_FOLDER_Path WHOAMIOUTPUT@184.108.40.206:/TO_FOLDER_PATH
When you have to move from the WEB1 var/www/html/wp-content/uploads folder to the WEB2 var/www/html/wp-content/ then below is an example command.
sudo rsync -e "ssh -i /home/WHOAMIOUTPUT/.ssh/id_rsa" -avzh /var/www/html/wp-content/uploads WHOAMIOUTPUT@220.127.116.11:/var/www/html/wp-content/
In this way, you can sync two folders between two Google VM instances by which you may have removed the export-import processes. Please let us know if you know of any other easy way.