> For the complete documentation index, see [llms.txt](https://docs.cloudeka.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cloudeka.ai/guideline-for-enterprise/reference/micellaneous/how-to-sync-local-and-remote-directories-with-rsync.md).

# How to Sync Local and Remote Directories with Rsync

## Introduction

Rsync (Remote Synch) is a command line that can be used to transfer and synchronize files or directories between two locations, either within a single computer or between computers over a network. There are main features in the rsync command, including the following:

1. File and Directory Synchronization, can synchronize files and directories from one location to another by transferring only the differences (deltas) between the source and destination. This is very efficient compared to traditional file transfer methods that transfer entire files even if there are only minor changes.
2. Incremental Transfer uses an algorithm that detects differences between the source and destination files, so only the files' changed parts are transferred. This saves bandwidth and time, especially for large files.
3. Support for Network Transfer can be used to transfer files between computers over a network using the SSH (Secure Shell) protocol for security. This makes it a powerful tool for data backup and replication.
4. One-Way and Two-Way Synchronization performs one-way synchronization, where files from the source are synchronized to the destination. However, with some settings, Rsync can also be used for two-way synchronization.
5. Data Compression compresses data before transferring it, reducing the amount of data that must be sent over the network, increasing transfer efficiency.
6. Time-Based Storage supports the option to store snapshots or time-based backups using hard links, allowing older backups to be stored efficiently.

## Rsync Command on Linux

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfm0ttHLAtOiGpOxg11u0tU2vaV7IgRDi23gWsn2T-iH0RLa-fSkc6LCk7u55U4lMKvO6Jnl3_IriDqrscF47AitHo3uRud2d3P7SWkywvqnu7mBcMfiRMgj15cy6yyvgTy-1M7yRARXz6V5k4JllhScsFR?key=djhHFQwCohBTlvEjNCoo2g" alt=""><figcaption></figcaption></figure>

## Using Rsync to Sync with a Remote System

To use rsync for synchronization with a remote system, you need to configure SSH access between the local computer and the computer to be accessed, and install rsync on both systems. Once SSH access is verified between both machines. The following are the steps for using rsync to synchronize remotely on the Cloudeka Portal Service.

1. On the Instance menu page in the Cloudeka Portal Service, access the rsync2 instance console by pressing the More button and selecting Access Console. Enter the username with root and password that was registered when creating the Instance.&#x20;

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXcAtxf4B7fK20gI1Q6jVm_evfpEwKoIEej2hys-YIve_PBy6Z-iMUUdY-onJ5I4fUu3R-sYBoMQGuMKdFBHK8i9AWKYcnn9v4Z7XU9ZXucjo4XoGDbSo4XFBa47GAwygggHrULCf8x1NpwugEfDvKkyrUAe?key=djhHFQwCohBTlvEjNCoo2g" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXe6PZMUWBDWZWq68CvHwMr3DBk3B89cIbk3zAWI30GCy-OOG42MtmWNDHHjFvs6qt5DeJ7jcIQCUY9pmBlUfTRkdB3wa65aea_uJZquiuhsjTxy_lZN2y8XNTUpAN3wwy9yw_vtcnrQ3177k32a0WipC81S?key=djhHFQwCohBTlvEjNCoo2g" alt=""><figcaption></figcaption></figure>

2. Create a new directory on the rsync2 Instance, namely dir3, by running the following command

```
mkdir dir3
```

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXc20Gl8D5YdJR8FvTCpxl8TeO0bIFwfyA6MJtOipbIH2rc_-mJZDwlkxU2rQ8p1N8GYQaTqjKx49yt91DSO8y5nkwe1IBTcgmDIz5EEM09wr3JhpekCCFSNEOD-chLL9PxbKnTjz-GrLec8Rrt6ZjRgNlZw?key=djhHFQwCohBTlvEjNCoo2g" alt=""><figcaption></figcaption></figure>

3. After creating a new directory in rsync2 instance namely dir3. The next step is that you can synchronize dir1 on the rsync instance to dir3 on the rsync2 instance. Because currently you are accessing the rsync2 console, you have to log in to the rsync instance using the IP address 192.168.1.137, so you need to access it via SSH by running the command syntax below.

```
ssh root@192.168.1.137
```

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXcXyZZeFm47jlfu5oUtD-nD6LFIqK8LayZ8UJMUMlnbHa33wIDHySwQ13rXdjGWpBldjAn8S-pYcuQV9KECsbhb1NcSIhzDnKcMpqawsRYuyXLuew9cHFc6Byt0MapADOsoaGBEDkLMBNcVogwBNQK3fpN5?key=djhHFQwCohBTlvEjNCoo2g" alt=""><figcaption></figcaption></figure>

4. After you have successfully logged into the rsync instance at IP address 192.168.1.137, run the command below. Please pay attention to the command being executed, that you want to transfer the actual directory, so you will omit the slash at the end:

```
rsync -a ~/dir1 username@remote_host:destination_directory
```

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfiTpw9qtK7u1x4HP6qacAHwp0Ndp68_wiIgK1xwYDt5ihu-w3GlrrRiWTUPC719sLPALzxGf2lUpK0Rj-8WIRAytbrqkwkpTGy04tmviPoplT329k3Y22bHsT40-HfTqzu89kcOraXsyEgCNx3MFgYqkma?key=djhHFQwCohBTlvEjNCoo2g" alt=""><figcaption></figcaption></figure>

5. Run the exit command to exit ssh on the rsync Instance and it automatically returns you to the rsync2 Instance.

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXd6dnu2tqzy-b_QPDyPkDyeSOoiQYWmO8elqURMa9QoAXOaid9radQ1K5-MsUctMxQyMlsUan7eB_io2u_Xl0FwywHEH84aNseXnq2LY1yN0c53NbIIDXGIF8WVU3s78jAJWJdDh1tWgujc4y8IvE9NgZZ4?key=djhHFQwCohBTlvEjNCoo2g" alt=""><figcaption></figcaption></figure>

6. To ensure that dir1 on the rsync instance has been copied to dir3 on the rsync2 instance, go to dir3 and view the contents of dir3 by running the command syntax below.

```
cd dir3
```

```
ls
```

If successful, on dir3 there is dir1 which has been successfully copied from the rsync instance.

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXexNe0X8DWEIQ2351vawYRHjwQhsLjLFv6BIDA2SCNBpUQU9-c5odlqMQjExICWm_UR8sempO-Fbh3BSEU1tvC6b8eIZuLVk03OE67VSAeZEceQrTsta2AbQnDC42j8_GL0y9TxQ4ivSaSKnKMi--00t7M?key=djhHFQwCohBTlvEjNCoo2g" alt=""><figcaption></figcaption></figure>

7. Go to dir1 and see the contents of the copied file by running the command syntax below.

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXdGvVxEIrk-7qqu7hYzehfLBtwZswqlXQRzOarCEyU3TqVcyyF9cfsKzfNoVN2b137DfNS6zF6_eFepZF0O2awHisKaMBN5CdnrHguge6TztBXA6Gwn3Fe8JHf08ijnN2HjsKsISeFTdLXpAce-DPCpNGb-?key=djhHFQwCohBTlvEjNCoo2g" alt=""><figcaption></figcaption></figure>

## Conclusions

Rsync can speed up file transfers over network connections and increase resilience in local directory synchronization. The flexibility offered by Rsync makes it an ideal choice for a variety of operations involving files, both small and large.

By mastering Rsync, you can design complex backup operations and have granular control over the transfer process. This capability allows you to determine exactly how and what to transfer, ensuring your data remains secure and in sync.
