How to sync local and remote directories with Raspberry PLC
Save your data by synchronizing remote and local information thanks to Raspberry Pi automation.
1 December, 2021 by
How to sync local and remote directories with Raspberry PLC
Boot & Work Corp. S.L., Fernandez Queralt Martinez

Introduction

While we work in industrial environments, data often have to be synchronized in order to keep it updated at all times.

In this post, we will learn to use the Rsynctool, with which you can synchronize all your local and remote data to any PLC! We are going to use an industrial Raspberry PLC.

Latest Posts

TOP 25 IoT Sensors
Discover how many sensors are related to IOT
How to Run Piscope on Raspberry PLC | Step by Step
Learn how to run piscope on your Raspberry PLC and see the pin digital activity

Rsync

In these blogs posts, we show you how to send files between a Raspberry Pi based PLC and your computer, Windows or Linux:

  • Rsync o 'remote sync' is a fast and extraordinarily versatile file copying tool. It can copy locally, to/from another host over any remote shell, or to/from a remote rsync daemon. 

  • It offers numerous options that control every aspect of its behavior and permit very flexible specifications of the set of files to be copied.

  • Furthermore, it is famous for its delta-transfer algorithm, which reduces the amount of data sent over the network by sending only the differences between the source files and the existing files in the destination. 

  • Rsync is widely used for backups and mirroring, and as an improved copy command for everyday use.

Synopsis

The synopsis, like cp, scp or ssh, is the same:

Rsync - Synopsis - How to sync local and remote directories with Raspberry PLC

IP addresses

These are the IP addresses of our devices. 

On the one hand, our laptop based on Linux has the IP address: 10.10.10.60 for the Ethernet interface. 

On the other hand, the industrial Raspberry Pi PLC has the IP address: 10.10.10.20 for the Ethernet interface.

IP addresses - How to sync local and remote directories with Raspberry PLC

From local to remote

Based on this, we are going to do the following:

1. We will create a local folder with 10 files on our laptop called testDir.

mkdir testDir
touch testDir/file{0..9}
ls testDir/

With the ls command, we will list the files in the folder and check that they have been created correctly.

From local to remote 1 - How to sync local and remote directories with Raspberry PLC

2. We will create a folder in the Raspberry PLC called remDir, to be able to send files from local to remote. With the ls command, we will list the files and check that it is empty:

mkdir remDir
ls remDir
From local to remote 2 - How to sync local and remote directories with Raspberry PLC

3. Now, in order to sync the data from local to the remote directory, we will execute the following command:

rsync -a testDir/ pi@10.10.10.20:/home/pi/remDir


The -a option is the archive mode. Equals -rlptoD:

-r --recursive: recourse into directories
-l --links: Copy symlinks as symlinks
-p --perms: Preserve permissions
-t --times: Preserve modification times
-o --owner: Preserve owner (super-user only)
-D: Preserve device files (super-user only) and special files.
Now, go to the Raspberry PLC, where you should be able to see the file in the remote directory.
From local to remote 3 - How to sync local and remote directories with Raspberry PLC

From remote to local

Now, we are going to do the opposite. From our local laptop, we are going to get the data from the Raspberry Pi industrial PLC.
We will use the remDir/ that we created in the Raspberry Pi PLC controller, to send files to a new and empty directory of the laptop.

1. Let's create a new directory in our computer, called newDir:

mkdir newDir
ls newDir
From remote to local 1 - How to sync local and remote directories with Raspberry PLC

2. Now, we are going to rsync from the remote host to the localhost.

rsync -a pi@10.10.10.20:/home/pi/remDir/ newDir/

In this step, we are going to emphasize the / mark next to the remDir. In this example, we will see the difference.

From remote to local 2 - How to sync local and remote directories with Raspberry PLC

Once the newDir is created, we rsync from remote to local without the / at the end of the remDir. If we miss the / mark, we will be sending the entire directory, not the content of it.
Otherwise, if we add the / mark at the end of the remDir, we will be sending the content of the directory.

Test

Now, type the following command:

man rsync

And discover all the options available in rsync command for you to optimize your file copies!

Test 1 - How to sync local and remote directories with Raspberry PLC
Test 2 - How to sync local and remote directories with Raspberry PLC
How to sync local and remote directories with Raspberry PLC
Boot & Work Corp. S.L., Fernandez Queralt Martinez
1 December, 2021
Share this post
Archive

Looking for your ideal Programmable Logic Controller?

Take a look at this product comparison with other industrial controllers Arduino-based. 

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.


Industrial PLC comparison >>>

Do you want more information?

Just fill the form!

Tell me more!