LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   rsync: exclude / include (https://www.linuxquestions.org/questions/linux-general-1/rsync-exclude-include-4175490905/)

tux111 01-11-2014 02:11 AM

rsync: exclude / include
 
Dear all,

Code:

rsync -avR /home/chris/ --delete --exclude="temp/" --exclude=".*" --link-dest=../last /media/alteplatte/backups/cd/$TODAY  >> $LOG 2>&1
I've excluded ".*" files in my rsync backup. Now, I want to include ".thunderbird", but not the other .-folders. How can this be done?

- Chris

wildwizard 01-11-2014 07:11 AM

I don't use include and exclude but rather filter

--filter='+ .thunderbird/***'
--filter='- .*'

If you include anything that is covered by a blanket exclude you must put the include before the exclude.
If you want everything inside a sub directory you use *** not *

The example given is a simple one as the sub directory is directly off the excluded path, if you wanted instead to include some sub sub directory then you would need to do something like this :-

--filter='+ .thunderbird/'
--filter='+ .thunderbird/sub-directory-here/***'
--filter='- .*'

Just a little gotcha when things get complicated.

tux111 01-11-2014 10:14 AM

Thank you very much. This is exactly what I was looking for.

lleb 01-11-2014 10:58 AM

you can also make an excludes.txt file and populate that.

in my backup script that runs on all of the laptops in the house:

Code:

rsync -aviS --exclude-from=${HOMEDIR}/excludes.txt ${PWD}/ ${RUSER}@${RHOST}:${RDIR}/${dow}/ >> ${log} 2>&1
here is a section of the excludes.txt

Code:

$ cat excludes.txt
- .cache/
- .config/
- .gconf/
- .local/
- .mozilla/
- .thunderbird/
- NFS/
- *.iso
- .steam/
- public/
- .minecraft/

works great. If you wanted to include something else, then you would just use a + foo and your good.

tux111 01-12-2014 01:54 AM

Thank you. I don't have so many subdirectories I want to backup, but exlcudes.txt is a clearly arranged list, I'll use when I add more folders.


All times are GMT -5. The time now is 07:17 AM.