Sean Carolan
2012-Oct-17 16:35 UTC
[CentOS] Rsync - include only files containing matching string
I have a string, "2012_10_16"; let's call this $YESTERDAY How can I rsync a file tree from a remote machine to the local one, including *only* filenames that contain the matching string? I've read the man page and googled around but can't seem to get the syntax right. I either end up syncing all the files, or none of them. Here's how the code looks now (I will remove the dry run once it is working): rsync -avz --dry-run --include=*$YESTERDAY* remotehost:remotedir/ localdir/transfer/
Marcelo Roccasalva
2012-Oct-17 16:59 UTC
[CentOS] Rsync - include only files containing matching string
On Wed, Oct 17, 2012 at 1:35 PM, Sean Carolan <scarolan at gmail.com> wrote:> I have a string, "2012_10_16"; let's call this $YESTERDAY > > How can I rsync a file tree from a remote machine to the local one, > including *only* filenames that contain the matching string? I've > read the man page and googled around but can't seem to get the syntax > right. I either end up syncing all the files, or none of them. > Here's how the code looks now (I will remove the dry run once it is > working): > > rsync -avz --dry-run --include=*$YESTERDAY* remotehost:remotedir/ > localdir/transfer/rsync -avz --dry-run --include=*$YESTERDAY* --exclude=* remotehost:remotedir/ localdir/transfer/> _______________________________________________ > CentOS mailing list > CentOS at centos.org > http://lists.centos.org/mailman/listinfo/centos >-- Marcelo "?No ser? acaso que ?sta vida moderna est? teniendo m?s de moderna que de vida?" (Mafalda)
Les Mikesell
2012-Oct-17 17:04 UTC
[CentOS] Rsync - include only files containing matching string
On Wed, Oct 17, 2012 at 11:35 AM, Sean Carolan <scarolan at gmail.com> wrote:> I have a string, "2012_10_16"; let's call this $YESTERDAY > > How can I rsync a file tree from a remote machine to the local one, > including *only* filenames that contain the matching string? I've > read the man page and googled around but can't seem to get the syntax > right. I either end up syncing all the files, or none of them. > Here's how the code looks now (I will remove the dry run once it is > working): > > rsync -avz --dry-run --include=*$YESTERDAY* remotehost:remotedir/ > localdir/transfer/Rsync's include/exclude syntax is pretty quirky... First it will include everything by default and it applies the directives in the order specified so if you don't want everything you need --exclude='*' at the end of the list. Also, patterns apply to directories, so you need to --include='**' as a special case to keep that exclude from excluding subdirectories. And if you want all filenames including your string you need to put *'s at each end (that's not a quirk, but may be tricky to arrange with variable expansion but not shell wildcard expansion). Maybe: rsync -avz --dry-run --include='**' --include='*2012_10_16*' --exclude='*' remotehost:remotedir/ localdir/transfer/ Not sure if that traverses all subdirectory levels or if ** is just one level. -- Les Mikesell lesmikesell at gmail.com