Hambarde
Posts: 6
Joined: Fri Jun 16, 2017 5:24 am

Rsync selective copy with delete

Fri Jan 19, 2018 12:34 pm

Hi Every one,
I need help with small command

In /home/pi there are two directories media and adverts.
I want all mp4 files from media to be copied in adverts.
If mp4 file is deleted from media dir, it should also get deleted from adverts.

So I tried below rsync command, it copies new files, but could not delete if it is deleted from media folder.
media folder got other files such as txt, json , etc.. which I don't want.

Code: Select all

rsync -av --delete /home/pi/media/*.mp4 /home/pi/adverts
any help with rsync, I want to use rsync only on changes because want to reduce file R/W on SD card.

Alternately I can archive same with small sh as below, but it takes a long route.

Code: Select all

#!/bin/sh
cd /home/pi/adverts
rm *
cd /home/pi/media
cp *.mp4 /home/pi/adverts
exit 
I am going to run this from crontab every 5min or so.


Please guide me with correct route.
__________________________________________________________________________________________
:arrow: mail me - [email protected]

Hambarde
Posts: 6
Joined: Fri Jun 16, 2017 5:24 am

Re: Rsync selective copy with delete

Tue Jan 23, 2018 5:17 am

Here is actual script which solved my problem

Code: Select all

#!/bin/sh
while
 inotifywait -e create -e delete  "Source DIR"
do
 rsync -zarv  --include="*.mp4" --exclude="*" --delete "Source DIR" "Destination DIR"
done
This script will copy all mp4 files from Source DIR to Destination DIR (incremental), and also will delete all mp4 files from Destination DIR which are not in source DIR.
__________________________________________________________________________________________
:arrow: mail me - [email protected]

Return to “General discussion”

Who is online

Users browsing this forum: No registered users and 38 guests