I thought this command would do what I wanted, but instead it doesn't transfer any files: rsync -avh --stats --password-file=/var/rsync.passwd --include=Maildir/ --exclude=* mail::root/usr/home /backup/usr/ I want to backup ONLY the /usr/home/*/Maildir directories. I don't want any other files from any other directories to be transferred. I can see in the man page where this is a problem: when using the --recursive (-r) option (which is implied by -a), every subcomponent of every path is visited from the top down, so include/ exclude patterns get applied recursively to each subcomponent's full name (e.g. to include "/foo/bar/baz" the subcomponents "/foo" and "/foo/bar" must not be excluded). It then gives an example of including the parent directories. Trouble is, I do not want any files in /usr/home/fred/ to be synced at all, only the files (and directories) in /usr/home/fred/Maildir/ Also, I don't necessarily know all the pathnames in /usr/home/; I don't want to have to build a manual include list every time I want to sync these folders. -- MY MOM IS NOT DATING JERRY SEINFELD Bart chalkboard Ep. AABF06
On Thu, Dec 24, 2009 at 05:50:22AM -0700, LuKreme wrote:> rsync -avh --stats --password-file=/var/rsync.passwd --include=Maildir/ --exclude=* mail::root/usr/home /backup/usr/That will send the Maildir directory (without any content) if that directory exists in the root of the transfer. If you want to send things inside the Maildir, you need to either specify includes for that information, or limit the excluding. For instance, assuming that the Maildir is in the root of the transfer, this is better: --include=/Maildir/ --exclude=/* Since both are anchored, this includes this top-level dir, excludes everything else in the top-level (root of the transfer), but does not exclude the files that are in the included dir. Another option: --include=/Maildir/*** --exclude=* If your rsync is new enough to understand "***", that includes both the dir and the contents, which overrides the global exclude. If your rsync is not new enough to understand "***", then you'd need a separate include for the dir and the content: --include=/Maildir/ --include=/Maildir/** --exclude=* The first method is the best when it is something this simple, but one of the latter methods can be useful when doing something more complex. ..wayne..
On Thu, 24 Dec 2009, LuKreme wrote:> I thought this command would do what I wanted, but instead it doesn't transfer any files: > > rsync -avh --stats --password-file=/var/rsync.passwd --include=Maildir/ > --exclude=* mail::root/usr/home /backup/usr/ > > I want to backup ONLY the /usr/home/*/Maildir directories. I don't want > any other files from any other directories to be transferred. > > I can see in the man page where this is a problem: > > when using the --recursive (-r) option (which is implied by -a), every > subcomponent of every path is visited from the top down, so include/ > exclude patterns get applied recursively to each subcomponent's full > name (e.g. to include "/foo/bar/baz" the subcomponents "/foo" and > "/foo/bar" must not be excluded). > > It then gives an example of including the parent directories. > > Trouble is, I do not want any files in /usr/home/fred/ to be synced at > all, only the files (and directories) in /usr/home/fred/Maildir/The following comes close: rsync -avh '--include=/*/' '--include=/*/Maildir/***' '--exclude=*' home/ backup/ (Might need to preface the first /* components in the patterns with 'root/usr/home' or '/root/usr/home' for your case.) I say "comes close" because it gets an extra empty directory for every user directory, even if it doesn't contain a Maildir.> Also, I don't necessarily know all the pathnames in /usr/home/; I don't > want to have to build a manual include list every time I want to sync > these folders.Not sure if "I don't want to have to build a manual include list" precludes using a script to generate the list, but for solving this same problem a while back (backing up user maildirs), I used something like the following: getent passwd | cut -f6 -d: | sort | uniq \ | perl -lnwe '$_.="/Maildir"; print if -e' \ | xargs -iZ rsync -avzR /./Z/ backup/Z/ I don't remember if that's the exact rsync command, but the point is that it wasn't too hard to generate the list of Maildir directories, assuming it's possible to list the homedirs. Best, Ben