How to sync two folders between two Google VM instances?

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

rsync --version

Then check who you are, by running the command


Let’s say the output is WHOAMIOUTPUT. Now view the content of the public key

cat /home/WHOAMIOUTPUT/.ssh/

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

cat /home/WHOAMIOUTPUT/.ssh/

Copy the output, it starts with ssh-rsa ….

SSH public key

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.

Metadata Google Cloud Platform

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, then your command will be like below:

sudo rsync -e  "ssh -i /home/WHOAMIOUTPUT/.ssh/id_rsa" -avzh /FROM_FOLDER_Path WHOAMIOUTPUT@

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@

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.

Previous article13 UI/UX design tools that will be used in 2024
Next articleTips to Overcome Mobile App Deployment Challenges


Please enter your comment!
Please enter your name here