Using --files-from but also having rsync delete...

Eli eli-list at
Sun Feb 27 22:34:48 GMT 2005

Wayne wrote: 
> On Sun, Feb 27, 2005 at 04:31:15AM -0500, Eli wrote:
> > I thought I could use --include-from and then add 
> --exclude='*' to see 
> > if rsync would backup what I needed and then delete 
> anything not in my 
> > list from the rsync server side, however it did not, not to mention 
> > coming up quite short in the list of files it should have backed up
> You probably neglected to add an --include='*/' to include 
> all directories on the way down to the files.  I.e.:
> rsync -av --include='*/' --include-from=files_from_file 
> --exclude='*' \
>   --delete /src/ /dest/

I had attempted with a list of files with absolute paths, and added
--include='/home' and --include='/home/mail' (the src dir is /home/mail)
before my --include-from= line, then after that had --exclude='*'.

It would build the file list and copy over some files, but not everything.
Even with --delete-excluded it still didn't delete files on the dest server
that weren't on the src system.

Oh, and with the above example, "a little slower" is a severe
understatement!  I've issued the command about an hour ago and it's still
just at "building file list ...".  Something tells me this isn't working
(and I can't have it take this long to do nothing)...
> That works as long as all the files in the "files_from_file" 
> are relative to the same "/src/" path.  It also forces rsync 
> to recurse through all the directories, which makes it run a 
> little slower.

My preferred method of using rsync would be to use --files-from= and yes,
the paths in that file are relative to the src directory (/home/mail).  I
tried with --include='*/' before that and --exclude='*' (and '**' as well to
test) after my --files-from= but that caused rsync to just copy directories.
I added --include='*' so it copied everything over, but it seems that rsync,
when using --files-from, makes the --files-from list it's *absolute* list of
files so --include & --exclude are based off of that, rather than the
specified src dir.

I'm sure this is all obvious to you, but I'm just figuring out how --include
and --exclude work, and it seems it's not doing what I'm hoping.
> Another potential solution is to generate the list of deleted 
> files on the system as you generate the file-from list, and 
> then use a command like this to delete them:
>     ssh -l remote_user remote_host xargs rm </local/delete_list

Yes I had thought of doing something similar.  I can't generate a list of
files to delete because they don't exist, I'd have to compare against the
list of files I want to copy over and delete anything not in that list which
is basically what I'm trying to have rsync do for me.

The commands I'm testing with is:

file=/var/tmp/tmp$$ && find /home/mail -mindepth 1 -mtime +2 -not -uid 0
-not -iname '' -not -iname '*.uid' -printf "%P\n" > $file && rsync
-a -R --numeric-ids --files-from=$file /home/mail`hostname`/
&& rm -f $file

Of course I change the options to rsync as I'm testing - I've fiddled with
includes and excludes to no avail so far.  It seems impossible to tell rsync
to copy the files in --files-from, and to delete any file on the destination
side that is not in that list, thus synchronizing a list of arbitrary files
from client to server and maintaining only that list and nothing more on the
server side.

Failing that, my last option is to simply mount the server side rsync
directory via samba, rsync the files over which I can do just fine, then run
another shell cmd to prune out all files not in my list of files copied
over.  Kinda kludgy but it would work - I was just hoping it wouldn't come
to that.

Any more thoughts/ideas are more than welcome.


More information about the rsync mailing list