Raspberry Pi-rsync and Raspberry Pi rsync
You can use rsync to synchronize folders between different computers. You may want to transfer a file from your desktop computer or laptop to your Raspberry Pi and keep the file updated. Or, you want to automatically transfer the photos taken by Raspberry Pi to your computer.
Using SSH-based rsync allows you to automatically transfer files to your computer.
The following example sets the photo folder on your Raspberry Pi to automatically synchronize to your computer:
Create a directory named camera on your computer:
mkdir camera
Log on to Raspberry Pi to run
Hostname-ICommand to view the IP address of Raspberry Pi. In this example, Raspberry Pi has created a scheduled task, which takes a picture every minute and uses a timestamp to save the photo to the local camera directory on the SD card.
Run the following command on your computer (replace it with your own Raspberry Pi IP address ):
rsync -avz -e ssh pi@192.168.1.10:camera/ camera/
This command will copy all files from the Raspberry Pi's camera folder to your computer's camera directory.
To maintain folder synchronization, run this command in cron.
Address: http://www.raspberrypi.org/documentation/remote-access/ssh/rsync.md
In linux, how does one determine whether a single or a file is successfully synchronized when rsync is used to synchronize files?
This problem can be solved. You only need to add a command after your command line.
# Rsync... | echo! $
What is the meaning of the command? That is to say, if the previous command fails, the echo will be executed! $ Command, and! $ Variable indicates the parameter followed by the execution of the previous command. That is to say, if an error occurs when the rsync command synchronizes a file, the file name will be! $ Is recorded, so I think using this command we can know that the file encountered a problem when executing the rsync command. The command was successfully tested by myself. However, because my rsync didn't fail, I modified | to & for testing. The principle is the same.
I don't know if this is what LZ wants?
Shell scripts I used rsync to synchronize files once every 5 minutes. If there are too many large file synchronization processes
#! /Bin/bash
Ps-fe | grep rsync | grep-v grep
If [$? = 1]
Then
Rsync XXX
Else
Echo No need to do rsync
Fi
Then set crontab and execute it every 5 minutes.