Tools · 2 min read · Updated

How to sync two folders between two Google VM instances?

Rsync two folders Google Cloud

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

whoami

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

cat /home/WHOAMIOUTPUT/.ssh/id_rsa.pub

If no key is set then add the SSH key in the WEB1 VM instance just by running the following command:

ssh-keygen

Run the following command to see the SSH public key

cat /home/WHOAMIOUTPUT/.ssh/id_rsa.pub

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

sudo rsync -e  "ssh -i /home/WHOAMIOUTPUT/.ssh/id_rsa" -avzh /FROM_FOLDER_Path WHOAMIOUTPUT@11.22.33.44:/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@11.22.33.44:/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.

Rupak Nepali
Written byRupak Nepali

Rupak Nepali is a web developer, manage Webocreation website and the author of six books:
Getting Started with OpenCart Module Development (Packt, 2013),
OpenCart Theme and Module Development (Packt, 2015),
OpenCart 4: Dev Guide for Themes & Extensions (2024),
OpenCart 4: User Manual (2025),
Cloudflare for the Enterprise Website (2026) and
The Technical Web Guide for Marketers (2026).
Rupak has built OpenCart stores and extensions since 2010, has published more than 600 tutorials on Webocreation, and shares free OpenCart extensions on GitHub.
Find Rupak on
GitHub | Amazon | LinkedIn | X | YouTube.

Leave a Reply

Your email address will not be published. Required fields are marked *