LINUX - rsync - how to exclude

RSYNC EXCLUDE
##############

Imagine the source /from folder looks like this where / is the real root of the filesytem

* /from/folder1 <-- this has lots of files & subfolders in it
* /from/folder2 <-- this has lots of fi files & subfoldersles in it
* /from/folder3/folder1  <-- this has lots of  files & subfolders in it
* /from/folder3/folder2/file1.txt  <-- this is one file
* /from/folder3/folder2/file3.txt  <-- this is one file

Lets say im trying to exlude

* /from/folder2 --- all of the files and subfolders from here will be obliterated (not backed up)
* /from/folder3/folder1 --- all of the files and subfolders from here will be obliterated (not backed up)
* /from/folder3/folder2/file3.txt -- this single file will be obliterated from the copy (not backed up)

Construct your exclude list like so:

exclude.txt

CONTENTS OF exclude.txt:

folder2/
folder3/folder1/
folder3/folder2/file3.txt

:END OF CONTENTS OF exclude.txt

Construct the exclude list on how the rsync will see the files (relative path from the source path). You can think of it like this, rsync looks at a file and runs a grep on it from the exclude list, if it finds it, it will exclude it. (This might be wrong but its close enough)

Also run a test run on the job with -n

# rsync -options -n /from /to

You will notice it doesnt see files with the full path but relative path from /from

folder1 <-- this has lots of files & subfolders in it
folder2 <-- this has lots of fi files & subfoldersles in it
folder3/folder1  <-- this has lots of  files & subfolders in it
folder3/folder2/file1.txt  <-- this is one file
folder3/folder2/file3.txt  <-- this is one file

So the final command to test, after the exclude.txt is made, should look like this:

# rsync -options -n --exclude-from 'excludelist.txt' /from /to

This shoudnt copy files out, but it will list the files

After you notice that the files and folders are not listed just remove the -n and run it again

# rsync -options --exclude-from 'excludelist.txt' /from /to

NOTE: excludelist.txt should be located in the same folder where your currently in (it doesnt have to be in /from or /to) - remember everything in linux is relative terms or absolute terms

EXAMPLE: 
# cd /root
# vi excludelist.txt
# rsync -options -n --exclude-from 'excludelist.txt' /from /to
# rsync -options --exclude-from 'excludelist.txt' /from /to

or

# rsync -options -n --exclude-from /root/excludelist.txt /from /to
# rsync -options --exclude-from /root/excludelist.txt /from /to

NOTE: the '' are optional and should be used with spaces only






SelectionFile type iconFile nameDescriptionSizeRevisionTimeUser
Comments