Rsync script and backup problems.

Hello everybody

I'm triing since few days to do this. So sorry if my question looks stupide, but i've tried.

I have to get picture from a folder (who is updated automaticly and with subfolder) with theirs extensions (i'm ok on that) and this files have to me copied in a folder where a website base on php will edit them (rename and creating of and xml file).
The problem is because of the rename function of the script when I do again the copy, it put it back and the script rename it... I've tried rsync with --backup with a folder --backup-dir define, but it's still doesn't work, it's still sending file in backup folder desite their presence in the incremental folder.

Here is my code. You can laugh on them, i'm not a pro shell script coder.

#!/bin/bash
find  '/home/name/picture' -name '*.jpg' | while read FILE ; do rsync --backup  --backup-dir=incremental --suffix=.old  "$FILE" /var/www/media ; done
wget --spider 'http://myscript.php' ; 
#exit 0

When I lauch just the find and rsync functions, it doesn't put all my files in the incremental folders (and the extensions). I have to run the functions twice to get all files in incremental folder. This the command.

find  '/home/name/picture' -name '*.jpg' | while read FILE ; do rsync --backup  --backup-dir=incremental --suffix=.old  "$FILE" /var/www/media ; done

Thank in advance for your help.

PS; A little more thing, would be to replace '.' with a 'space' just after the *.jpeg copy. My php script have some problem to define file with with comma because of the extension. I'm finking about a command with 'find' like I like just below with a 'sed' function? It's good?

you can try this..

find ! -wholename /home/name/picture -name '*.jpg'|xargs -I '{}' rsync -abR --backup-dir=incremental --suffix=.old '{}' /var/www/media/

Thanks. I'm gonna try now.

---------- Post updated at 01:41 PM ---------- Previous update was at 01:02 PM ----------

I miss something, I have to grab image from all folder and sub folder to one folders. I tried your script and it keep the directory.
I get also this for xargs

xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option

try

find /home/name/picture -name '*.jpg' -print0|xargs -0 -I '{}' rsync -ab --backup-dir=incremental --suffix=.old '{}' /var/www/media/

or

find /home/name/picture -name '*.jpg' -printf '"%p"\n'|xargs -I '{}' rsync -ab --backup-dir=incremental --suffix=.old '{}' /var/www/media/

Hello

Thanks for your answer. I just try it. The files are copy but nothing go in 'incremental' folder, so when I edit the name of my copied files and do again the command the files with name's changed are copied again.

It's strange because rsync doesn't do what I want. No suffix and no backup-dir... :frowning:

  • if your files are not modified rsync does not do anything.therefore incremental folder is empty.
  • if you change your file's names then rsync behaves on these such as new files and copy t target folder.

regards
ygemici

Thanks for your feedback.

Anybody have a solution?

After few hours of hard work the answer has been found on another forum (can't post link).
It's on KornShell

#!/bin/ksh
DEST_DIR=/destination
HIST_DIR=/images_bck
SOURCE_DIR=/images
 
find ${SOURCE_DIR} -name "*.jpg" >${HIST_DIR}/tmp.file
exec 3<${HIST_DIR}/tmp.file
 
while read file <&3;do
  file_name=$(basename "${file}")
  if [ ! -f "${HIST_DIR}/${file_name}.old" ];then
    cp -p "${file}" "${HIST_DIR}/${file_name}.old"
    cp "${file}" "${DEST_DIR}"
  fi
done
exec 3<&-
[ -f ${HIST_DIR}/tmp.file ] && rm -f ${HIST_DIR}/tmp.file