LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   exclude folders from rsync (https://www.linuxquestions.org/questions/linux-software-2/exclude-folders-from-rsync-4175588933/)

alaios 09-07-2016 07:17 AM

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

pan64 09-07-2016 07:24 AM

did you read the man page of rsync? look for --exclude

Emerson 09-07-2016 07:31 AM

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.


keefaz 09-07-2016 07:40 AM

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

alaios 09-08-2016 02:41 AM

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?

IsaacKuo 09-08-2016 04:33 AM

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).

IsaacKuo 09-08-2016 04:36 AM

[delete duplicate]

keefaz 09-08-2016 08:27 AM

Quote:

Originally Posted by alaios (Post 5602318)
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;}

keefaz 09-08-2016 08:40 AM

Quote:

Originally Posted by IsaacKuo (Post 5602339)
]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

IsaacKuo 09-08-2016 10:05 AM

Quote:

Originally Posted by keefaz (Post 5602440)
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.

alaios 09-13-2016 03:02 AM

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

pan64 09-13-2016 03:58 AM

for example something like this:
Code:

rsync ....
RC=$?
case $RC in
  1)  ...
  24) ...
  *)  ...
esac


keefaz 09-13-2016 04:48 AM

How much vanished files warnings? Maybe add those files to the exclude list

alaios 09-13-2016 08:43 AM

Quote:

Originally Posted by keefaz (Post 5604514)
How much vanished files warnings? Maybe add those files to the exclude list

I do not know how many... How I can find?
Alex

keefaz 09-13-2016 08:57 AM

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 \)


All times are GMT -5. The time now is 02:51 AM.