LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-22-2013, 11:20 PM   #1
mpc8250
LQ Newbie
 
Registered: Jan 2013
Posts: 7

Rep: Reputation: Disabled
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
 
Old 01-23-2013, 07:16 AM   #2
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
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.
 
Old 01-23-2013, 02:36 PM   #3
mpc8250
LQ Newbie
 
Registered: Jan 2013
Posts: 7

Original Poster
Rep: Reputation: Disabled
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
 
Old 01-24-2013, 01:48 PM   #4
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
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.
 
Old 01-24-2013, 02:30 PM   #5
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Quote:
Originally Posted by lleb View Post
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.
 
Old 01-24-2013, 02:31 PM   #6
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Quote:
Originally Posted by mpc8250 View Post
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
DeltaCopy to rsync server failed: filename too long traigo Linux - Software 5 10-27-2015 04:46 AM
rsync exclude any filename containing a colon -- how???? andrewtblake Linux - Newbie 3 08-28-2009 02:18 PM
rsync question - Excluding files with a certain character in the filename EmigrantChris Linux - General 2 04-21-2009 10:07 PM
Strange behavior of rsync w.r.t filename cae jjge Linux - Software 2 09-25-2008 03:03 PM
quick rsync question don_wombat_73 Linux - Software 1 07-16-2008 04:18 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration