LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to rsync certain filename - quick question (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-rsync-certain-filename-quick-question-4175446838/)

mpc8250 01-22-2013 11:20 PM

How to rsync certain filename - quick question
 
Hi All

We have to rsync all files under a folder /scratch/a/b between hosts A and B.
Under /scratch/a/b, there's a set of files with same filename but under different subdirectories at the same level:
eg
/scratch/a/b/config.txt
/scratch/d/e/config.txt
:
:

We're interested in only copying/syncing up the config.txt files but yet keep the same directory strucutres in A and B. ie no structural change but update only those config.txt files from A to B while keeping the rest of the files and directories structures intact.

We're not sure how to include and exclude with rsync.

Thanks

lleb 01-23-2013 07:16 AM

just create a small txt file, call it excludes.txt and populate it as follows:

Code:

+ config.txt
the + tells rsync to include and a - would tell it to exclude from a specific directory. you might also try just a wild card in the source path. use the -a argument to keep the file structor.

mpc8250 01-23-2013 02:36 PM

Hi lleb

This does not seem to work.
No config.txt is copied.
Any tips ?

rsync -auvc --include 'config.txt' --exclude '*' --delete-delay /scratch/jobs root@host.com:/scratch/jobs


Thanks

lleb 01-24-2013 01:48 PM

you should adjust your format to the following:

Code:

--exclude-from=/path/to/excludes.txt
again you need to put into the excludes.txt a + or - then a file name/type that you want to add, ignore in the rsycn. also use the full path to the excludes.txt file, not just =excludes.txt as that may or may not work. the full path will always work.

you can add some variables to your script to address the pathing as that is typically what i do.

Code:

HOMEDIR="$HOME"
rsync -aviS --exclude-from=${HOMEDIR}/excludes.txt source/ destination/

my excludes on some systems looks roughly like this:

Code:

- *.tar
- *.tgz
- *.bz2
- *.bz
- *.google*
- *.mozilla*

as you can see this will tell rsycn to never copy over any of those types of files. in your case you would add the + config.txt to the excludes.txt file.

suicidaleggroll 01-24-2013 02:30 PM

Quote:

Originally Posted by lleb (Post 4876898)
you should adjust your format to the following:

Code:

--exclude-from=/path/to/excludes.txt
again you need to put into the excludes.txt a + or - then a file name/type that you want to add, ignore in the rsycn. also use the full path to the excludes.txt file, not just =excludes.txt as that may or may not work. the full path will always work.

you can add some variables to your script to address the pathing as that is typically what i do.

Code:

HOMEDIR="$HOME"
rsync -aviS --exclude-from=${HOMEDIR}/excludes.txt source/ destination/

my excludes on some systems looks roughly like this:

Code:

- *.tar
- *.tgz
- *.bz2
- *.bz
- *.google*
- *.mozilla*

as you can see this will tell rsycn to never copy over any of those types of files. in your case you would add the + config.txt to the excludes.txt file.

There's no need to put it in a file, everything can be specified on the command line.

suicidaleggroll 01-24-2013 02:31 PM

Quote:

Originally Posted by mpc8250 (Post 4876350)
Hi lleb

This does not seem to work.
No config.txt is copied.
Any tips ?

rsync -auvc --include 'config.txt' --exclude '*' --delete-delay /scratch/jobs root@host.com:/scratch/jobs


Thanks

That's because you're excluding all of the directories that could contain a config.txt. Try this:

Code:

rsync -auvc --include '*/' --include 'config.txt' --exclude '*' --delete-delay /scratch/jobs root@host.com:/scratch/jobs


All times are GMT -5. The time now is 03:42 PM.