LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-07-2016, 07:17 AM   #1
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Rep: Reputation: 45
exclude folders from rsync


Hi all,
I have written an rsync linke

Code:
 rsync -Lrav -e ssh apa@test:/home/apa/ "$MOUNTPOINT/test/home/apa"    || { doEmail 9; exit 1; }
that copies all the files inside the /home/apa.
What I want is to exclude on file inside the /home/apa. Is it possible to exclude that ?
How could I possible do that with the rsync?
I would like to thank you for your reply
Regards
Alex
 
Old 09-07-2016, 07:24 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 17,003

Rep: Reputation: 5741Reputation: 5741Reputation: 5741Reputation: 5741Reputation: 5741Reputation: 5741Reputation: 5741Reputation: 5741Reputation: 5741Reputation: 5741Reputation: 5741
did you read the man page of rsync? look for --exclude
 
Old 09-07-2016, 07:31 AM   #3
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~arch
Posts: 7,231

Rep: Reputation: Disabled
man rsync
Code:
-C, --cvs-exclude
              This  is  a useful shorthand for excluding a broad range of files that you often don’t want to
              transfer between systems. It uses a similar algorithm to CVS to determine if a file should  be
              ignored.

              The exclude list is initialized to exclude the following items (these initial items are marked
              as perishable -- see the FILTER RULES section):

                     RCS SCCS CVS CVS.adm RCSLOG cvslog.* tags TAGS .make.state .nse_depinfo *~  #*  .#*  ,*
                     _$*  *$  *.old *.bak *.BAK *.orig *.rej .del-* *.a *.olb *.o *.obj *.so *.exe *.Z *.elc
                     *.ln core .svn/ .git/ .hg/ .bzr/


              then, files listed in a $HOME/.cvsignore are added to the list and any  files  listed  in  the
              CVSIGNORE environment variable (all cvsignore names are delimited by whitespace).

              Finally,  any  file is ignored if it is in the same directory as a .cvsignore file and matches
              one of the patterns listed therein.  Unlike rsync’s filter/exclude files, these  patterns  are
              split on whitespace.  See the cvs(1) manual for more information.

              If  you’re  combining -C with your own --filter rules, you should note that these CVS excludes
              are appended at the end of your own rules, regardless of where the -C was placed on  the  com‐
              mand-line.   This makes them a lower priority than any rules you specified explicitly.  If you
              want to control where these CVS excludes get inserted into your filter rules, you should  omit
              the  -C  as a command-line option and use a combination of --filter=:C and --filter=-C (either
              on your command-line or by putting the ":C" and "-C" rules into a filter file with your  other
              rules).   The  first  option turns on the per-directory scanning for the .cvsignore file.  The
              second option does a one-time import of the CVS excludes mentioned above.

Last edited by Emerson; 09-07-2016 at 07:36 AM.
 
Old 09-07-2016, 07:40 AM   #4
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,325

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Take in account that with -a, you have to include path in filter, I mean:
Code:
--filter '- /home/apa/*/'
will exclude all directories in /home/apa

Last edited by keefaz; 09-07-2016 at 07:59 AM.
 
2 members found this post helpful.
Old 09-08-2016, 02:41 AM   #5
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Original Poster
Rep: Reputation: 45
thanks.. but how I am going to combine exclude with the ssh ?

rsync -Lrav -e ssh apa@test:/home/apa/ -C apa@test:/home/apa/EXCLUDEME/ "$MOUNTPOINT/test/home/apa" || { doEmail 9; exit 1;}

does not really work...
any ideas?
 
Old 09-08-2016, 04:33 AM   #6
IsaacKuo
Senior Member
 
Registered: Apr 2004
Location: Baton Rouge, Louisiana, USA
Distribution: Debian Stable
Posts: 2,398
Blog Entries: 8

Rep: Reputation: 412Reputation: 412Reputation: 412Reputation: 412Reputation: 412
I use rsync with --exclude all the time, although I haven't used it with the ssh option. Based on my experience, though, I can guess the following modification:

From this
Code:
rsync -Lrav -e ssh apa@test:/home/apa/ "$MOUNTPOINT/test/home/apa"    || { doEmail 9; exit 1; }
to this
Code:
rsync -Lrav --exclude EXCLUDEME -e ssh apa@test:/home/apa/ "$MOUNTPOINT/test/home/apa"    || { doEmail 9; exit 1; }
Basically, the path you give after "--exclude" should be the relative path from your source path. Thus, specifying "EXCLUDEME" means skipping /home/apa/EXCLUDEME. Note that EXCLUDEME can be either a file (it just skips that one specific file) or a directory (it skips the directory, including everything inside it).

Last edited by IsaacKuo; 09-08-2016 at 04:37 AM.
 
1 members found this post helpful.
Old 09-08-2016, 04:36 AM   #7
IsaacKuo
Senior Member
 
Registered: Apr 2004
Location: Baton Rouge, Louisiana, USA
Distribution: Debian Stable
Posts: 2,398
Blog Entries: 8

Rep: Reputation: 412Reputation: 412Reputation: 412Reputation: 412Reputation: 412
[delete duplicate]
 
Old 09-08-2016, 08:27 AM   #8
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,325

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by alaios View Post
thanks.. but how I am going to combine exclude with the ssh ?

rsync -Lrav -e ssh apa@test:/home/apa/ -C apa@test:/home/apa/EXCLUDEME/ "$MOUNTPOINT/test/home/apa" || { doEmail 9; exit 1;}

does not really work...
any ideas?
I would give this a try:
Code:
rsync -Lrav --filter '- /home/apa/EXCLUDEME/' -e ssh apa@test:/home/apa/ "$MOUNTPOINT/test/home/apa" || { doEmail 9; exit 1;}
 
Old 09-08-2016, 08:40 AM   #9
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,325

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by IsaacKuo View Post
]Basically, the path you give after "--exclude" should be the relative path from your source path. Thus, specifying "EXCLUDEME" means skipping /home/apa/EXCLUDEME. Note that EXCLUDEME can be either a file (it just skips that one specific file) or a directory (it skips the directory, including everything inside it).
Yes but without anchoring pattern to a specific spot in path hierarchy, this could also exclude for example:

/home/apa/something/EXCLUDEME
 
1 members found this post helpful.
Old 09-08-2016, 10:05 AM   #10
IsaacKuo
Senior Member
 
Registered: Apr 2004
Location: Baton Rouge, Louisiana, USA
Distribution: Debian Stable
Posts: 2,398
Blog Entries: 8

Rep: Reputation: 412Reputation: 412Reputation: 412Reputation: 412Reputation: 412
Quote:
Originally Posted by keefaz View Post
Yes but without anchoring pattern to a specific spot in path hierarchy, this could also exclude for example:

/home/apa/something/EXCLUDEME
Ha! Thanks for the warning, I did not know that. Sooner or later, that was going to bite me. Glad to know beforehand.
 
Old 09-13-2016, 03:02 AM   #11
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Original Poster
Rep: Reputation: 45
Now I am getting the following message

Rsync warning: some files vanished before they could be transferred (code 24)


I have googled it and I found that this is an okay warning. The only problem though is that makes my script to terminate
since
Quote:
rsync -Lrav -e ssh my@host:/home/my/ --exclude storage0 "$MOUNTPOINT/remote/home/src" || { doEmail 9; exit 1; }
my code requires a return code of normal execution to proceed further.
How I can "ignore" the code 24 so my code in that case executes normally the lines below, that pretty much unmount the hard disk.
Regards
Alex
 
Old 09-13-2016, 03:58 AM   #12
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 17,003

Rep: Reputation: 5741Reputation: 5741Reputation: 5741Reputation: 5741Reputation: 5741Reputation: 5741Reputation: 5741Reputation: 5741Reputation: 5741Reputation: 5741Reputation: 5741
for example something like this:
Code:
rsync ....
RC=$?
case $RC in
   1)  ...
   24) ...
   *)  ...
esac
 
Old 09-13-2016, 04:48 AM   #13
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,325

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
How much vanished files warnings? Maybe add those files to the exclude list
 
Old 09-13-2016, 08:43 AM   #14
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Original Poster
Rep: Reputation: 45
Quote:
Originally Posted by keefaz View Post
How much vanished files warnings? Maybe add those files to the exclude list
I do not know how many... How I can find?
Alex
 
Old 09-13-2016, 08:57 AM   #15
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,325

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Hey, sorry I thought that with ' -v ', rsync would print the vanished file names :/

Maybe this would work
Code:
(rsync -Lrav -e ssh my@host:/home/my/ \
--exclude storage0 "$MOUNTPOINT/remote/home/src"; \
(( ret = $? == 24 ? 0 : $? )); \
exit $ret) \
 || { doEmail 9; exit 1; }
The \ means that following line should be on same line (care not to add spaces after \)

Last edited by keefaz; 09-13-2016 at 09:00 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
include and exclude in rsync xeon123 Linux - Newbie 4 05-26-2011 11:27 PM
Can we use exclude option in"rm" command to exclude some files/folders? yadav_rk727 Linux - Newbie 1 02-03-2010 10:14 AM
Subversion: exclude certain files or folders Ephracis Linux - Software 1 03-01-2008 03:58 PM
help with rsync exclude syntax please JacekZ Linux - General 2 07-08-2007 01:23 PM
What files to exclude when using rsync TongueTied Linux - General 2 07-20-2006 08:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:28 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