0

I'm using rsync in a shell script to perform deployments of Bitbucket (Git) managed repositories. Part of the requirements for deployment is that files from several designated directories in source are aggregated into a "Common" folder in the destination. If files in these designated directories are in subdirectories, then these get copied over also.

Say "Templates" and "Webforms" are a designated directories, then it would work as follows:

Proj/Templates/t_x.html                 =>  Proj/Common/t_x.html
Proj/Templates/modal/t_y.html           =>  Proj/Common/modal/t_y.html
Proj/Webforms/wf_x.html                 =>  Proj/Common/wf_x.html
Proj/Webforms/mobile/android/wf_y.html  =>  Proj/Common/mobile/android/wf_y.html

To handle this, I loop through a list of the designated directories defined in an associative array like DIRLIST[dirname] = '/dest/dir', and use find to locate the directories to rsync. I then substitute the directory in a variable passed to rsync. This looks like the following:

for dirname in "${!DIRLIST[@]}"
    find . -type d -name "$dirname" | while read line; do
      SUBDIR="${PROJ_PATH}/Common/${DIRLIST[$dirname]}"
      if ls -1qA "${line}/" | grep -q
      then
      rsync -vrpgocuI -e "ssh <some ssh stuff>" "${SOUCRE}/" "${SUBPATH}"
      fi
    done
done

Since GIT doesn't preserve the file modification time, I'm forced to use the --checksum (-c) option. The problem is that, despite using checksum, rsync seems to overwrite files that already exist on the destination side. I've verified this by doing a file diff and both files on the source and destination are identical. Perhaps coincidental, but strangely enough, it only affect files that have the extenstion .efx

So these files wouldn't be affected

Proj/Common/t_x.html
Proj/Common/modal/t_y.html

But these would

Proj/Common/e_x.efx
Proj/Common/modal/e_x.efx

I tried to configure my rsync flags to handle this as best as possible but it's still overwriting the files. Info sec restricts us from using non-approved third-party tools, so I can't use something like vimdiff. If I use diff over ssh, that would require the remote directory to be sync'd locally and the project is too large for that to be feasible.

Does anyone have any suggestions for what might be causing this behavior, for how to modify my rsync command, or for a different approach than the one I've described?

So far I've tried using several combinations of --ignore-times, --checksum, and --size-only, but this seems to have minimal effect.

  • Run with -i or --itemize-changes and add the output from those files in your question. – BowlOfRed Apr 12 at 20:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.