I have been working on this for several days and no matter what I do I can't get it to work. I've read practically every Q&A on StackExchange network about rsync but still not found the answer.
Basically I am writing a website deploy tool and it uses rsync to move files from a source Git repo to deploy Git repo; the destination. Committing to the deploy repo actually deploys the code to the web server so I am delaying with rsync between two different directories.
It is very important that any files that the developer deleted in the source repo also get deleted in the deploy repo. However, there are selected files that are in the deploy repo that need to not be deleted Specifically this are files that the hosting provider provides and are needed in production but that are problematic to maintain in the source repo.
I understand from what I have read in man
, here, and elsewhere that if I add the names of the files that are in the deploy/destination repo that I want to keep to an --exclude-from
file
Here is what I am doing, basically:
rsync --archive --verbose \
--exclude ".git" --exclude ".git*" \
--exclude-from="/tmp/excludes.txt" --delete-after \
/dir/to/source/repo/ \
/dir/to/deploy/repo
And for example purposes let's say this is the contents of /tmp/excludes.txt
:
/foo/bar/baz.php
Now when I have tried this using a trivial example locally it always seems to work as expected. But when I use it with CircleCI in a real-world deploy scenario, rsync
always deletes /foo/bar/baz.php
after running the above command.
Can you see what I am doing wrong? Thanks in advance.
UPDATE - THE ABOVE DOES WORK
Turns out the logic in my script running in CircleCI was at fault, and I just could not see it. I was running multiple rsync commands with different roots (essentially subdirectories of my main root) because of different rules needed, and one list of exclude files with filepaths that were all based on the main root. Ugh.
Anyway dear reader, the upshot is that the above example indeed works as I describing how I wanted it to work.
/foo/bar/baz.php
actually/dir/to/deploy/repo/foo/bar/baz.php
? If not, what is the relationship between the target directory and this exclusion?/foo/bar/baz.php
is actually/dir/to/deploy/repo/foo/bar/baz.php
. Wow, you are active here. I was just reading your answer on another question.--backup
and--backup-dir
I learned about from one of your answers to see if I could look for the files there, and now it is working as expected. Does that many any sense?!?!?!?rsync
command in the question should not delete files on the target at all since you don't use--delete
nor--delete-excluded
. Du you haversync
set up as an alias for something?--delete-after
implies--delete
.